コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }