Exemplo n.º 1
0
        public void IsInvalid_WhenUserName_IsGreaterThan_MaxLength()
        {
            var userName = Guid.NewGuid().ToString();

            while (userName.Length < User.Constraints.NameMaxLength)
            {
                userName += Guid.NewGuid().ToString();
            }
            var command = new FakeMustBeValidUserNameCommand
            {
                UserName = userName,
            };
            var validator = new FakeMustBeValidUserNameValidator();

            var result = validator.Validate(command);

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

            result.Errors.Count(userNameError).ShouldEqual(1);
            result.Errors.Single(userNameError).ErrorMessage.ShouldEqual(Resources.Validation_MaxLength
                                                                         .Replace("{PropertyName}", User.Constraints.NameLabel)
                                                                         .Replace("{MaxLength}", User.Constraints.NameMaxLength
                                                                                  .ToString(CultureInfo.InvariantCulture))
                                                                         .Replace("{TotalLength}", userName.Length.ToString(CultureInfo.InvariantCulture))
                                                                         );
            validator.ShouldHaveValidationErrorFor(x => x.UserName, command.UserName);
        }
Exemplo n.º 2
0
        public void IsInvalid_WhenUserName_IsLessThan_MinLength(string userName)
        {
            var command = new FakeMustBeValidUserNameCommand
            {
                UserName = userName,
            };
            var validator = new FakeMustBeValidUserNameValidator();

            var result = validator.Validate(command);

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

            result.Errors.Count(userNameError).ShouldEqual(1);
            result.Errors.Single(userNameError).ErrorMessage.ShouldEqual(Resources.Validation_MinLength
                                                                         .Replace("{PropertyName}", User.Constraints.NameLabel)
                                                                         .Replace("{MinLength}", User.Constraints.NameMinLength
                                                                                  .ToString(CultureInfo.InvariantCulture))
                                                                         .Replace("{TotalLength}", userName.Length.ToString(CultureInfo.InvariantCulture))
                                                                         .Replace("{Characters}", userName.Length == 1
                    ? Resources.Validation_CharacterLower
                    : Resources.Validation_CharactersLower)
                                                                         );
            validator.ShouldHaveValidationErrorFor(x => x.UserName, command.UserName);
        }
Exemplo n.º 3
0
        public void IsValid_WhenUserName_IsEmailAddress()
        {
            var userName = string.Format("{0}@domain.tld", Guid.NewGuid());
            var command  = new FakeMustBeValidUserNameCommand
            {
                UserName = userName,
            };
            var validator = new FakeMustBeValidUserNameValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            validator.ShouldNotHaveValidationErrorFor(x => x.UserName, command.UserName);
        }
Exemplo n.º 4
0
        public void IsValid_WhenUserName_IsEmailAddress()
        {
            var userName = FakeData.Email();
            var command  = new FakeMustBeValidUserNameCommand
            {
                UserName = userName,
            };
            var validator = new FakeMustBeValidUserNameValidator();

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            validator.ShouldNotHaveValidationErrorFor(x => x.UserName, command.UserName);
        }
Exemplo n.º 5
0
        public void IsInvalid_WhenUserName_IsEmpty(string userName)
        {
            var command = new FakeMustBeValidUserNameCommand
            {
                UserName = userName,
            };
            var validator = new FakeMustBeValidUserNameValidator();

            var result = validator.Validate(command);

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

            result.Errors.Count(userNameError).ShouldEqual(1);
            result.Errors.Single(userNameError).ErrorMessage.ShouldEqual(Resources.notempty_error
                                                                         .Replace("{PropertyName}", User.Constraints.NameLabel)
                                                                         );
            validator.ShouldHaveValidationErrorFor(x => x.UserName, command.UserName);
        }