コード例 #1
0
        public void IsValid_WhenEmailVerificationByTicket_IsAllowedPurpose(
            EmailVerificationPurpose entityPurpose, EmailVerificationPurpose allowedPurpose1, EmailVerificationPurpose?allowedPurpose2)
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBePurposedVerifyEmailTicketCommand
            {
                Ticket   = ticket,
                Purpose1 = allowedPurpose1,
                Purpose2 = allowedPurpose2,
            };
            var entity = new EmailVerification {
                Ticket = ticket, Purpose = entityPurpose,
            };
            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 FakeMustBePurposedVerifyEmailTicketValidator(queries.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldNotHaveValidationErrorFor(x => x.Ticket, command);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
コード例 #2
0
        public void IsInvalid_WhenEmailVerificationByTicket_IsNotAllowedPurpose(
            EmailVerificationPurpose entityPurpose, EmailVerificationPurpose allowedPurpose1, EmailVerificationPurpose?allowedPurpose2)
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBePurposedVerifyEmailTicketCommand
            {
                Ticket   = ticket,
                Purpose1 = allowedPurpose1,
                Purpose2 = allowedPurpose2,
            };
            var entity = new EmailVerification {
                Ticket = ticket, Purpose = entityPurpose,
            };
            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 FakeMustBePurposedVerifyEmailTicketValidator(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_IsWrongPurpose
                                                                       .Replace("{PropertyName}", EmailVerification.Constraints.Label.ToLower())
                                                                       );
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Once);
            validator.ShouldHaveValidationErrorFor(x => x.Ticket, command);
            queries.Verify(x => x.Execute(It.Is(expectedQuery)), Times.Exactly(2));
        }
コード例 #3
0
        public void IsValid_WhenTicket_IsNullOrWhitespace(string ticket)
        {
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBePurposedVerifyEmailTicketCommand
            {
                Ticket = ticket,
            };
            var validator = new FakeMustBePurposedVerifyEmailTicketValidator(queries.Object);

            var result = validator.Validate(command);

            result.IsValid.ShouldBeTrue();
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
            validator.ShouldNotHaveValidationErrorFor(x => x.Ticket, command);
            queries.Verify(x => x.Execute(It.IsAny <EmailVerificationBy>()), Times.Never);
        }
コード例 #4
0
        public void IsValid_WhenEmailVerificationByTicket_DoesNotExist()
        {
            var ticket  = FakeData.String();
            var queries = new Mock <IProcessQueries>(MockBehavior.Strict);
            var command = new FakeMustBePurposedVerifyEmailTicketCommand
            {
                Ticket = ticket,
            };
            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 FakeMustBePurposedVerifyEmailTicketValidator(queries.Object);

            var result = validator.Validate(command);

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