本文整理汇总了C#中AllReady.Controllers.AdminController.ConfirmEmail方法的典型用法代码示例。如果您正苦于以下问题:C# AdminController.ConfirmEmail方法的具体用法?C# AdminController.ConfirmEmail怎么用?C# AdminController.ConfirmEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Controllers.AdminController
的用法示例。
在下文中一共展示了AdminController.ConfirmEmail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsSuccessful
public async Task ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsSuccessful()
{
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings { DefaultAdminUsername = It.IsAny<string>() });
var sut = new AdminController(userManager.Object, null, Mock.Of<IMediator>(), settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
var result = await sut.ConfirmEmail("userId", "code") as ViewResult;
Assert.Equal(result.ViewName, "ConfirmEmail");
}
示例2: ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsUnsuccessful
public async Task ConfirmEmailReturnsCorrectViewWhenUsersConfirmationIsUnsuccessful()
{
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));
var sut = new AdminController(userManager.Object, null, null, null, null);
var result = await sut.ConfirmEmail("userId", "code") as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
示例3: ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully
public async Task ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully()
{
const string requestScheme = "requestScheme";
const string userId = "1";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser { Id = userId }));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings());
var urlHelper = new Mock<IUrlHelper>();
var sut = new AdminController(userManager.Object, null, Mock.Of<IMediator>(), settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(requestScheme);
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
urlHelper.Verify(x => x.Action(It.Is<UrlActionContext>(uac =>
uac.Action == "EditUser" &&
uac.Controller == "Site" &&
uac.Protocol == requestScheme &&
uac.Values.ToString() == $"{{ area = Admin, userId = {userId} }}")),
Times.Once);
}
示例4: CreateUserManagerMock
public async Task ConfirmEmailSendsSendApproveOrganizationUserAccountEmailWithCorrectDataWhenUsersEmailIsConfirmedSuccessfully()
{
const string defaultAdminUserName = "requestScheme";
const string callbackUrl = "callbackUrl";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings { DefaultAdminUsername = defaultAdminUserName });
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(callbackUrl);
var mediator = new Mock<IMediator>();
var sut = new AdminController(userManager.Object, null, mediator.Object, settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
mediator.Verify(x => x.SendAsync(It.Is<SendApproveOrganizationUserAccountEmail>(y => y.DefaultAdminUsername == defaultAdminUserName && y.CallbackUrl == callbackUrl)));
}
示例5: ConfirmEmailInvokesConfirmEmailAsyncWithCorrectUserAndCode
public async Task ConfirmEmailInvokesConfirmEmailAsyncWithCorrectUserAndCode()
{
const string code = "code";
var user = new ApplicationUser();
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(user));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));
var sut = new AdminController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(null, code);
userManager.Verify(x => x.ConfirmEmailAsync(user, code), Times.Once);
}
示例6: ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId
public async Task ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId()
{
const string userId = "userId";
var userManager = CreateUserManagerMock();
var sut = new AdminController(userManager.Object, null, null, null, null);
await sut.ConfirmEmail(userId, "code");
userManager.Verify(x => x.FindByIdAsync(userId), Times.Once);
}
示例7: ConfirmEmailReturnsErrorWhenCannotFindUserByUserId
public async Task ConfirmEmailReturnsErrorWhenCannotFindUserByUserId()
{
var userManager = CreateUserManagerMock();
var sut = new AdminController(userManager.Object, null, null, null, null);
var result = await sut.ConfirmEmail(null, "code") as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
示例8: ConfirmEmailInvokesSendEmailAsyncWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully
public async Task ConfirmEmailInvokesSendEmailAsyncWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully()
{
const string defaultAdminUserName = "requestScheme";
const string callbackUrl = "callbackUrl";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings { DefaultAdminUsername = defaultAdminUserName });
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(callbackUrl);
var emailSender = new Mock<IEmailSender>();
var sut = new AdminController(userManager.Object, null, emailSender.Object, null, settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
emailSender.Verify(x => x.SendEmailAsync(defaultAdminUserName, "Approve organization user account",
$"Please approve this account by clicking this <a href=\"{callbackUrl}\">link</a>"));
}
示例9: ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully
public async Task ConfirmEmailInvokesUrlActionWithCorrectParametersWhenUsersEmailIsConfirmedSuccessfully()
{
const string requestScheme = "requestScheme";
var userManager = CreateUserManagerMock();
userManager.Setup(x => x.FindByIdAsync(It.IsAny<string>())).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.ConfirmEmailAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
var settings = new Mock<IOptions<SampleDataSettings>>();
settings.Setup(x => x.Value).Returns(new SampleDataSettings());
var urlHelper = new Mock<IUrlHelper>();
var sut = new AdminController(userManager.Object, null, Mock.Of<IEmailSender>(), null, settings.Object, null);
sut.SetFakeHttpRequestSchemeTo(requestScheme);
sut.Url = urlHelper.Object;
await sut.ConfirmEmail(It.IsAny<string>(), "code");
//note: I can't test the Values part here b/c I do not have control over the Id generation on ApplicationUser b/c it's new'ed up in the controller
urlHelper.Verify(x => x.Action(It.Is<UrlActionContext>(uac =>
uac.Action == "EditUser" &&
uac.Controller == "Site" &&
uac.Protocol == requestScheme)),
Times.Once);
}