コード例 #1
0
            public void ThrowsArgumentNullException_WhenCommandArgIsNull()
            {
                var handler = new RedeemEmailConfirmationHandler(null);
                ArgumentNullException exception = null;
                try
                {
                    handler.Handle(null);
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("command");
                // ReSharper restore PossibleNullReferenceException
            }
コード例 #2
0
            public void ExecutesUpdate_OnEmailConfirmation_WhenNotRedeeed()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    EmailAddress = new EmailAddress(),
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(null as string);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>()).Returns(new[] { confirmation }.AsQueryable);
                entities.Setup(m => m.Update(It.Is(ConfirmationEntity(confirmation))));
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                handler.Handle(command);

                entities.Verify(m => m.Update(It.Is(ConfirmationEntity(confirmation))),
                    Times.Once());
            }
コード例 #3
0
            public void ExecutesQuery_ForEmailConfirmation()
            {
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = Guid.NewGuid(),
                };
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>())
                    .Returns(Enumerable.Empty<EmailConfirmation>().AsQueryable);
                var handler = new RedeemEmailConfirmationHandler(entities.Object);
                NullReferenceException exception = null;
                try
                {
                    handler.Handle(command);
                }
                catch (NullReferenceException ex)
                {
                    exception = ex;
                }

                entities.Verify(m => m.Get<EmailConfirmation>(), Times.Once());
                exception.ShouldNotBeNull();
            }
コード例 #4
0
            public void CopiesTicketValue_ToCommandProperty_WhenAlreadyRedeeed()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    EmailAddress = new EmailAddress(),
                    RedeemedOnUtc = DateTime.UtcNow.AddSeconds(-5),
                    Ticket = TwoFiftySixLengthString2,
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(TwoFiftySixLengthString1);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>()).Returns(new[] { confirmation }.AsQueryable);
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                handler.Handle(command);

                command.Ticket.ShouldNotBeNull();
                command.Ticket.Length.ShouldEqual(256);
                command.Ticket.ShouldEqual(confirmation.Ticket);
                command.Ticket.ShouldEqual(TwoFiftySixLengthString2);
            }
コード例 #5
0
            public void SetsConfirmationProperty_Ticket_WhenNotRedeeed()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    EmailAddress = new EmailAddress(),
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(TwoFiftySixLengthString2);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>()).Returns(new[] { confirmation }.AsQueryable);
                entities.Setup(m => m.Update(It.Is(ConfirmationEntity(confirmation))));
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                confirmation.Ticket.ShouldBeNull();
                handler.Handle(command);

                confirmation.Ticket.ShouldNotBeNull();
                confirmation.Ticket.Length.ShouldEqual(256);
            }
コード例 #6
0
            public void SetsNoConfirmationProperty_RedeemedOnUtc_WhenAlreadyRedeeed()
            {
                var redeemedOnUtc = DateTime.UtcNow.AddSeconds(-5);
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    EmailAddress = new EmailAddress(),
                    RedeemedOnUtc = redeemedOnUtc,
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(null as string);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>()).Returns(new[] { confirmation }.AsQueryable);
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                handler.Handle(command);

                confirmation.RedeemedOnUtc.HasValue.ShouldBeTrue();
                // ReSharper disable PossibleInvalidOperationException
                confirmation.RedeemedOnUtc.Value.ShouldEqual(redeemedOnUtc);
                // ReSharper restore PossibleInvalidOperationException
            }
コード例 #7
0
            public void SetsNoEmailAddressProperty_IsConfirmed_WhenAlreadyRedeeed()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.CreatePassword)
                {
                    EmailAddress = new EmailAddress(),
                    RedeemedOnUtc = DateTime.UtcNow.AddSeconds(-5),
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(null as string);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>())
                    .Returns(new[] { confirmation }.AsQueryable);
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                confirmation.EmailAddress.IsConfirmed.ShouldBeFalse();
                handler.Handle(command);

                confirmation.EmailAddress.IsConfirmed.ShouldBeFalse();
            }
コード例 #8
0
            public void SetsEmailAddressProperty_IsConfirmed_ToTrue_WhenNotRedeemed()
            {
                var confirmation = new EmailConfirmation(EmailConfirmationIntent.ResetPassword)
                {
                    EmailAddress = new EmailAddress(),
                };
                var command = new RedeemEmailConfirmationCommand
                {
                    Token = confirmation.Token,
                };
                var queryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict);
                var entities = new Mock<ICommandEntities>(MockBehavior.Strict).Initialize();
                entities.Setup(m => m.Get<EmailConfirmation>()).Returns(new[] { confirmation }.AsQueryable);
                entities.Setup(m => m.Update(It.Is(ConfirmationEntity(confirmation))));
                queryProcessor.Setup(m => m.Execute(It.Is(RandomSecretGeneration(256))))
                    .Returns(null as string);
                var handler = new RedeemEmailConfirmationHandler(entities.Object);

                confirmation.EmailAddress.IsConfirmed.ShouldBeFalse();
                handler.Handle(command);

                confirmation.EmailAddress.IsConfirmed.ShouldBeTrue();
            }