예제 #1
0
        public void IsInvalid_WhenEmailAddress_IsFound_ButIsPrimary()
        {
            var emailAddress = new ProxiedEmailAddress(FakeData.Id())
            {
                Value     = FakeData.Email(),
                IsPrimary = true,
            };
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustNotBePrimaryEmailAddressCommand {
                EmailAddressId = emailAddress.Id
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Id == emailAddress.Id;

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

            var result = validator.Validate(command);

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

            result.Errors.Count(emailError).ShouldEqual(1);
            result.Errors.Single(emailError).ErrorMessage.ShouldEqual(Resources.Validation_EmailAddress_CannotBePrimary
                                                                      .Replace("{PropertyName}", EmailAddress.Constraints.Label.ToLower())
                                                                      );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldHaveValidationErrorFor(x => x.EmailAddressId, command.EmailAddressId);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
예제 #2
0
        public void IsValid_WhenEmailAddress_IsNotFound()
        {
            var emailAddressId = FakeData.Id();
            var queries        = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command        = new FakeMustNotBePrimaryEmailAddressCommand {
                EmailAddressId = emailAddressId
            };
            Expression <Func <EmailAddressBy, bool> > expectedQuery = x => x.Id == emailAddressId;

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

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldNotHaveValidationErrorFor(x => x.EmailAddressId, command.EmailAddressId);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }