Imported Upstream version 5.10.0.69

Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-29 19:03:06 +00:00
parent d8f8abd549
commit e2950ec768
6283 changed files with 453847 additions and 91879 deletions

View File

@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Xunit;
using System;
using System.Runtime.Caching;
namespace System.Runtime.Caching.Tests
{
// These are the tests to fill in some of the coverage in ported Mono caching tests
public class AdditionalCacheTests
{
[Fact]
public void DisposedCacheTest()
{
var mc = new MemoryCache("my disposed cache 1");
mc.Add("aa", "bb", new CacheItemPolicy());
mc.Dispose();
Assert.Null(mc["aa"]);
mc = new MemoryCache("my disposed cache 2");
CacheEntryRemovedReason reason = (CacheEntryRemovedReason)1111;
var cip = new CacheItemPolicy();
cip.RemovedCallback = (CacheEntryRemovedArguments args) =>
{
reason = args.RemovedReason;
};
mc.Set("key", "value", cip);
mc.Dispose();
Assert.Equal(reason, CacheEntryRemovedReason.CacheSpecificEviction);
}
}
}

View File

@@ -0,0 +1,48 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
using System.Text;
namespace MonoTests.Common
{
internal class PokerChangeMonitor : ChangeMonitor
{
private List<string> _calls;
private string _uniqueId;
public List<string> Calls
{
get
{
if (_calls == null)
_calls = new List<string>();
return _calls;
}
}
public override string UniqueId
{
get { return _uniqueId; }
}
public PokerChangeMonitor()
{
_uniqueId = "UniqueID";
InitializationComplete();
}
public void SignalChange()
{
OnChanged(null);
}
protected override void Dispose(bool disposing)
{
Calls.Add("Dispose (bool disposing)");
}
}
}

View File

@@ -0,0 +1,160 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.Caching;
using System.Text;
namespace MonoTests.Common
{
internal class PokerMemoryCache : MemoryCache
{
private List<string> _calls;
public List<string> Calls
{
get
{
if (_calls == null)
_calls = new List<string>();
return _calls;
}
}
public override object this[string key]
{
get
{
Calls.Add("get_this [string key]");
return base[key];
}
set
{
Calls.Add("set_this [string key]");
base[key] = value;
}
}
public PokerMemoryCache(string name, NameValueCollection config = null)
: base(name, config)
{ }
public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
{
Calls.Add("AddOrGetExisting (CacheItem item, CacheItemPolicy policy)");
return base.AddOrGetExisting(item, policy);
}
public override object AddOrGetExisting(string key, object value, CacheItemPolicy policy, string regionName = null)
{
Calls.Add("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)");
return base.AddOrGetExisting(key, value, policy, regionName);
}
public override object AddOrGetExisting(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
Calls.Add("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)");
return base.AddOrGetExisting(key, value, absoluteExpiration, regionName);
}
public override object Get(string key, string regionName = null)
{
Calls.Add("Get (string key, string regionName = null)");
return base.Get(key, regionName);
}
public override CacheItem GetCacheItem(string key, string regionName = null)
{
Calls.Add("GetCacheItem (string key, string regionName = null)");
return base.GetCacheItem(key, regionName);
}
public override long GetCount(string regionName = null)
{
Calls.Add("GetCount (string regionName = null)");
return base.GetCount(regionName);
}
public override bool Contains(string key, string regionName = null)
{
Calls.Add("Contains (string key, string regionName = null)");
return base.Contains(key, regionName);
}
public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable<string> keys, string regionName = null)
{
Calls.Add("CreateCacheEntryChangeMonitor (IEnumerable<string> keys, string regionName = null)");
return base.CreateCacheEntryChangeMonitor(keys, regionName);
}
protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
Calls.Add("IEnumerator<KeyValuePair<string, object>> GetEnumerator ()");
return base.GetEnumerator();
}
public IEnumerator<KeyValuePair<string, object>> DoGetEnumerator()
{
return GetEnumerator();
}
public override IDictionary<string, object> GetValues(IEnumerable<string> keys, string regionName = null)
{
Calls.Add("IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)");
return base.GetValues(keys, regionName);
}
public override IDictionary<string, object> GetValues(string regionName, params string[] keys)
{
Calls.Add("IDictionary<string, object> GetValues (string regionName, params string [] keys)");
return base.GetValues(regionName, keys);
}
public override void Set(CacheItem item, CacheItemPolicy policy)
{
Calls.Add("Set (CacheItem item, CacheItemPolicy policy)");
base.Set(item, policy);
}
public override void Set(string key, object value, CacheItemPolicy policy, string regionName = null)
{
Calls.Add("Set (string key, object value, CacheItemPolicy policy, string regionName = null)");
base.Set(key, value, policy, regionName);
}
public override void Set(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
Calls.Add("Set (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)");
base.Set(key, value, absoluteExpiration, regionName);
}
}
}

View File

@@ -0,0 +1,192 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Caching;
namespace MonoTests.Common
{
internal class PokerObjectCache : ObjectCache
{
private Dictionary<string, object> _cache;
private Dictionary<string, object> Cache
{
get
{
if (_cache == null)
_cache = new Dictionary<string, object>();
return _cache;
}
}
public string MethodCalled { get; private set; }
public override object AddOrGetExisting(string key, object value, CacheItemPolicy policy, string regionName = null)
{
MethodCalled = "AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)";
if (String.IsNullOrEmpty(key) || value == null)
return null;
object item;
if (Cache.TryGetValue(key, out item))
return item;
Cache.Add(key, value);
return null;
}
public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
{
MethodCalled = "AddOrGetExisting (CacheItem value, CacheItemPolicy policy)";
if (value == null)
return null;
object item;
if (Cache.TryGetValue(value.Key, out item))
return item as CacheItem;
Cache.Add(value.Key, value);
return null;
}
public override object AddOrGetExisting(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
MethodCalled = "AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)";
if (String.IsNullOrEmpty(key) || value == null)
return null;
object item;
if (Cache.TryGetValue(key, out item))
return item;
Cache.Add(key, value);
return null;
}
public override bool Contains(string key, string regionName = null)
{
throw new NotImplementedException();
}
public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable<string> keys, string regionName = null)
{
throw new NotImplementedException();
}
public override DefaultCacheCapabilities DefaultCacheCapabilities
{
get { throw new NotImplementedException(); }
}
public override object Get(string key, string regionName = null)
{
throw new NotImplementedException();
}
public override CacheItem GetCacheItem(string key, string regionName = null)
{
throw new NotImplementedException();
}
public override long GetCount(string regionName = null)
{
throw new NotImplementedException();
}
protected override IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
throw new NotImplementedException();
}
public override IDictionary<string, object> GetValues(IEnumerable<string> keys, string regionName = null)
{
MethodCalled = "IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)";
var ret = new Dictionary<string, object>();
if (keys == null)
return ret;
Dictionary<string, object> cache = Cache;
if (cache.Count == 0)
return ret;
object value;
foreach (string key in keys)
{
if (!cache.TryGetValue(key, out value))
continue;
ret.Add(key, value);
}
return ret;
}
public override string Name
{
get { throw new NotImplementedException(); }
}
public override object Remove(string key, string regionName = null)
{
throw new NotImplementedException();
}
public override void Set(string key, object value, CacheItemPolicy policy, string regionName = null)
{
throw new NotImplementedException();
}
public override void Set(CacheItem item, CacheItemPolicy policy)
{
throw new NotImplementedException();
}
public override void Set(string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)
{
throw new NotImplementedException();
}
public override object this[string key]
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
}

View File

@@ -0,0 +1,94 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Caching;
using System.Runtime.Caching.Hosting;
namespace MonoTests.Common
{
internal class TestNotificationSystem : IServiceProvider, IFileChangeNotificationSystem
{
private OnChangedCallback _callback;
public bool StartMonitoringCalled { get; private set; }
public uint StartMonitoringCallCount { get; private set; }
public bool StopMonitoringCalled { get; private set; }
public uint StopMonitoringCallCount { get; private set; }
public bool UseNullState { get; set; }
public object GetService(Type serviceType)
{
return this;
}
object IServiceProvider.GetService(Type serviceType)
{
return GetService(serviceType);
}
public void FakeChanged(string filePath)
{
if (_callback == null)
return;
_callback(null);
}
public void StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
{
if (UseNullState)
state = null;
else
state = filePath;
lastWriteTime = DateTimeOffset.FromFileTime(DateTime.Now.Ticks);
_callback = onChangedCallback;
fileSize = 10;
StartMonitoringCalled = true;
StartMonitoringCallCount++;
}
public void StopMonitoring(string filePath, object state)
{
StopMonitoringCalled = true;
StopMonitoringCallCount++;
}
void IFileChangeNotificationSystem.StartMonitoring(string filePath, OnChangedCallback onChangedCallback, out object state, out DateTimeOffset lastWriteTime, out long fileSize)
{
StartMonitoring(filePath, onChangedCallback, out state, out lastWriteTime, out fileSize);
}
void IFileChangeNotificationSystem.StopMonitoring(string filePath, object state)
{
StopMonitoring(filePath, state);
}
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp-Windows_NT;
netfx;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
<PropertyGroup>
<ProjectGuid>{397E49A7-EB26-4368-8F46-D78B98F4A971}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Compile Include="AdditionalCacheTests\AdditionalCacheTests.cs" />
<Compile Include="Common\PokerChangeMonitor.cs" />
<Compile Include="Common\PokerMemoryCache.cs" />
<Compile Include="Common\PokerObjectCache.cs" />
<Compile Include="Common\TestNotificationSystem.cs" />
<Compile Include="System.Runtime.Caching\HostFileChangeMonitorTest.cs" />
<Compile Include="System.Runtime.Caching\ObjectCacheTest.cs" />
<Compile Include="System.Runtime.Caching\MemoryCacheTest.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,314 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Caching;
using System.Runtime.Caching.Hosting;
using System.Text;
using Xunit;
using MonoTests.Common;
namespace MonoTests.System.Runtime.Caching
{
public class HostFileChangeMonitorTest
{
[Fact]
public void Constructor_Exceptions()
{
string relPath = Path.Combine("relative", "file", "path");
var paths = new List<string> {
relPath
};
Assert.Throws<ArgumentException>(() =>
{
new HostFileChangeMonitor(paths);
});
paths.Clear();
paths.Add(null);
Assert.Throws<ArgumentException>(() =>
{
new HostFileChangeMonitor(paths);
});
paths.Clear();
paths.Add(String.Empty);
Assert.Throws<ArgumentException>(() =>
{
new HostFileChangeMonitor(paths);
});
Assert.Throws<ArgumentNullException>(() =>
{
new HostFileChangeMonitor(null);
});
paths.Clear();
Assert.Throws<ArgumentException>(() =>
{
new HostFileChangeMonitor(paths);
});
}
[Fact]
private static void Constructor_MissingFiles_Handler()
{
HostFileChangeMonitor monitor;
string missingFile = Path.GetFullPath(Path.Combine(Guid.NewGuid().ToString("N"), "file", "path"));
var paths = new List<string> {
missingFile
};
// Actually thrown by FileSystemWatcher constructor - note that the exception message suggests the file's
// parent directory is being watched, not the file itself:
//
// MonoTests.System.Runtime.Caching.HostFileChangeMonitorTest.Constructor_MissingFiles:
// System.ArgumentException : The directory name c:\missing\file is invalid.
// at System.IO.FileSystemWatcher..ctor(String path, String filter)
// at System.IO.FileSystemWatcher..ctor(String path)
// at System.Runtime.Caching.FileChangeNotificationSystem.System.Runtime.Caching.Hosting.IFileChangeNotificationSystem.StartMonitoring(String filePath, OnChangedCallback onChangedCallback, Object& state, DateTimeOffset& lastWriteTime, Int64& fileSize)
// at System.Runtime.Caching.HostFileChangeMonitor.InitDisposableMembers()
// at System.Runtime.Caching.HostFileChangeMonitor..ctor(IList`1 filePaths)
// at MonoTests.System.Runtime.Caching.HostFileChangeMonitorTest.Constructor_MissingFiles() in c:\users\grendel\documents\visual studio 2010\Projects\System.Runtime.Caching.Test\System.Runtime.Caching.Test\System.Runtime.Caching\HostFileChangeMonitorTest.cs:line 68
Assert.Throws<ArgumentException>(() =>
{
new HostFileChangeMonitor(paths);
});
missingFile = Path.GetFullPath(Guid.NewGuid().ToString("N"));
paths.Clear();
paths.Add(missingFile);
monitor = new HostFileChangeMonitor(paths);
Assert.Equal(1, monitor.FilePaths.Count);
Assert.Equal(missingFile, monitor.FilePaths[0]);
//??
Assert.Equal(missingFile + "701CE1722770000FFFFFFFFFFFFFFFF", monitor.UniqueId);
monitor.Dispose();
paths.Add(missingFile);
monitor = new HostFileChangeMonitor(paths);
Assert.Equal(2, monitor.FilePaths.Count);
Assert.Equal(missingFile, monitor.FilePaths[0]);
Assert.Equal(missingFile, monitor.FilePaths[1]);
//??
Assert.Equal(missingFile + "701CE1722770000FFFFFFFFFFFFFFFF", monitor.UniqueId);
monitor.Dispose();
}
[Fact]
public void Constructor_Duplicates()
{
HostFileChangeMonitor monitor;
string missingFile = Path.GetFullPath(Guid.NewGuid().ToString("N"));
var paths = new List<string> {
missingFile,
missingFile
};
// Just checks if it doesn't throw any exception for dupes
monitor = new HostFileChangeMonitor(paths);
monitor.Dispose();
}
private static Tuple<string, string, string, IList<string>> SetupMonitoring()
{
string testPath = Path.Combine(Path.GetTempPath(), "HostFileChangeMonitorTest", "Dispose_Calls_StopMonitoring");
if (!Directory.Exists(testPath))
Directory.CreateDirectory(testPath);
string firstFile = Path.Combine(testPath, "FirstFile.txt");
string secondFile = Path.Combine(testPath, "SecondFile.txt");
File.WriteAllText(firstFile, "I am the first file.");
File.WriteAllText(secondFile, "I am the second file.");
var paths = new List<string> {
firstFile,
secondFile
};
return new Tuple<string, string, string, IList<string>>(testPath, firstFile, secondFile, paths);
}
private static void CleanupMonitoring(Tuple<string, string, string, IList<string>> setup)
{
string testPath = setup != null ? setup.Item1 : null;
if (String.IsNullOrEmpty(testPath) || !Directory.Exists(testPath))
return;
foreach (string f in Directory.EnumerateFiles(testPath))
{
try
{
File.Delete(f);
}
catch
{
// ignore
}
}
try
{
// 2 nested folders were created by SetupMonitoring, so we'll delete both
var dirInfo = new DirectoryInfo(testPath);
var parentDirInfo = dirInfo.Parent;
dirInfo.Delete(recursive: true);
parentDirInfo.Delete(recursive: true);
}
catch
{
// ignore
}
}
[Fact]
[ActiveIssue(25168)]
private static void Constructor_Calls_StartMonitoring_Handler()
{
Tuple<string, string, string, IList<string>> setup = null;
try
{
var tns = new TestNotificationSystem();
ObjectCache.Host = tns;
setup = SetupMonitoring();
var monitor = new HostFileChangeMonitor(setup.Item4);
Assert.True(tns.StartMonitoringCalled);
Assert.Equal(2U, tns.StartMonitoringCallCount);
}
finally
{
CleanupMonitoring(setup);
}
}
[Fact]
[ActiveIssue(25168)]
private static void Dispose_Calls_StopMonitoring_Handler()
{
Tuple<string, string, string, IList<string>> setup = null;
try
{
var tns = new TestNotificationSystem();
ObjectCache.Host = tns;
setup = SetupMonitoring();
var monitor = new HostFileChangeMonitor(setup.Item4);
tns.FakeChanged(setup.Item2);
Assert.True(tns.StopMonitoringCalled);
Assert.Equal(2U, tns.StopMonitoringCallCount);
}
finally
{
CleanupMonitoring(setup);
}
}
[Fact]
[ActiveIssue(25168)]
private static void Dispose_NullState_NoStopMonitoring_Handler()
{
Tuple<string, string, string, IList<string>> setup = null;
try
{
var tns = new TestNotificationSystem();
tns.UseNullState = true;
ObjectCache.Host = tns;
setup = SetupMonitoring();
var monitor = new HostFileChangeMonitor(setup.Item4);
tns.FakeChanged(setup.Item2);
Assert.False(tns.StopMonitoringCalled);
Assert.Equal(0U, tns.StopMonitoringCallCount);
}
finally
{
CleanupMonitoring(setup);
}
}
[Fact]
public void UniqueId()
{
Tuple<string, string, string, IList<string>> setup = null;
try
{
setup = SetupMonitoring();
FileInfo fi;
var monitor = new HostFileChangeMonitor(setup.Item4);
var sb = new StringBuilder();
fi = new FileInfo(setup.Item2);
sb.AppendFormat("{0}{1:X}{2:X}",
setup.Item2,
fi.LastWriteTimeUtc.Ticks,
fi.Length);
fi = new FileInfo(setup.Item3);
sb.AppendFormat("{0}{1:X}{2:X}",
setup.Item3,
fi.LastWriteTimeUtc.Ticks,
fi.Length);
Assert.Equal(sb.ToString(), monitor.UniqueId);
var list = new List<string>(setup.Item4);
list.Add(setup.Item1);
monitor = new HostFileChangeMonitor(list);
var di = new DirectoryInfo(setup.Item1);
sb.AppendFormat("{0}{1:X}{2:X}",
setup.Item1,
di.LastWriteTimeUtc.Ticks,
-1L);
Assert.Equal(sb.ToString(), monitor.UniqueId);
list.Add(setup.Item1);
monitor = new HostFileChangeMonitor(list);
Assert.Equal(sb.ToString(), monitor.UniqueId);
monitor.Dispose();
}
finally
{
CleanupMonitoring(setup);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,148 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
using Xunit;
using MonoTests.Common;
namespace MonoTests.System.Runtime.Caching
{
public class ObjectCacheTest
{
[Fact]
[ActiveIssue(25168)]
private static void Host_SetToProvider()
{
var tns1 = new TestNotificationSystem();
var tns2 = new TestNotificationSystem();
ObjectCache.Host = tns1;
Assert.NotNull(ObjectCache.Host);
Assert.Equal(tns1, ObjectCache.Host);
Assert.Throws<InvalidOperationException>(() =>
{
ObjectCache.Host = tns2;
});
}
[Fact]
public void Add_CacheItem_CacheItemPolicy()
{
var poker = new PokerObjectCache();
bool ret;
ret = poker.Add(null, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (CacheItem value, CacheItemPolicy policy)", poker.MethodCalled);
var item = new CacheItem("key", 1234);
ret = poker.Add(item, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (CacheItem value, CacheItemPolicy policy)", poker.MethodCalled);
ret = poker.Add(item, null);
Assert.False(ret);
Assert.Equal("AddOrGetExisting (CacheItem value, CacheItemPolicy policy)", poker.MethodCalled);
}
[Fact]
public void Add_String_Object_CacheItemPolicy_String()
{
var poker = new PokerObjectCache();
bool ret;
ret = poker.Add(null, null, null, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)", poker.MethodCalled);
ret = poker.Add("key", 1234, null, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)", poker.MethodCalled);
ret = poker.Add("key", 1234, null, null);
Assert.False(ret);
Assert.Equal("AddOrGetExisting (string key, object value, CacheItemPolicy policy, string regionName = null)", poker.MethodCalled);
}
[Fact]
public void Add_String_Object_DateTimeOffset_String()
{
var poker = new PokerObjectCache();
bool ret;
ret = poker.Add(null, null, DateTimeOffset.Now, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)", poker.MethodCalled);
ret = poker.Add("key", 1234, DateTimeOffset.Now, null);
Assert.True(ret);
Assert.Equal("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)", poker.MethodCalled);
ret = poker.Add("key", 1234, DateTimeOffset.Now, null);
Assert.False(ret);
Assert.Equal("AddOrGetExisting (string key, object value, DateTimeOffset absoluteExpiration, string regionName = null)", poker.MethodCalled);
}
[Fact]
public void GetValues()
{
var poker = new PokerObjectCache();
IDictionary<string, object> values = poker.GetValues(null, (string[])null);
Assert.NotNull(values);
Assert.Equal(0, values.Count);
Assert.Equal("IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)", poker.MethodCalled);
poker.Add("key1", 1, null);
poker.Add("key2", 2, null);
poker.Add("key3", 3, null);
values = poker.GetValues(new string[] { "key1", "key2", "key3" });
Assert.NotNull(values);
Assert.Equal(3, values.Count);
Assert.Equal("IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)", poker.MethodCalled);
values = poker.GetValues(new string[] { "key1", "key22", "key3" });
Assert.NotNull(values);
Assert.Equal(2, values.Count);
Assert.Equal("IDictionary<string, object> GetValues (IEnumerable<string> keys, string regionName = null)", poker.MethodCalled);
}
[Fact]
public void Defaults()
{
Assert.Equal(DateTimeOffset.MaxValue, ObjectCache.InfiniteAbsoluteExpiration);
Assert.Equal(TimeSpan.Zero, ObjectCache.NoSlidingExpiration);
}
}
}