コード例 #1
0
            public void DoesntSendAccountChangedEmailsIfConfirmationTokenDoesntMatch()
            {
                var user = new User
                {
                    EmailAddress            = "*****@*****.**",
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "the-token"
                };
                var controller = new TestableUsersController();

                controller.MockUserService
                .Setup(u => u.FindByUsername("username"))
                .Returns(user);
                controller.MockUserService
                .Setup(u => u.ConfirmEmailAddress(user, "faketoken"))
                .Returns(false);

                // act:
                var model = (controller.Confirm("username", "faketoken") as ViewResult).Model as EmailConfirmationModel;

                // verify:
                Assert.False(model.SuccessfulConfirmation);
                Assert.False(model.ConfirmingNewAccount);
                controller.MockMessageService
                .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny <MailAddress>(), It.IsAny <string>()), Times.Never());
                controller.MockMessageService
                .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(It.IsAny <User>(), It.IsAny <string>()), Times.Never());
            }
コード例 #2
0
            public void Returns404WhenTokenIsEmpty()
            {
                var controller = new TestableUsersController();

                var result = controller.Confirm("username", "") as HttpNotFoundResult;

                Assert.NotNull(result);
            }
コード例 #3
0
            public void ReturnsConfirmedWhenTokenMatchesUser()
            {
                var user = new User
                {
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "the-token"
                };
                var controller = new TestableUsersController();

                controller.MockUserService
                .Setup(u => u.FindByUsername("username"))
                .Returns(user);
                controller.MockUserService
                .Setup(u => u.ConfirmEmailAddress(user, "the-token"))
                .Returns(true);

                var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.True(model.SuccessfulConfirmation);
            }
コード例 #4
0
            public void ReturnsFalseWhenTokenDoesNotMatchUser()
            {
                var user = new User
                {
                    EmailAddress            = "*****@*****.**",
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "the-token"
                };
                var controller = new TestableUsersController();

                controller.MockUserService
                .Setup(u => u.FindByUsername("username"))
                .Returns(user);
                controller.MockUserService
                .Setup(u => u.ConfirmEmailAddress(user, "not-the-token"))
                .Returns(false);

                var model = (controller.Confirm("username", "not-the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.False(model.SuccessfulConfirmation);
            }
コード例 #5
0
            public void SendsAccountChangedNoticeWhenConfirmingChangedEmail()
            {
                var user = new User
                {
                    EmailAddress            = "*****@*****.**",
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken  = "the-token"
                };
                var controller = new TestableUsersController();

                controller.MockUserService
                .Setup(u => u.FindByUsername("username"))
                .Returns(user);
                controller.MockUserService
                .Setup(u => u.ConfirmEmailAddress(user, "the-token"))
                .Returns(true);

                var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.True(model.SuccessfulConfirmation);
                Assert.False(model.ConfirmingNewAccount);
                controller.MockMessageService
                .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(user, "*****@*****.**"));
            }
コード例 #6
0
            public void ReturnsConfirmedWhenTokenMatchesUser()
            {
                var user = new User
                    {
                        UnconfirmedEmailAddress = "*****@*****.**",
                        EmailConfirmationToken = "the-token"
                    };
                var controller = new TestableUsersController();
                controller.MockUserService
                          .Setup(u => u.FindByUsername("username"))
                          .Returns(user);
                controller.MockUserService
                          .Setup(u => u.ConfirmEmailAddress(user, "the-token"))
                          .Returns(true);
                
                var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.True(model.SuccessfulConfirmation);
            }
コード例 #7
0
            public void Returns404WhenTokenIsEmpty()
            {
                var controller = new TestableUsersController();

                var result = controller.Confirm("username", "") as HttpNotFoundResult;

                Assert.NotNull(result);
            }
コード例 #8
0
            public void ReturnsFalseWhenTokenDoesNotMatchUser()
            {
                var user = new User
                    {
                        EmailAddress = "*****@*****.**",
                        UnconfirmedEmailAddress = "*****@*****.**",
                        EmailConfirmationToken = "the-token"
                    };
                var controller = new TestableUsersController();
                controller.MockUserService
                          .Setup(u => u.FindByUsername("username"))
                          .Returns(user);
                controller.MockUserService
                          .Setup(u => u.ConfirmEmailAddress(user, "not-the-token"))
                          .Returns(false);
                
                var model = (controller.Confirm("username", "not-the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.False(model.SuccessfulConfirmation);
            }
コード例 #9
0
            public void DoesntSendAccountChangedEmailsIfConfirmationTokenDoesntMatch()
            {
                var user = new User
                {
                    EmailAddress = "*****@*****.**",
                    UnconfirmedEmailAddress = "*****@*****.**",
                    EmailConfirmationToken = "the-token"
                };
                var controller = new TestableUsersController();
                controller.MockUserService
                          .Setup(u => u.FindByUsername("username"))
                          .Returns(user);
                controller.MockUserService
                          .Setup(u => u.ConfirmEmailAddress(user, "faketoken"))
                          .Returns(false);
                
                // act:
                var model = (controller.Confirm("username", "faketoken") as ViewResult).Model as EmailConfirmationModel;

                // verify:
                Assert.False(model.SuccessfulConfirmation);
                Assert.False(model.ConfirmingNewAccount);
                controller.MockMessageService
                          .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never());
                controller.MockMessageService
                          .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(It.IsAny<User>(), It.IsAny<string>()), Times.Never());
            }
コード例 #10
0
            public void SendsAccountChangedNoticeWhenConfirmingChangedEmail()
            {
                var user = new User
                    {
                        EmailAddress = "*****@*****.**",
                        UnconfirmedEmailAddress = "*****@*****.**",
                        EmailConfirmationToken = "the-token"
                    };
                var controller = new TestableUsersController();
                controller.MockUserService
                          .Setup(u => u.FindByUsername("username"))
                          .Returns(user);
                controller.MockUserService
                          .Setup(u => u.ConfirmEmailAddress(user, "the-token"))
                          .Returns(true);
                
                var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel;

                Assert.True(model.SuccessfulConfirmation);
                Assert.False(model.ConfirmingNewAccount);
                controller.MockMessageService
                          .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(user, "*****@*****.**"));
            }