Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 3
0
        public void IsValid_WhenEmailAddress_IsNotFound()
        {
            var emailAddress = FakeData.Email();
            var queries      = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command      = new FakeMustBeVerifiableEmailAddressCommand {
                EmailAddress = emailAddress
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == emailAddress;

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

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldNotHaveValidationErrorFor(x => x.EmailAddress, command.EmailAddress);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
Esempio n. 4
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);
        }