Esempio n. 1
0
        public void IsInvalid_WhenEmailVerification_IsAlreadyRedeemed()
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeRedeemableVerifyEmailTicketCommand {
                Ticket = ticket,
            };
            var entity = new EmailVerification
            {
                Ticket        = ticket,
                RedeemedOnUtc = DateTime.UtcNow.AddMinutes(-1),
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == ticket;

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

            var result = validator.Validate(command);

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

            result.Errors.Count(ticketError).ShouldEqual(1);
            result.Errors.Single(ticketError).ErrorMessage.ShouldEqual(Resources
                                                                       .Validation_EmailVerificationTicket_IsRedeemed
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.Label.ToLower())
                                                                       );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
            validator.ShouldHaveValidationErrorFor(x => x.Ticket, command.Ticket);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(4));
        }
Esempio n. 2
0
        public void IsInvalid_WhenEmailVerification_IsNotFoundByTicket()
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeRedeemableVerifyEmailTicketCommand {
                Ticket = ticket,
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == ticket;

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

            var result = validator.Validate(command);

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

            result.Errors.Count(ticketError).ShouldEqual(1);
            result.Errors.Single(ticketError).ErrorMessage.ShouldEqual(Resources
                                                                       .Validation_DoesNotExist_NoValue
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.Label)
                                                                       );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldHaveValidationErrorFor(x => x.Ticket, command.Ticket);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
Esempio n. 3
0
        public void IsInvalid_WhenTicket_IsEmpty(string ticket)
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeRedeemableVerifyEmailTicketCommand {
                Ticket = ticket,
            };
            var validator = new FakeMustBeRedeemableVerifyEmailTicketValidator(queries.Object);

            var result = validator.Validate(command);

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

            result.Errors.Count(ticketError).ShouldEqual(1);
            result.Errors.Single(ticketError).ErrorMessage.ShouldEqual(Resources
                                                                       .notempty_error
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.Label)
                                                                       );
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
            validator.ShouldHaveValidationErrorFor(x => x.Ticket, command.Ticket);
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
        }
Esempio n. 4
0
        public void IsValid_WhenEmailVerification_IsNotEmpty_AndIsFoundByTicket_AndIsNotRedeemed_AndIsNotExpired()
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBeRedeemableVerifyEmailTicketCommand {
                Ticket = ticket,
            };
            var entity = new EmailVerification
            {
                Ticket       = ticket,
                ExpiresOnUtc = DateTime.UtcNow.AddMinutes(1),
            };
            Expression <Func <EmailVerificationBy, bool> > expectedQuery = x => x.Ticket == ticket;

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

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(3));
            validator.ShouldNotHaveValidationErrorFor(x => x.Ticket, command.Ticket);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(6));
        }