public async Task GetCategoriesReturnsEmptyListWhenCategoriesNotFoundTest() { var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { cache.GetCategories().Returns((ICollection <Category>)null); store.GetAllCategories(tokenSource.Token).Returns((IEnumerable <Category>)null); var actual = await sut.GetCategories(ReadType.All, tokenSource.Token).ConfigureAwait(false); actual.Should().BeEmpty(); } }
public async Task GetCategoriesReturnsCachedCategoriesTest() { var expected = Model.Create <List <Category> >(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); cache.GetCategories().Returns(expected); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { var actual = await sut.GetCategories(ReadType.All, tokenSource.Token).ConfigureAwait(false); actual.Should().BeEquivalentTo(expected); } }
public async Task GetCategoriesReturnsVisibleCategoriesFromCacheWhenVisibleOnlyRequestedTest() { var categories = Model.Create <List <Category> >(); var expected = categories.Where(x => x.Visible).ToList(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); cache.GetCategories().Returns(expected); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { var actual = await sut.GetCategories(ReadType.VisibleOnly, tokenSource.Token).ConfigureAwait(false); actual.Should().BeEquivalentTo(expected); } }
public async Task GetCategoriesCachesCategoryReturnedFromStoreTest() { var expected = Model.Create <List <Category> >(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { cache.GetCategories().Returns((ICollection <Category>)null); store.GetAllCategories(tokenSource.Token).Returns(expected); await sut.GetCategories(ReadType.All, tokenSource.Token).ConfigureAwait(false); cache.Received().StoreCategories( Verify.That <ICollection <Category> >(x => x.Should().BeEquivalentTo(expected))); } }