public void IsInvalid_WhenEmailVerificationByTicket_HasSecretNotEqualToCommandSecret()
        {
            string secret  = FakeData.String().ToUpper();
            string ticket  = FakeData.String();
            var    queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var    command = new FakeMustBeVerifiedEmailSecretCommand {
                Secret = secret, Ticket = ticket,
            };
            var entity = new EmailVerification {
                Secret = secret.ToLower(), Ticket = ticket,
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == command.Ticket;

            queries.Setup(x => x.Execute(It.Is(expectedQuery))).Returns(Task.FromResult(entity));
            var validator = new FakeMustBeVerifiedEmailSecretValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(secretError).ShouldEqual(1);
            result.Errors.Single(secretError).ErrorMessage.ShouldEqual(Resources
                                                                       .Validation_EmailVerificationSecret_IsWrong
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.SecretLabel.ToLower())
                                                                       .Replace("{PropertyValue}", command.Secret)
                                                                       );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldHaveValidationErrorFor(x => x.Secret, command);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
        public void IsValid_WhenSecret_IsEmpty(string secret)
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeVerifiedEmailSecretCommand
            {
                Secret = secret,
            };
            var validator = new FakeMustBeVerifiedEmailSecretValidator(queries.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
            validator.ShouldNotHaveValidationErrorFor(x => x.Secret, command);
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
        }
        public void IsValid_WhenEmailVerificationByTicket_IsNotFound()
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeVerifiedEmailSecretCommand
            {
                Secret = FakeData.String(),
                Ticket = FakeData.String(),
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == command.Ticket;

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

            var result = validator.Validate(command);

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