Esempio n. 1
0
        public async Task WhenTheSubscriptionExists_ItShouldDeleteTheSubscription()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UnsubscribeFromChannelDbStatement(testDatabase, this.requestSnapshot);

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

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

                var deletion = new ChannelSubscription(
                    Subscriptions[0].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    Subscriptions[0].AcceptedPrice.Value,
                    PriceLastAcceptedDate,
                    SubscriptionStartDate);

                return(new ExpectedSideEffects {
                    Delete = deletion
                });
            });
        }
Esempio n. 2
0
        public async Task ItShouldRequestSnapshotAfterUpdate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                var trackingDatabase = new TrackingConnectionFactory(testDatabase);
                this.target          = new UnsubscribeFromChannelDbStatement(trackingDatabase, this.requestSnapshot);

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

                this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase);

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

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

                var deletion = new ChannelSubscription(
                    Subscriptions[0].ChannelId.Value,
                    null,
                    UserId.Value,
                    null,
                    Subscriptions[0].AcceptedPrice.Value,
                    PriceLastAcceptedDate,
                    SubscriptionStartDate);

                return(new ExpectedSideEffects {
                    Delete = deletion
                });
            });
        }
Esempio n. 3
0
        public async Task WhenTheUserDoesNotExist_ItShouldDoNothing()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UnsubscribeFromChannelDbStatement(testDatabase, this.requestSnapshot);

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

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

                return(ExpectedSideEffects.None);
            });
        }
Esempio n. 4
0
        public async Task ItShouldBeIdempotent()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UnsubscribeFromChannelDbStatement(testDatabase, this.requestSnapshot);

                await this.CreateDataAsync(testDatabase);

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

                return(ExpectedSideEffects.None);
            });
        }
Esempio n. 5
0
        public async Task ItShouldNotUpdateIfSnapshotFails()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UnsubscribeFromChannelDbStatement(testDatabase, this.requestSnapshot);

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

                this.requestSnapshot.ThrowException();

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

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