public async Task GetCategoryReturnsCategoryBasedOnReadTypeAndVisibilityTest( ReadType readType, bool isVisible, bool valueReturned) { var expected = Model.Create <Category>().Set(x => x.Visible = isVisible); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { store.GetCategory(expected.Group, expected.Name, tokenSource.Token).Returns(expected); var actual = await sut.GetCategory(readType, expected.Group, expected.Name, tokenSource.Token) .ConfigureAwait(false); if (valueReturned) { actual.Should().BeEquivalentTo(expected); } else { actual.Should().BeNull(); } } }
public void GetCategoryThrowsExceptionWithInvalidNameTest(string name) { var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); Func <Task> actual = async() => await sut.GetCategory(ReadType.VisibleOnly, CategoryGroup.Skill, name, CancellationToken.None) .ConfigureAwait(false); actual.Should().Throw <ArgumentException>(); }
public async Task GetCategoryReturnsCategoryFromCacheTest() { var expected = Model.Create <Category>(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { store.GetCategory(expected.Group, expected.Name, tokenSource.Token).Returns(expected); var actual = await sut.GetCategory(ReadType.All, expected.Group, expected.Name, tokenSource.Token) .ConfigureAwait(false); actual.Should().BeEquivalentTo(expected); cache.Received().StoreCategory(expected); } }
public async Task GetCategoryDoesNotCacheNullValueFromStoreTest() { var expected = Model.Create <Category>(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { store.GetCategory(expected.Group, expected.Name, tokenSource.Token).Returns((Category)null); var actual = await sut.GetCategory(ReadType.All, expected.Group, expected.Name, tokenSource.Token) .ConfigureAwait(false); actual.Should().BeNull(); cache.DidNotReceive().StoreCategory(Arg.Any <Category>()); } }
public async Task GetCategoryStoresValueInCacheWhenReturnedFromStoreTest() { var expected = Model.Create <Category>(); var store = Substitute.For <ICategoryStore>(); var cache = Substitute.For <ICategoryCache>(); var sut = new CategoryQuery(store, cache); using (var tokenSource = new CancellationTokenSource()) { cache.GetCategory(expected.Group, expected.Name).Returns(expected); var actual = await sut.GetCategory(ReadType.All, expected.Group, expected.Name, tokenSource.Token) .ConfigureAwait(false); actual.Should().BeEquivalentTo(expected); await store.DidNotReceive().GetCategory( Arg.Any <CategoryGroup>(), Arg.Any <string>(), Arg.Any <CancellationToken>()).ConfigureAwait(false); } }