当前位置: 首页>>代码示例>>C#>>正文


C# User.UpdateEmailAddress方法代码示例

本文整理汇总了C#中NuGetGallery.User.UpdateEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:C# User.UpdateEmailAddress方法的具体用法?C# User.UpdateEmailAddress怎么用?C# User.UpdateEmailAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NuGetGallery.User的用法示例。


在下文中一共展示了User.UpdateEmailAddress方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoesNotSendEmailChangeConfirmationNoticeWhenUserWasNotConfirmed

            public async Task DoesNotSendEmailChangeConfirmationNoticeWhenUserWasNotConfirmed()
            {
                var user = new User
                {
                    Username = "aUsername",
                    UnconfirmedEmailAddress = "[email protected]",
                };

                GetMock<AuthenticationService>()
                    .Setup(u => u.Authenticate("aUsername", "password"))
                    .CompletesWith(new AuthenticatedUser(user, new Credential()));
                GetMock<IUserService>()
                    .Setup(u => u.ChangeEmailAddress(It.IsAny<User>(), It.IsAny<string>()))
                    .Callback(() => user.UpdateEmailAddress("[email protected]", () => "new-token"))
                    .Completes();
                var controller = GetController<UsersController>();
                controller.SetCurrentUser(user);

                var model = new AccountViewModel()
                {
                    ChangeEmail = new ChangeEmailViewModel
                    {
                        NewEmail = "[email protected]",
                        Password = "password"
                    }
                };

                await controller.ChangeEmail(model);

                Assert.Equal("Your new email address was saved!", controller.TempData["Message"]);
                GetMock<IUserService>()
                    .Verify(u => u.ChangeEmailAddress(user, "[email protected]"));
                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never());
            }
开发者ID:kamillangowski,项目名称:NuGetGallery,代码行数:35,代码来源:UsersControllerFacts.cs

示例2: DoesNotSendEmailChangeConfirmationNoticeWhenAddressDoesntChange

            public async Task DoesNotSendEmailChangeConfirmationNoticeWhenAddressDoesntChange()
            {
                var user = new User
                {
                    EmailAddress = "[email protected]",
                    Username = "aUsername",
                };

                var authResult =
                    new PasswordAuthenticationResult(PasswordAuthenticationResult.AuthenticationResult.Success, new AuthenticatedUser(user, new Credential()));

                GetMock<AuthenticationService>()
                    .Setup(u => u.Authenticate("aUsername", "password"))
                    .CompletesWith(authResult);
                GetMock<IUserService>()
                    .Setup(u => u.ChangeEmailAddress(It.IsAny<User>(), It.IsAny<string>()))
                    .Callback(() => user.UpdateEmailAddress("[email protected]", () => "new-token"));
                var controller = GetController<UsersController>();
                controller.SetCurrentUser(user);

                var model = new AccountViewModel()
                {
                    ChangeEmail = new ChangeEmailViewModel
                    {
                        NewEmail = "[email protected]",
                        Password = "password"
                    }
                };

                await controller.ChangeEmail(model);

                GetMock<IUserService>()
                    .Verify(u => u.ChangeEmailAddress(user, "[email protected]"), Times.Never());
                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never());
            }
开发者ID:NuGet,项目名称:NuGetGallery,代码行数:36,代码来源:UsersControllerFacts.cs

示例3: SendsEmailChangeConfirmationNoticeWhenChangingAConfirmedEmailAddress

            public async Task SendsEmailChangeConfirmationNoticeWhenChangingAConfirmedEmailAddress()
            {
                var user = new User
                {
                    Username = "theUsername",
                    EmailAddress = "[email protected]",
                    EmailAllowed = true
                };

                GetMock<AuthenticationService>()
                    .Setup(u => u.Authenticate("theUsername", "password"))
                    .CompletesWith(new AuthenticatedUser(user, new Credential()));
                GetMock<IUserService>()
                    .Setup(u => u.ChangeEmailAddress(user, "[email protected]"))
                    .Callback(() => user.UpdateEmailAddress("[email protected]", () => "token"))
                    .Completes();
                var controller = GetController<UsersController>();
                controller.SetCurrentUser(user);

                var model = new AccountViewModel()
                {
                    ChangeEmail = new ChangeEmailViewModel
                    {
                        NewEmail = "[email protected]",
                        Password = "password"
                    }
                };

                var result = await controller.ChangeEmail(model);

                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()));
            }
开发者ID:kamillangowski,项目名称:NuGetGallery,代码行数:33,代码来源:UsersControllerFacts.cs

示例4: ChangeEmailAddress

        public async Task ChangeEmailAddress(User user, string newEmailAddress)
        {
            var existingUsers = FindAllByEmailAddress(newEmailAddress);
            if (existingUsers.AnySafe(u => u.Key != user.Key))
            {
                throw new EntityException(Strings.EmailAddressBeingUsed, newEmailAddress);
            }

            await Auditing.SaveAuditRecord(new UserAuditRecord(user, UserAuditAction.ChangeEmail, newEmailAddress));

            user.UpdateEmailAddress(newEmailAddress, Crypto.GenerateToken);
            UserRepository.CommitChanges();
        }
开发者ID:hugoparedes,项目名称:NuGetGallery,代码行数:13,代码来源:UserService.cs

示例5: ChangeEmailAddress

        public void ChangeEmailAddress(User user, string newEmailAddress)
        {
            var existingUsers = FindAllByEmailAddress(newEmailAddress);
            if (existingUsers.AnySafe(u => u.Key != user.Key))
            {
                throw new EntityException(Strings.EmailAddressBeingUsed, newEmailAddress);
            }

            user.UpdateEmailAddress(newEmailAddress, Crypto.GenerateToken);
            UserRepository.CommitChanges();
        }
开发者ID:nicholaspei,项目名称:NuGetGallery,代码行数:11,代码来源:UserService.cs

示例6: DoesNotSendEmailChangeConfirmationNoticeWhenAddressDoesntChange

            public void DoesNotSendEmailChangeConfirmationNoticeWhenAddressDoesntChange()
            {
                var user = new User
                {
                    EmailAddress = "[email protected]",
                    Username = "aUsername",
                };

                GetMock<AuthenticationService>()
                          .Setup(u => u.Authenticate("aUsername", "password"))
                          .Returns(new AuthenticatedUser(user, new Credential()));
                GetMock<IUserService>()
                          .Setup(u => u.ChangeEmailAddress(It.IsAny<User>(), It.IsAny<string>()))
                          .Callback(() => user.UpdateEmailAddress("[email protected]", () => "new-token"));
                var controller = GetController<UsersController>();
                controller.SetCurrentUser(user);

                var model = new ChangeEmailRequestModel { NewEmail = "[email protected]", Password = "password" };

                controller.ChangeEmail(model);

                GetMock<IUserService>()
                    .Verify(u => u.ChangeEmailAddress(user, "[email protected]"), Times.Never());
                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never());
            }
开发者ID:kl4w,项目名称:NuGetGallery,代码行数:26,代码来源:UsersControllerFacts.cs

示例7: DoesNotSendEmailChangeConfirmationNoticeWhenUserWasNotConfirmed

            public void DoesNotSendEmailChangeConfirmationNoticeWhenUserWasNotConfirmed()
            {
                var user = new User
                {
                    Username = "aUsername",
                    UnconfirmedEmailAddress = "[email protected]",
                };

                var controller = GetController<UsersController>();
                controller.SetUser(user);
                GetMock<IUserService>()
                          .Setup(u => u.FindByUsernameAndPassword(It.IsAny<string>(), It.IsAny<string>()))
                          .Returns(user);
                GetMock<IUserService>()
                          .Setup(u => u.ChangeEmailAddress(It.IsAny<User>(), It.IsAny<string>()))
                          .Callback(() => user.UpdateEmailAddress("[email protected]", () => "new-token"));
                var model = new ChangeEmailRequestModel{ NewEmail = "[email protected]" };

                controller.ChangeEmail(model);

                Assert.Equal("Your new email address was saved!", controller.TempData["Message"]);
                GetMock<IUserService>()
                    .Verify(u => u.ChangeEmailAddress(user, "[email protected]"));
                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never());
            }
开发者ID:nicholaspei,项目名称:NuGetGallery,代码行数:26,代码来源:UsersControllerFacts.cs

示例8: SendsEmailChangeConfirmationNoticeWhenChangingAConfirmedEmailAddress

            public void SendsEmailChangeConfirmationNoticeWhenChangingAConfirmedEmailAddress()
            {
                var user = new User
                {
                    Username = "theUsername",
                    EmailAddress = "[email protected]",
                    EmailAllowed = true
                };

                var controller = GetController<UsersController>();
                controller.SetUser(user);

                GetMock<IUserService>()
                    .Setup(u => u.FindByUsernameAndPassword(It.IsAny<string>(), It.IsAny<string>()))
                    .Returns(user);
                GetMock<IUserService>()
                    .Setup(u => u.ChangeEmailAddress(user, "[email protected]"))
                    .Callback(() => user.UpdateEmailAddress("[email protected]", () => "token"));
                var model = new ChangeEmailRequestModel { NewEmail = "[email protected]" };

                var result = controller.ChangeEmail(model);

                GetMock<IMessageService>()
                    .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()));
            }
开发者ID:nicholaspei,项目名称:NuGetGallery,代码行数:25,代码来源:UsersControllerFacts.cs


注:本文中的NuGetGallery.User.UpdateEmailAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。