public void IsValid_WhenEmailVerificationByTicket_HasEmailMatchingUserName_CaseInsensitively(
            string userName, string ticketEmail)
        {
            string       ticket       = FakeData.String();
            var          queries      = new Mock <IProcessQueries>(MockBehavior.Strict);
            EmailAddress emailAddress = new ProxiedEmailAddress(FakeData.Id())
            {
                Value = ticketEmail,
            };
            EmailVerification verification = new ProxiedEmailVerification(FakeData.Id())
            {
                Ticket       = ticket,
                EmailAddress = emailAddress,
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == ticket;

            queries.Setup(x => x.Execute(It.Is(expectedQuery)))
            .Returns(Task.FromResult(verification));
            var command = new FakeMustNotBeUnverifiedEmailUserNameCommand
            {
                UserName = userName,
                Ticket   = ticket,
            };
            var validator = new FakeMustNotBeUnverifiedEmailUserNameValidator(queries.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressesBy>()), Times.Never);
            validator.ShouldNotHaveValidationErrorFor(x => x.UserName, command);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressesBy>()), Times.Never);
        }
        public void IsInvalid_WhenEmailVerificationByTicket_HasEmailNotMatchingUserName(
            string userName, string ticketEmail)
        {
            string       ticket       = FakeData.String();
            var          queries      = new Mock <IProcessQueries>(MockBehavior.Strict);
            EmailAddress emailAddress = new ProxiedEmailAddress(FakeData.Id())
            {
                Value = ticketEmail,
            };
            EmailVerification verification = new ProxiedEmailVerification(FakeData.Id())
            {
                Ticket       = ticket,
                EmailAddress = emailAddress,
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == ticket;

            queries.Setup(x => x.Execute(It.Is(expectedQuery)))
            .Returns(Task.FromResult(verification));
            var command = new FakeMustNotBeUnverifiedEmailUserNameCommand
            {
                UserName = userName,
                Ticket   = ticket,
            };
            var validator = new FakeMustNotBeUnverifiedEmailUserNameValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(ticketError).ShouldEqual(1);
            result.Errors.Single(ticketError).ErrorMessage.ShouldEqual(Resources
                                                                       .Validation_UserName_AllowedEmailAddress
                                                                       .Replace("{PropertyName}", User.Constraints.NameLabel.ToLower())
                                                                       .Replace("{PropertyValue}", userName)
                                                                       );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressesBy>()), Times.Never);
            validator.ShouldHaveValidationErrorFor(x => x.UserName, command);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
            queries.Verify(x => x.Execute(It.IsAny <EmailAddressesBy>()), Times.Never);
        }