public void Validate_GivenNewPasswordIsNull_ExpectValidationFailure() { var securitySettings = new Mock <IOptions <SecuritySettings> >(); securitySettings.Setup(x => x.Value).Returns(new SecuritySettings()); var model = new Password.Model { ConfirmPassword = "******", NewPassword = null, OldPassword = "******", }; var validator = new Password.Validator(securitySettings.Object); var result = validator.Validate(model); Assert.False(result.IsValid); Assert.Contains(result.Errors, x => x.PropertyName == "NewPassword"); }
public void Validate_GivenAllPropertiesAreValid_ExpectValidationSuccess() { var securitySettings = new Mock <IOptions <SecuritySettings> >(); securitySettings.Setup(x => x.Value).Returns(new SecuritySettings { PasswordRequirements = new SecuritySettings.PasswordRequirement(), }); var model = new Password.Model { ConfirmPassword = "******", NewPassword = "******", OldPassword = "******", }; var validator = new Password.Validator(securitySettings.Object); var result = validator.Validate(model); Assert.True(result.IsValid); }
public void Validate_GivenConfirmPasswordDoesNotMatch_ExpectValidationFailure() { var securitySettings = new Mock <IOptions <SecuritySettings> >(); securitySettings.Setup(x => x.Value).Returns(new SecuritySettings { PasswordRequirements = new SecuritySettings.PasswordRequirement(), }); var model = new Password.Model { ConfirmPassword = string.Empty, NewPassword = "******", OldPassword = "******", }; var validator = new Password.Validator(securitySettings.Object); var result = validator.Validate(model); Assert.False(result.IsValid); Assert.Contains(result.Errors, x => x.PropertyName == "ConfirmPassword"); }