示例#1
0
        public void IsInvalid_WhenEmailAddress_IsAlreadyVerified()
        {
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail {
                EmailAddress = "*****@*****.**"
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == command.EmailAddress;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(new EmailAddress
            {
                Value      = command.EmailAddress,
                IsVerified = true,
            }));

            var result = validator.Validate(command);

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

            result.Errors.Count(targetError).ShouldEqual(1);
            result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.Validation_EmailAddress_IsAlreadyVerified
                                                                       .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                       .Replace("{PropertyValue}", command.EmailAddress)
                                                                       );
        }
示例#2
0
        public void IsInvalid_WhenEmailAddressLength_IsGreaterThan_MaxLength()
        {
            var emailAddress = "*****@*****.**";

            while (emailAddress.Length <= EmailAddress.Constraints.ValueMaxLength)
            {
                emailAddress = emailAddress.Replace("0", "a0");
            }
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail {
                EmailAddress = emailAddress
            };

            var result = validator.Validate(command);

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

            result.Errors.Count(targetError).ShouldEqual(1);
            result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.Validation_MaxLength
                                                                       .Replace("{PropertyName}", EmailAddress.Constraints.Label)
                                                                       .Replace("{MaxLength}", EmailAddress.Constraints.ValueMaxLength.ToString(CultureInfo.InvariantCulture))
                                                                       .Replace("{TotalLength}", command.EmailAddress.Length.ToString(CultureInfo.InvariantCulture))
                                                                       );
        }
示例#3
0
        public void IsValid_WhenAllRulesPass(EmailVerificationPurpose purpose)
        {
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail
            {
                EmailAddress     = "*****@*****.**",
                IsExpectingEmail = true,
                Purpose          = purpose,
                SendFromUrl      = "[send from this url]",
                VerifyUrlFormat  = "[here is the token:' {0}']",
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == command.EmailAddress;
            User user         = new ProxiedUser(FakeData.Id());
            var  emailAddress = new EmailAddress
            {
                Value = command.EmailAddress,
                User  = user,
            };

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(emailAddress));

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
        }
示例#4
0
        public void IsInvalid_WhenIsExpectingEmail_IsFalse()
        {
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail();

            var result = validator.Validate(command);

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

            result.Errors.Count(targetError).ShouldEqual(1);
            result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.Validation_SendVerificationEmail_IsExpectingEmail
                                                                       .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                       );
        }
示例#5
0
        public void IsInvalid_WhenEmailAddress_DoesNotMatchPattern(string emailAddress)
        {
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail
            {
                EmailAddress = emailAddress,
            };

            var result = validator.Validate(command);

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

            result.Errors.Count(targetError).ShouldEqual(1);
            result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.email_error
                                                                       .Replace("{PropertyName}", EmailAddress.Constraints.Label)
                                                                       .Replace("{PropertyValue}", command.EmailAddress)
                                                                       );
        }
示例#6
0
        public void IsInvalid_WhenPurpose_IsZero(EmailVerificationPurpose?purpose)
        {
            var queries   = new Mock <IProcessQueries>(MockBehavior.Strict);
            var validator = new ValidateSendVerificationEmailCommand(queries.Object);
            var command   = new SendVerificationEmail();

            if (purpose.HasValue)
            {
                command.Purpose = purpose.Value;
            }

            var result = validator.Validate(command);

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

            result.Errors.Count(targetError).ShouldEqual(1);
            result.Errors.Single(targetError).ErrorMessage.ShouldEqual(Resources.Validation_EmailVerificationPurpose_IsEmpty
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.Label.ToLower())
                                                                       );
        }