Exemplo n.º 1
0
        public async Task ItShouldRequestSnapshotAfterUpdate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                var trackingDatabase = new TrackingConnectionFactory(testDatabase);
                this.target          = new UpdateBlogSubscriptionsDbStatement(trackingDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);
                await testDatabase.TakeSnapshotAsync();

                this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase);

                await this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions1, Now);

                this.requestSnapshot.VerifyCalledWith(UserId, SnapshotType.SubscriberChannels);

                var expectedResults =
                    AcceptedBlog3Subscriptions1.Select(
                        v => new ChannelSubscription(
                            v.ChannelId.Value,
                            null,
                            UserId.Value,
                            null,
                            v.AcceptedPrice.Value,
                            Now,
                            SubscriptionStartDate)).ToList();

                return(new ExpectedSideEffects {
                    Updates = expectedResults
                });
            });
        }
Exemplo n.º 2
0
        public async Task WhenTheSubscriptionHasNotChanged_ItShouldUpdatePriceLastAcceptedDate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogSubscriptionsDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);
                await testDatabase.TakeSnapshotAsync();

                await this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions1, Now);

                var expectedResults =
                    AcceptedBlog3Subscriptions1.Select(
                        v => new ChannelSubscription(
                            v.ChannelId.Value,
                            null,
                            UserId.Value,
                            null,
                            v.AcceptedPrice.Value,
                            Now,
                            SubscriptionStartDate)).ToList();

                return(new ExpectedSideEffects {
                    Updates = expectedResults
                });
            });
        }
Exemplo n.º 3
0
        public async Task ItShouldBeIdempotent()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogSubscriptionsDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);

                await this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions1, Now);
                await testDatabase.TakeSnapshotAsync();
                await this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions1, Now);

                return(ExpectedSideEffects.None);
            });
        }
Exemplo n.º 4
0
        public async Task WhenTheSubscriptionHasChangedChanged_ItShouldUpdateTheSubscription()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogSubscriptionsDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);
                await testDatabase.TakeSnapshotAsync();

                await this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions2, Now);

                var expectedUpdate = new ChannelSubscription(
                    AcceptedBlog3Subscriptions2[0].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    AcceptedBlog3Subscriptions2[0].AcceptedPrice.Value,
                    Now,
                    SubscriptionStartDate);

                var expectedInsert = new ChannelSubscription(
                    AcceptedBlog3Subscriptions2[1].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    AcceptedBlog3Subscriptions2[1].AcceptedPrice.Value,
                    Now,
                    Now);

                var expectedDelete = new ChannelSubscription(
                    AcceptedBlog3Subscriptions1[1].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    AcceptedBlog3Subscriptions1[1].AcceptedPrice.Value,
                    PriceLastAcceptedDate,
                    SubscriptionStartDate);

                return(new ExpectedSideEffects
                {
                    Update = expectedUpdate,
                    Insert = expectedInsert,
                    Delete = expectedDelete
                });
            });
        }
Exemplo n.º 5
0
        public async Task ItShouldNotUpdateIfSnapshotFails()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogSubscriptionsDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);
                await testDatabase.TakeSnapshotAsync();

                this.requestSnapshot.ThrowException();

                await ExpectedException.AssertExceptionAsync <SnapshotException>(
                    () => this.target.ExecuteAsync(UserId, Blog3Id, AcceptedBlog3Subscriptions1, Now));

                return(ExpectedSideEffects.TransactionAborted);
            });
        }
Exemplo n.º 6
0
 public void TestInitialize()
 {
     this.requestSnapshot = new MockRequestSnapshotService();
     this.target          = new UpdateBlogSubscriptionsDbStatement(new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict).Object, this.requestSnapshot);
 }