コード例 #1
0
        public void IsInvalid_WhenEmailAddress_IsFound_ButHasNullUser()
        {
            var emailAddress = FakeData.Email();
            var queries      = new Mock <IProcessQueries>(MockBehavior.Strict);
            var entity       = new ProxiedEmailAddress(FakeData.Id())
            {
                IsVerified = true,
                Value      = emailAddress,
            };
            var command = new FakeMustFindUserByVerifiedEmailCommand {
                EmailAddress = emailAddress
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == emailAddress;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(entity as EmailAddress));
            var validator = new FakeMustFindUserByVerifiedEmailValidator(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_CouldNotFind
                                                                      .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                      .Replace("{PropertyValue}", 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));
        }
コード例 #2
0
        public void IsValid_WhenEmailAddress_IsFound_WithNonNullUser()
        {
            var emailAddress = FakeData.Email();
            var queries      = new Mock <IProcessQueries>(MockBehavior.Strict);
            var user         = new User();
            var entity       = new ProxiedEmailAddress(FakeData.Id())
            {
                IsVerified = true,
                Value      = emailAddress,
                User       = user,
            };
            var command = new FakeMustFindUserByVerifiedEmailCommand {
                EmailAddress = emailAddress
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Value == emailAddress;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(entity as EmailAddress));
            var validator = new FakeMustFindUserByVerifiedEmailValidator(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));
        }
コード例 #3
0
        public void IsInvalid_WhenEmailAddress_IsEmpty(string emailAddress)
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustFindUserByVerifiedEmailCommand {
                EmailAddress = emailAddress
            };

            queries.Setup(x => x.Execute(It.IsAny <EmailAddressBy>())).Returns(Task.FromResult(null as EmailAddress));
            var validator = new FakeMustFindUserByVerifiedEmailValidator(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_CouldNotFind
                                                                      .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                      .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);
        }