Example #1
0
        public void IsInvalid_WhenPasswords_DoNotMatch(bool useMatchLabel)
        {
            string passwordA = Guid.NewGuid().ToString();
            string passwordB = Guid.NewGuid().ToString();
            var    command   = new FakeMustEqualPasswordCommand
            {
                PasswordA     = passwordA,
                PasswordB     = passwordB,
                UseMatchLabel = useMatchLabel,
            };
            var validator = new FakeMustEqualPasswordValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBeFalse();
            Func <ValidationFailure, bool> passwordError = x => x.PropertyName == command.PropertyName(y => y.PasswordA);

            result.Errors.Count(passwordError).ShouldEqual(1);
            result.Errors.Single(passwordError).ErrorMessage.ShouldEqual(
                Resources.Validation_PasswordDoesNotEqualConfirmation
                .Replace("{PropertyName}", LocalMembership.Constraints.PasswordLabel)
                .Replace("{PasswordLabel}", useMatchLabel
                    ? FakeMustEqualPasswordCommand.MatchLabelConstant
                    : LocalMembership.Constraints.PasswordLabel.ToLower())
                );
            validator.ShouldHaveValidationErrorFor(x => x.PasswordA, command);
        }
Example #2
0
        public void IsValid_WhenPasswords_Match()
        {
            string passwordA = Guid.NewGuid().ToString();
            string passwordB = passwordA;
            var    command   = new FakeMustEqualPasswordCommand
            {
                PasswordA = passwordA,
                PasswordB = passwordB,
            };
            var validator = new FakeMustEqualPasswordValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            validator.ShouldNotHaveValidationErrorFor(x => x.PasswordA, command);
        }