コード例 #1
0
            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");
            }
コード例 #2
0
            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);
            }
コード例 #3
0
            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");
            }