本文整理汇总了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());
}
示例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());
}
示例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>()));
}
示例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();
}
示例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();
}
示例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());
}
示例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());
}
示例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>()));
}