public void RemoveEntry() { // arrange FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new IResult <string> [0]) .ConfigureAwait(false); var options = new DataLoaderOptions <string> { Batching = false }; var loader = new DataLoader <string, string>(options, fetch); var key = "Foo"; loader.Set(key, Task.FromResult("Bar")); // act IDataLoader <string, string> result = loader.Remove(key); // assert Task <string> loadResult = loader.LoadAsync(key); if (loadResult is IAsyncResult asyncResult) { asyncResult.AsyncWaitHandle.WaitOne(); } Assert.Equal(loader, result); Assert.NotNull(loadResult.Exception); }
public void IDataLoaderRemoveNoException() { // arrange FetchDataDelegate <string, string> fetch = TestHelpers.CreateFetch <string, string>(); var batchScheduler = new ManualBatchScheduler(); IDataLoader loader = new DataLoader <string, string>(batchScheduler, fetch); object key = "Foo"; // act Action verify = () => loader.Remove(key); // assert Assert.Null(Record.Exception(verify)); }
public void IDataLoaderRemoveKeyNull() { // arrange FetchDataDelegate <string, string> fetch = TestHelpers.CreateFetch <string, string>(); var batchScheduler = new ManualBatchScheduler(); IDataLoader loader = new DataLoader <string, string>(batchScheduler, fetch); object key = null; loader.Set("Foo", Task.FromResult((object)"Bar")); // act Action verify = () => loader.Remove(key); // assert Assert.Throws <ArgumentNullException>("key", verify); }
public void RemoveNoException() { // arrange FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new IResult <string> [0]) .ConfigureAwait(false); var options = new DataLoaderOptions <string>(); var loader = new DataLoader <string, string>(options, fetch); var key = "Foo"; // act Action verify = () => loader.Remove(key); // assert Assert.Null(Record.Exception(verify)); }
public void RemoveKeyNull() { // arrange FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new IResult <string> [0]) .ConfigureAwait(false); var options = new DataLoaderOptions <string>(); var loader = new DataLoader <string, string>(options, fetch); string key = null; loader.Set("Foo", Task.FromResult("Bar")); // act Action verify = () => loader.Remove(key); // assert Assert.Throws <ArgumentNullException>("key", verify); }
public void IDataLoaderRemoveEntry() { // arrange FetchDataDelegate <string, string> fetch = TestHelpers.CreateFetch <string, string>(); var batchScheduler = new ManualBatchScheduler(); var cache = new TaskCache(10); var options = new DataLoaderOptions <string> { Cache = cache }; IDataLoader loader = new DataLoader <string, string>(batchScheduler, fetch, options); object key = "Foo"; loader.Set(key, Task.FromResult((object)"Bar")); // act loader.Remove(key); // assert Assert.Equal(0, cache.Usage); }