public async Task ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.InitializeTarget(trackingDatabase); var channel = await this.CreateChannelAsync(testDatabase); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); await this.target.ExecuteAsync(UserId, ChannelId, Name, Price, IsVisibleToNonSubscribers, Now); this.requestSnapshot.VerifyCalledWith(UserId, SnapshotType.CreatorChannels); var expectedChannel = new Channel(ChannelId.Value) { IsVisibleToNonSubscribers = IsVisibleToNonSubscribers, Name = Name.Value, Price = Price.Value, PriceLastSetDate = Now, BlogId = channel.BlogId, CreationDate = channel.CreationDate, IsDiscoverable = channel.IsDiscoverable, }; return(new ExpectedSideEffects { Update = expectedChannel }); }); }
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 }); }); }
public async Task ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.target = new UpdateFreeAccessUsersDbStatement(trackingDatabase, this.requestSnapshot); await this.CreateDataAsync(testDatabase, true); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); await this.target.ExecuteAsync(CreatorId, BlogId, null); this.requestSnapshot.VerifyCalledWith(CreatorId, SnapshotType.CreatorFreeAccessUsers); return(new ExpectedSideEffects { Deletes = new List <FreeAccessUser> { new FreeAccessUser { BlogId = BlogId.Value, Email = "*****@*****.**" }, new FreeAccessUser { BlogId = BlogId.Value, Email = "*****@*****.**" }, new FreeAccessUser { BlogId = BlogId.Value, Email = "*****@*****.**" }, }, }); }); }
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 }); }); }
public async Task WhenRegisteringANewUser_ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.target = new RegisterUserDbStatement(this.userManager.Object, trackingDatabase, this.requestSnapshot); var hashedPassword = RegistrationData.Password + "1"; this.passwordHasher.Setup(v => v.HashPassword(RegistrationData.Password.Value)).Returns(hashedPassword); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); await this.target.ExecuteAsync( UserId, RegistrationData.Username, RegistrationData.Email, RegistrationData.ExampleWork, RegistrationData.Password, TimeStamp); this.requestSnapshot.VerifyCalledWith(UserId, SnapshotType.Subscriber); var expectedUser = new FifthweekUser { Id = UserId.Value, UserName = RegistrationData.Username.Value, Email = RegistrationData.Email.Value, ExampleWork = RegistrationData.ExampleWork, RegistrationDate = TimeStamp, LastSignInDate = SqlDateTime.MinValue.Value, LastAccessTokenDate = SqlDateTime.MinValue.Value, PasswordHash = hashedPassword, }; return(new ExpectedSideEffects { Insert = new WildcardEntity <FifthweekUser>(expectedUser) { Expected = actual => { expectedUser.SecurityStamp = actual.SecurityStamp; return expectedUser; } } }); }); }
public async Task ItShouldAbortUpdateIfSnapshotFails() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.InitializeTarget(trackingDatabase); await this.CreateChannelAsync(testDatabase); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.ThrowException(); await ExpectedException.AssertExceptionAsync <SnapshotException>( () => this.target.ExecuteAsync(UserId, ChannelId, Name, Price, IsVisibleToNonSubscribers, Now)); return(ExpectedSideEffects.TransactionAborted); }); }
public async Task ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.InitializeTarget(trackingDatabase); await this.CreateEntitiesAsync(testDatabase); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); await this.target.HandleAsync(Command); this.requestSnapshot.VerifyCalledWith(UserId, SnapshotType.CreatorChannels); var expectedChannel = new Channel( ChannelId.Value, BlogId.Value, null, Name.Value, Price.Value, IsVisibleToNonSubscribers, default(DateTime), default(DateTime), false); return(new ExpectedSideEffects { Insert = new WildcardEntity <Channel>(expectedChannel) { Expected = actual => { expectedChannel.CreationDate = actual.CreationDate; expectedChannel.PriceLastSetDate = actual.PriceLastSetDate; Assert.AreEqual(actual.CreationDate, actual.PriceLastSetDate); return expectedChannel; } } }); }); }
public async Task ItShouldRequestSnapshot() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); await this.InitializeTarget(trackingDatabase); await this.CreateUserAsync(UserId, testDatabase); await testDatabase.TakeSnapshotAsync(); this.requestSnapshotService.VerifyConnectionDisposed(trackingDatabase); await this.target.HandleAsync(Command); this.requestSnapshotService.VerifyCalledWith(UserId, SnapshotType.CreatorChannels); return(new ExpectedSideEffects { ExcludedFromTest = entity => entity is Channel || entity is Blog }); }); }
public async Task WhenUpdateAccountSettingsCalled_ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.target = new UpdateAccountSettingsDbStatement(trackingDatabase, this.userManager.Object, this.requestSnapshot); await this.CreateUserAsync(testDatabase); await testDatabase.TakeSnapshotAsync(); var hashedNewPassword = this.newPassword.Value + "1"; this.passwordHasher.Setup(v => v.HashPassword(this.newPassword.Value)).Returns(hashedNewPassword); var expectedUser = await this.GetUserAsync(testDatabase); expectedUser.UserName = this.newUsername.Value; expectedUser.Email = this.newEmail.Value; expectedUser.EmailConfirmed = false; expectedUser.PasswordHash = hashedNewPassword; expectedUser.ProfileImageFileId = this.newFileId.Value; expectedUser.SecurityStamp = this.securityStamp; this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); var result = await this.target.ExecuteAsync( this.userId, this.newUsername, this.newEmail, this.newPassword, this.newFileId, this.securityStamp); this.requestSnapshot.VerifyCalledWith(this.userId, SnapshotType.Subscriber); Assert.AreEqual(false, result.EmailConfirmed); return(new ExpectedSideEffects { Update = expectedUser }); }); }
public async Task ItShouldRequestSnapshotAfterUpdate() { await this.DatabaseTestAsync(async testDatabase => { var trackingDatabase = new TrackingConnectionFactory(testDatabase); this.InitializeTarget(trackingDatabase); await this.CreateEntitiesAsync(testDatabase); var expectedDeletions = await this.GetExpectedDeletionsAsync(testDatabase); await testDatabase.TakeSnapshotAsync(); this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase); await this.target.ExecuteAsync(CreatorId, ChannelId); this.requestSnapshot.VerifyCalledWith(CreatorId, SnapshotType.CreatorChannels); return(new ExpectedSideEffects { Deletes = expectedDeletions, }); }); }