public void GetOrAddTaskWhenNothingIsCached_IntegerKey() { // arrange var cacheSize = 10; var cache = new TaskCache(cacheSize); var key = new TaskCacheKey("a", 1); // act Task <string> resolved = cache.GetOrAddTask(key, () => Task.FromResult("Quox")); // assert Assert.Equal("Quox", resolved.Result); }
public void TryAddValueNull() { // arrange var cacheSize = 10; var cache = new TaskCache(cacheSize); var key = new TaskCacheKey("a", "Foo"); // act void Verify() => cache.TryAdd(key, default(Task <string>) !); // assert Assert.Throws <ArgumentNullException>("value", Verify); }
public void TryAddNewCacheEntryWithFactory() { // arrange var cacheSize = 10; var cache = new TaskCache(cacheSize); var key = new TaskCacheKey("a", "Foo"); var expected = Task.FromResult("Bar"); // act var added = cache.TryAdd(key, () => expected); // assert Task <string> resolved = cache.GetOrAddTask(key, () => Task.FromResult("Baz")); Assert.True(added); Assert.Same(expected, resolved); }
public void RemoveEntry() { // arrange var cacheSize = 10; var cache = new TaskCache(cacheSize); var key = new TaskCacheKey("a", "Foo"); var value = Task.FromResult("Bar"); cache.TryAdd(key, value); // act cache.TryRemove(key); // assert Task <string> retrieved = cache.GetOrAddTask(key, () => Task.FromResult("Baz")); Assert.NotSame(value, retrieved); }
public void TryAddTwice() { // arrange var cacheSize = 10; var cache = new TaskCache(cacheSize); var key = new TaskCacheKey("a", "Foo"); var expected = Task.FromResult("Bar"); var another = Task.FromResult("Baz"); // act var addedFirst = cache.TryAdd(key, expected); var addedSecond = cache.TryAdd(key, another); // assert Task <string> resolved = cache.GetOrAddTask(key, () => Task.FromResult("Quox")); Assert.True(addedFirst); Assert.False(addedSecond); Assert.Same(expected, resolved); }
/// <inheritdoc /> public virtual void ResolvedTaskFromCache( IDataLoader dataLoader, TaskCacheKey cacheKey, Task task) { }