public async Task WhenUsernameDoesNotExist_ItShouldDoNothing() { var command = new RequestPasswordResetCommand(null, ValidUsername.Parse(Username)); this.userManager.Setup(_ => _.FindByNameAsync(Username)).ReturnsAsync(null); await this.target.HandleAsync(command); }
public void AssertNotReserved(ValidUsername username) { username.AssertNotNull("username"); if (this.IsReserved(username)) { throw new RecoverableException("The username '" + username.Value + "' is already taken."); } }
public async Task WhenUsernameExists_ItShouldSendEmail() { var command = new RequestPasswordResetCommand(null, ValidUsername.Parse(Username)); this.userManager.Setup(_ => _.FindByNameAsync(Username)).ReturnsAsync(new FifthweekUser() { Id = UserId, UserName = Username }); await this.AssertEmailSent(command); }
public async Task <IHttpActionResult> GetUsernameAvailabilityAsync(string username) { username.AssertUrlParameterProvided("username"); ValidUsername usernameObject; if (!ValidUsername.TryParse(username, out usernameObject)) { return(this.NotFound()); } var query = new IsUsernameAvailableQuery(usernameObject); var usernameAvailable = await this.isUsernameAvailable.HandleAsync(query); if (usernameAvailable) { return(this.Ok()); } return(this.NotFound()); }
public async Task WhenPostingUserRegistration_ItShouldIssueRegisterUserCommand() { var registration = NewRegistrationData(); var command = new RegisterUserCommand( UserId, registration.ExampleWork, ValidEmail.Parse(registration.Email), ValidUsername.Parse(registration.Username), ValidPassword.Parse(registration.Password), false); this.guidCreator.Setup(_ => _.CreateSqlSequential()).Returns(UserId.Value); this.registerUser.Setup(v => v.HandleAsync(command)).Returns(Task.FromResult(0)); var result = await this.controller.PostRegistrationAsync(registration); Assert.IsInstanceOfType(result, typeof(OkResult)); this.registerUser.Verify(v => v.HandleAsync(command)); this.guidCreator.Verify(v => v.CreateSqlSequential()); }
public void AssertAvailableShouldReturnForNonReservedUsernames() { this.target.AssertNotReserved(ValidUsername.Parse("phil")); }
public void AssertAvailableShouldThrowAnExceptionForReservedUsernames() { this.target.AssertNotReserved(ValidUsername.Parse("static")); }
public void IsReservedShouldReturnFalseForNonReservedUsernames() { Assert.IsFalse(this.target.IsReserved(ValidUsername.Parse("phil"))); Assert.IsFalse(this.target.IsReserved(ValidUsername.Parse("fifthweek"))); }
public void IsReservedShouldReturnTrueForReservedUsernames() { Assert.IsTrue(this.target.IsReserved(ValidUsername.Parse("static"))); Assert.IsTrue(this.target.IsReserved(ValidUsername.Parse("bower_components"))); }
public bool IsReserved(ValidUsername username) { username.AssertNotNull("username"); return(this.reservedUsernames.Contains(username.Value)); }
public static RequestPasswordResetCommand NewCommand(PasswordResetRequestData data) { return(new RequestPasswordResetCommand( data.Email == null ? null : ValidEmail.Parse(data.Email), data.Username == null ? null : ValidUsername.Parse(data.Username))); }
public async Task WhenEmailExistsAndUsernameExists_ItShouldSendEmailToUserIdentifiedByUsername() { var command = new RequestPasswordResetCommand(ValidEmail.Parse(EmailAddress), ValidUsername.Parse(Username)); this.userManager.Setup(_ => _.FindByNameAsync(Username)).ReturnsAsync(new FifthweekUser() { Id = UserId, UserName = Username }); this.userManager.Setup(_ => _.FindByEmailAsync(EmailAddress)).ReturnsAsync(new FifthweekUser() { Id = UserId2, UserName = Username }); await this.AssertEmailSent(command); }
public async Task <UpdateAccountSettingsResult> ExecuteAsync( UserId userId, ValidUsername newUsername, ValidEmail newEmail, ValidPassword newPassword, FileId newProfileImageFileId, string newSecurityStamp) { userId.AssertNotNull("userId"); newUsername.AssertNotNull("newUsername"); newEmail.AssertNotNull("newEmail"); string passwordHash = null; if (newPassword != null) { passwordHash = this.userManager.PasswordHasher.HashPassword(newPassword.Value); } var query = new StringBuilder(); query.AppendLine(@"DECLARE @emailConfirmed bit"); query.Append(@" UPDATE dbo.AspNetUsers SET Email = @Email, UserName = @Username, ProfileImageFileId = @ProfileImageFileId, SecurityStamp = @SecurityStamp, @emailConfirmed = ( CASE WHEN ((EmailConfirmed = 0) OR (Email != @Email)) THEN 0 ELSE 1 END ), EmailConfirmed = @emailConfirmed"); if (passwordHash != null) { query.Append(@", PasswordHash=@PasswordHash"); } query.AppendLine().Append(@"WHERE Id=@UserId").AppendLine(); query.Append(@"select @emailConfirmed"); bool emailConfirmed; using (var transaction = TransactionScopeBuilder.CreateAsync()) { using (var connection = this.connectionFactory.CreateConnection()) { emailConfirmed = await connection.ExecuteScalarAsync <bool>( query.ToString(), new { UserId = userId.Value, Username = newUsername.Value, Email = newEmail.Value, PasswordHash = passwordHash, SecurityStamp = newSecurityStamp, ProfileImageFileId = newProfileImageFileId == null ? (Guid?)null : newProfileImageFileId.Value }); } await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.Subscriber); transaction.Complete(); } return(new UpdateAccountSettingsResult(emailConfirmed)); }