public async Task WhenTheSubscriptionExists_ItShouldUpdateTheSubscription()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateChannelSubscriptionDbStatement(testDatabase, this.requestSnapshot);

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

                await this.target.ExecuteAsync(UserId, Subscriptions[0].ChannelId, NewAcceptedPrice, Now);

                var update = new ChannelSubscription(
                    Subscriptions[0].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    NewAcceptedPrice.Value,
                    Now,
                    SubscriptionStartDate);

                return(new ExpectedSideEffects {
                    Update = update
                });
            });
        }
        public async Task ItShouldRequestSnapshotAfterUpdate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                var trackingDatabase = new TrackingConnectionFactory(testDatabase);
                this.target          = new UpdateChannelSubscriptionDbStatement(trackingDatabase, this.requestSnapshot);

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

                this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase);

                await this.target.ExecuteAsync(UserId, Subscriptions[0].ChannelId, NewAcceptedPrice, Now);

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

                var update = new ChannelSubscription(
                    Subscriptions[0].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    NewAcceptedPrice.Value,
                    Now,
                    SubscriptionStartDate);

                return(new ExpectedSideEffects {
                    Update = update
                });
            });
        }
        public async Task WhenTheUserDoesNotExist_ItShouldDoNothing()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateChannelSubscriptionDbStatement(testDatabase, this.requestSnapshot);

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

                await this.target.ExecuteAsync(new UserId(Guid.NewGuid()), Subscriptions[0].ChannelId, NewAcceptedPrice, Now);

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldBeIdempotent()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateChannelSubscriptionDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);

                await this.target.ExecuteAsync(UserId, Subscriptions[0].ChannelId, NewAcceptedPrice, Now);
                await testDatabase.TakeSnapshotAsync();
                await this.target.ExecuteAsync(UserId, Subscriptions[0].ChannelId, NewAcceptedPrice, Now);

                return(ExpectedSideEffects.None);
            });
        }
        public async Task ItShouldNotUpdateIfSnapshotFails()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateChannelSubscriptionDbStatement(testDatabase, this.requestSnapshot);

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

                this.requestSnapshot.ThrowException();

                await ExpectedException.AssertExceptionAsync <SnapshotException>(
                    () => this.target.ExecuteAsync(UserId, Subscriptions[0].ChannelId, NewAcceptedPrice, Now));

                return(ExpectedSideEffects.TransactionAborted);
            });
        }
 public void TestInitialize()
 {
     this.requestSnapshot = new MockRequestSnapshotService();
     this.target          = new UpdateChannelSubscriptionDbStatement(new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict).Object, this.requestSnapshot);
 }