public async Task DispatchAsyncKeysValuesNotMatching() { // arrange FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new IResult <string> [0]) .ConfigureAwait(false); var options = new DataLoaderOptions <string> { BatchRequestDelay = TimeSpan.FromMinutes(10) }; var loader = new DataLoader <string, string>(options, fetch); await Task.Delay(10); Task <IReadOnlyList <string> > loadResult = loader.LoadAsync("Foo", "Bar"); await loader.DispatchAsync().ConfigureAwait(false); // act Func <Task> verify = () => loadResult; // assert await Assert.ThrowsAsync <InvalidOperationException>(verify) .ConfigureAwait(false); }
public async Task DispatchAsyncNoBatching() { // arrange IResult <string> expectedResult = Result <string> .Resolve("Bar"); FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new[] { expectedResult }) .ConfigureAwait(false); var options = new DataLoaderOptions <string> { Batching = false }; var loader = new DataLoader <string, string>(options, fetch); // this would block if batching would be enabled var loadResult = await loader.LoadAsync("Foo") .ConfigureAwait(false); // act await loader.DispatchAsync().ConfigureAwait(false); // assert Assert.Equal(expectedResult.Value, loadResult); }
public async Task DispatchAsyncAuto() { // arrange IResult <string> expectedResult = Result <string> .Resolve("Bar"); FetchDataDelegate <string, string> fetch = async keys => await Task.FromResult(new[] { expectedResult }) .ConfigureAwait(false); var options = new DataLoaderOptions <string> { BatchRequestDelay = TimeSpan.FromMinutes(10) }; var loader = new DataLoader <string, string>(options, fetch); await Task.Delay(10); Task <string> loadResult = loader.LoadAsync("Foo"); // act await loader.DispatchAsync().ConfigureAwait(false); // assert Assert.Equal(expectedResult.Value, await loadResult.ConfigureAwait(false)); }
public void DispatchAsyncNoException() { // arrange FetchDataDelegate <string, string> fetch = TestHelpers .CreateFetch <string, string>(); var options = new DataLoaderOptions <string>(); var loader = new DataLoader <string, string>(options, fetch); // act Action verify = () => loader.DispatchAsync(); // assert Assert.Null(Record.Exception(verify)); }
public async Task DispatchAsyncNoException() { // 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); // act Func <Task> verify = () => loader.DispatchAsync(); // assert Assert.Null(await Record.ExceptionAsync(verify) .ConfigureAwait(false)); }