public void RETURN_FALSE_IF_USERNAME_CONTAINS_SPECIAL_CHARACTERS() { RegisterDtoValidator objectUnderTest = new RegisterDtoValidator(); var testData = new RegisterDto() { Password = "******", RepeatedPassword = "******", Username = "******" }; var result = objectUnderTest.Validate(testData); Assert.IsNotNull(result); Assert.IsFalse(result.IsValid); }
public void RETURN_FALSE_IF_USERNAME_CONTAINS_DOUBLE_QUOTES() { RegisterDtoValidator objectUnderTest = new RegisterDtoValidator(); var testData = new RegisterDto() { Password = "******", RepeatedPassword = "******", Username = "******"test\"" }; var result = objectUnderTest.Validate(testData); Assert.IsNotNull(result); Assert.IsFalse(result.IsValid); }
public void RETURN_FALSE_IF_PASSWORDS_NOT_MATCH() { RegisterDtoValidator objectUnderTest = new RegisterDtoValidator(); var testData = new RegisterDto() { AccountType = Common.DataModels.IdentityManagement.AccountType.Administrator, Password = "******", RepeatedPassword = "******", Username = "******" }; var result = objectUnderTest.Validate(testData); Assert.IsNotNull(result); Assert.IsFalse(result.IsValid); }
public void RETURN_TRUE_IF_DATA_IS_VALID() { RegisterDtoValidator objectUnderTest = new RegisterDtoValidator(); var testData = new RegisterDto() { AccountType = Common.DataModels.IdentityManagement.AccountType.Administrator, Password = "******", RepeatedPassword = "******", Username = "******" }; var result = objectUnderTest.Validate(testData); Assert.IsNotNull(result); Assert.IsTrue(result.IsValid); }
public async Task ValidateBeforeRegistration(RegisterDto userForRegistration) { var validator = new RegisterDtoValidator(); CheckValidationResults(validator.Validate(userForRegistration)); var existingUserEmail = await _userManager.FindByEmailAsync(userForRegistration.Email); if (existingUserEmail != null) { ThrowValidationError("Email", $"Email {userForRegistration.Email} already exists!"); } var existingUserUsername = await _userManager.FindByNameAsync(userForRegistration.UserName); if (existingUserUsername != null) { ThrowValidationError("Username", $"Username {userForRegistration.UserName} already exists!"); } }