Ejemplo n.º 1
0
        public async Task BanProfileDoesNotProcessChangesWhenNoneFoundTest()
        {
            var profile  = Model.Create <Profile>();
            var bannedAt = DateTimeOffset.UtcNow.AddDays(-2);

            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())
            {
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.BanProfile(profile.Id, Arg.Any <DateTimeOffset>(), tokenSource.Token).Returns(profile);

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

                await processor.DidNotReceive().Execute(
                    Arg.Any <Profile>(),
                    Arg.Any <ProfileChangeResult>(),
                    Arg.Any <CancellationToken>()).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        public async Task BanProfileRemovesProfileFromResultsCacheTest()
        {
            var profile      = Model.Create <Profile>().Set(x => x.BannedAt = DateTimeOffset.UtcNow);
            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())
            {
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.BanProfile(profile.Id, profile.BannedAt.Value, tokenSource.Token).Returns(profile);
                cache.GetProfileResults().Returns(cacheResults);

                await sut.BanProfile(profile.Id, profile.BannedAt.Value, tokenSource.Token).ConfigureAwait(false);

                cache.Received().StoreProfileResults(
                    Verify.That <ICollection <ProfileResult> >(x => x.Should().NotContain(y => y.Id == profile.Id)));
            }
        }
Ejemplo n.º 3
0
        public void BanProfileThrowsExceptionWithEmptyIdTest()
        {
            var bannedAt = DateTimeOffset.UtcNow.AddDays(-2);

            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.BanProfile(Guid.Empty, bannedAt, CancellationToken.None)
                                 .ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 4
0
        public async Task BanProfileReturnsNullWhenProfileNotInStoreTest()
        {
            var profileId = Guid.NewGuid();
            var bannedAt  = DateTimeOffset.UtcNow.AddDays(-2);

            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())
            {
                var actual = await sut.BanProfile(profileId, bannedAt, tokenSource.Token).ConfigureAwait(false);

                actual.Should().BeNull();
                cache.DidNotReceive().StoreProfile(Arg.Any <Profile>());
            }
        }
Ejemplo n.º 5
0
        public async Task BanProfileDoesNotCacheProfileResultWhenNoResultsAreCachedTest()
        {
            var profile = Model.Create <Profile>().Set(x => x.BannedAt = DateTimeOffset.UtcNow);

            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())
            {
                calculator.RemoveAllCategoryLinks(profile).Returns(new ProfileChangeResult());
                store.BanProfile(profile.Id, profile.BannedAt.Value, tokenSource.Token).Returns(profile);
                cache.GetProfileResults().Returns((ICollection <ProfileResult>)null);

                await sut.BanProfile(profile.Id, profile.BannedAt.Value, tokenSource.Token).ConfigureAwait(false);

                cache.DidNotReceive().StoreProfileResults(Arg.Any <ICollection <ProfileResult> >());
            }
        }
Ejemplo n.º 6
0
        public async Task BanProfileRemovesProfileFromCacheTest()
        {
            var expected = Model.Create <Profile>().Set(x => x.Status = ProfileStatus.Unavailable);
            var bannedAt = DateTimeOffset.UtcNow.AddDays(-2);

            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())
            {
                calculator.RemoveAllCategoryLinks(expected).Returns(new ProfileChangeResult());
                store.BanProfile(expected.Id, bannedAt, tokenSource.Token).Returns(expected);

                await sut.BanProfile(expected.Id, bannedAt, tokenSource.Token).ConfigureAwait(false);

                cache.Received().RemoveProfile(expected.Id);
            }
        }