Esempio n. 1
0
        public async Task DeleteProfileRemovesProfileFromResultsCacheTest()
        {
            var profile      = Model.Create <Profile>();
            var cacheResults = new List <ProfileResult>
            {
                Model.Create <ProfileResult>().Set(x => x.Id = profile.Id)
            };

            var store      = Substitute.For <IProfileStore>();
            var calculator = Substitute.For <IProfileChangeCalculator>();
            var processor  = Substitute.For <IProfileChangeProcessor>();
            var cache      = Substitute.For <IProfileCache>();

            var sut = new ProfileCommand(store, calculator, processor, cache);

            using (var tokenSource = new CancellationTokenSource())
            {
                store.GetProfile(profile.Id, tokenSource.Token).Returns(profile);
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.DeleteProfile(profile.Id, tokenSource.Token).Returns(profile);
                cache.GetProfileResults().Returns(cacheResults);

                await sut.DeleteProfile(profile.Id, tokenSource.Token).ConfigureAwait(false);

                cache.Received().StoreProfileResults(
                    Verify.That <ICollection <ProfileResult> >(x => x.Should().NotContain(y => y.Id == profile.Id)));
            }
        }
Esempio n. 2
0
        public async Task DeleteProfileDoesNotProcessChangesWhenNoneFoundTest()
        {
            var profile = Model.Create <Profile>();

            var store      = Substitute.For <IProfileStore>();
            var calculator = Substitute.For <IProfileChangeCalculator>();
            var processor  = Substitute.For <IProfileChangeProcessor>();
            var cache      = Substitute.For <IProfileCache>();

            var sut = new ProfileCommand(store, calculator, processor, cache);

            using (var tokenSource = new CancellationTokenSource())
            {
                store.GetProfile(profile.Id, tokenSource.Token).Returns(profile);
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.DeleteProfile(profile.Id, tokenSource.Token).Returns(profile);

                await sut.DeleteProfile(profile.Id, tokenSource.Token).ConfigureAwait(false);

                await processor.DidNotReceive().Execute(
                    Arg.Any <Profile>(),
                    Arg.Any <ProfileChangeResult>(),
                    Arg.Any <CancellationToken>()).ConfigureAwait(false);
            }
        }
Esempio n. 3
0
        public void DeleteProfileThrowsExceptionWithEmptyIdTest()
        {
            var store      = Substitute.For <IProfileStore>();
            var calculator = Substitute.For <IProfileChangeCalculator>();
            var processor  = Substitute.For <IProfileChangeProcessor>();
            var cache      = Substitute.For <IProfileCache>();

            var sut = new ProfileCommand(store, calculator, processor, cache);

            Func <Task> action = async() => await sut.DeleteProfile(Guid.Empty, CancellationToken.None)
                                 .ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
Esempio n. 4
0
        public async Task DeleteProfileIgnoresWhenProfileNotFoundTest()
        {
            var profileId = Guid.NewGuid();

            var store      = Substitute.For <IProfileStore>();
            var calculator = Substitute.For <IProfileChangeCalculator>();
            var processor  = Substitute.For <IProfileChangeProcessor>();
            var cache      = Substitute.For <IProfileCache>();

            var sut = new ProfileCommand(store, calculator, processor, cache);

            using (var tokenSource = new CancellationTokenSource())
            {
                await sut.DeleteProfile(profileId, tokenSource.Token).ConfigureAwait(false);
            }
        }
Esempio n. 5
0
        public async Task DeleteProfileRemovesProfileFromStoreTest()
        {
            var profile = Model.Create <Profile>();

            var store      = Substitute.For <IProfileStore>();
            var calculator = Substitute.For <IProfileChangeCalculator>();
            var processor  = Substitute.For <IProfileChangeProcessor>();
            var cache      = Substitute.For <IProfileCache>();

            var sut = new ProfileCommand(store, calculator, processor, cache);

            using (var tokenSource = new CancellationTokenSource())
            {
                store.GetProfile(profile.Id, tokenSource.Token).Returns(profile);
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.DeleteProfile(profile.Id, tokenSource.Token).Returns(profile);

                await sut.DeleteProfile(profile.Id, tokenSource.Token).ConfigureAwait(false);

                await store.Received().DeleteProfile(profile.Id, tokenSource.Token).ConfigureAwait(false);
            }
        }