Exemple #1
0
        public void IsInvalid_WhenEmailAddress_IsGreaterThanMaxLength()
        {
            var emailAddress = FakeData.Email();

            while (emailAddress.Length < EmailAddress.Constraints.ValueMaxLength)
            {
                emailAddress = Guid.NewGuid() + emailAddress;
            }
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeVerifiableEmailAddressCommand {
                EmailAddress = emailAddress,
            };
            var validator = new FakeMustBeVerifiableEmailAddressValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(emailError).ShouldEqual(1);
            result.Errors.Single(emailError).ErrorMessage.ShouldEqual(Resources
                                                                      .Validation_MaxLength
                                                                      .Replace("{PropertyName}", EmailAddress.Constraints.Label)
                                                                      .Replace("{MaxLength}", EmailAddress.Constraints.ValueMaxLength
                                                                               .ToString(CultureInfo.InvariantCulture))
                                                                      .Replace("{TotalLength}", emailAddress.Length.ToString(CultureInfo.InvariantCulture))
                                                                      );
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressBy>()), Times.Never);
            validator.ShouldHaveValidationErrorFor(x => x.EmailAddress, command.EmailAddress);
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressBy>()), Times.Never);
        }
Exemple #2
0
        public void IsInvalid_WhenEmailAddress_IsFound_ButIsVerified()
        {
            EmailAddress emailAddress = new ProxiedEmailAddress(FakeData.Id())
            {
                Value      = FakeData.Email(),
                IsVerified = true,
            };
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeVerifiableEmailAddressCommand {
                EmailAddress = emailAddress.Value
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == emailAddress.Value;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(emailAddress));
            var validator = new FakeMustBeVerifiableEmailAddressValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(emailError).ShouldEqual(1);
            result.Errors.Single(emailError).ErrorMessage.ShouldEqual(Resources
                                                                      .Validation_EmailAddress_IsAlreadyVerified
                                                                      .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                      .Replace("{PropertyValue}", command.EmailAddress)
                                                                      );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldHaveValidationErrorFor(x => x.EmailAddress, command.EmailAddress);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
Exemple #3
0
        public void IsInvalid_WhenEmailAddress_DoesNotMatchEmailRegularExpression(string emailAddress)
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeVerifiableEmailAddressCommand {
                EmailAddress = emailAddress,
            };
            var validator = new FakeMustBeVerifiableEmailAddressValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(emailError).ShouldEqual(1);
            result.Errors.Single(emailError).ErrorMessage.ShouldEqual(Resources
                                                                      .email_error
                                                                      .Replace("{PropertyValue}", emailAddress)
                                                                      );
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressBy>()), Times.Never);
            validator.ShouldHaveValidationErrorFor(x => x.EmailAddress, command.EmailAddress);
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressBy>()), Times.Never);
        }