public void Should_PassValidation_When_AllRulesPass() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: "******", password: "******"); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; // Assert isValid.Should().Be(true); }
public void Should_FailValidationWithMessage_When_UsernameContainsSpecialCharacters() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: "******", password: "******"); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; var errors = result.Errors; // Assert isValid.Should().Be(false); errors.Count.Should().Be(1); errors[0].ToString().Should().Be("Username must not contain spaces and special characters."); }
public void Should_FailValidationWithMessage_When_PasswordContainsSpaces() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: "******", password: "******"); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; var errors = result.Errors; // Assert isValid.Should().Be(false); errors.Count.Should().Be(1); errors[0].ToString().Should().Be("Password must not be empty or contain spaces."); }
public void Should_FailValidationWithMessage_When_PasswordIsMoreThan64Characters() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: "******", password: "******"); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; var errors = result.Errors; // Assert isValid.Should().Be(false); errors.Count.Should().Be(1); errors[0].ToString().Should().Be("Password must be at least 8 characters and less than or equal to 64."); }
public void Should_FailValidationWithMessage_When_UsernameIsNull() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: null, password: "******"); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; var errors = result.Errors; // Assert isValid.Should().Be(false); errors.Count.Should().Be(2); errors[0].ToString().Should().Be("Username is required."); errors[1].ToString().Should().Be("Username is required."); }
public void Should_FailValidationWithMessage_When_PasswordIsEmpty() { // Arrange var loginDtoValidator = new LoginDtoValidator(); var loginDto = new LoginDto(username: "******", password: ""); // Act var result = loginDtoValidator.Validate(loginDto, ruleSet: "UsernameAndPassword"); var isValid = result.IsValid; var errors = result.Errors; // Assert isValid.Should().Be(false); errors.Count.Should().Be(3); errors[0].ToString().Should().Be("Password is required."); errors[1].ToString().Should().Be("Password must be at least 8 characters and less than or equal to 64."); errors[2].ToString().Should().Be("Password must not be empty or contain spaces."); }
public void ValidateBeforeLogin(LoginDto userForLogin) { var validator = new LoginDtoValidator(); CheckValidationResults(validator.Validate(userForLogin)); }