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