Exemple #1
0
        public async Task ExecuteAsync_ElementIsMissingFromFetchDictionary_ShouldResolveLoadAsyncWithDefaultValue()
        {
            var loader = new KeyedDataLoader <Guid, Book>(_contextMock.Object,
                                                          (keys, token) => Task.FromResult <IReadOnlyDictionary <Guid, Book> >(new Dictionary <Guid, Book>()));

            var task = loader.LoadAsync(Guid.NewGuid());

            await await((IExecutableDataLoader)loader).ExecuteAsync(CancellationToken.None);

            Assert.That(task.IsCompleted, Is.True);
            Assert.That(task.Result, Is.EqualTo(null));
        }
Exemple #2
0
        public void SetUp()
        {
            _contextMock = new Mock <IDataLoaderContext>();
            _fetchCalls  = new List <Tuple <Guid[], CancellationToken> >();
            _loader      = new KeyedDataLoader <Guid, Book>(
                _contextMock.Object,
                (keys, token) =>
            {
                _fetchCalls.Add(new Tuple <Guid[], CancellationToken>(keys.ToArray(), token));

                return(Task.FromResult <IReadOnlyDictionary <Guid, Book> >(keys.Select(id => new Book
                {
                    Id = id,
                    Title = $"SomeTitle",
                    Author = $"SomeAuthor"
                }).ToDictionary(x => x.Id)));
            });
        }