本文整理汇总了C#中AllReady.Controllers.AdminController.SendCode方法的典型用法代码示例。如果您正苦于以下问题:C# AdminController.SendCode方法的具体用法?C# AdminController.SendCode怎么用?C# AdminController.SendCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Controllers.AdminController
的用法示例。
在下文中一共展示了AdminController.SendCode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendCodePostReturnsRedirectToActionResult
public async Task SendCodePostReturnsRedirectToActionResult()
{
var model = new SendCodeViewModel { SelectedProvider = string.Empty, ReturnUrl = "ReturnUrl", RememberMe = true };
var routeValues = new Dictionary<string, object>
{
["Provider"] = model.SelectedProvider,
["ReturnUrl"] = model.ReturnUrl,
["RememberMe"] = model.RememberMe
};
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser());
userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync("token");
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
var result = await sut.SendCode(model) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(AdminController.VerifyCode));
Assert.Equal(result.RouteValues, routeValues);
}
示例2: SendCodePostReturnsErrorViewWhenAuthenticationTokenIsNull
public async Task SendCodePostReturnsErrorViewWhenAuthenticationTokenIsNull()
{
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser());
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
var result = await sut.SendCode(new SendCodeViewModel()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
示例3: SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone
public async Task SendCodePostSendsSendSecurityCodeSmsWithCorrectDataWhenSelectedProviderIsPhone()
{
const string token = "token";
const string usersPhoneNumber = "usersPhoneNumber";
var applicationUser = new ApplicationUser();
var model = new SendCodeViewModel { SelectedProvider = "Phone" };
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
var mediator = new Mock<IMediator>();
userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(token);
userManager.Setup(x => x.GetPhoneNumberAsync(applicationUser)).ReturnsAsync(usersPhoneNumber);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);
var sut = new AdminController(userManager.Object, signInManager.Object, mediator.Object, null, null);
await sut.SendCode(model);
mediator.Verify(x => x.SendAsync(It.Is<SendSecurityCodeSms>(y => y.PhoneNumber == usersPhoneNumber && y.Token == token)));
}
示例4: SendCodePosReturnsErrorViewWhenUserIsNotFound
public async Task SendCodePosReturnsErrorViewWhenUserIsNotFound()
{
var signInManager = CreateSignInManagerMock();
var sut = new AdminController(null, signInManager.Object, null, null, null);
var result = await sut.SendCode(It.IsAny<SendCodeViewModel>()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
示例5: SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider
public async Task SendCodePostInvokesGenerateTwoFactorTokenAsyncWithCorrectUserAndTokenProvider()
{
var applicationUser = new ApplicationUser();
var model = new SendCodeViewModel { SelectedProvider = "Email" };
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
await sut.SendCode(model);
userManager.Verify(x => x.GenerateTwoFactorTokenAsync(applicationUser, model.SelectedProvider), Times.Once);
}
示例6: SendCodePostInvokesGetTwoFactorAuthenticationUserAsync
public async Task SendCodePostInvokesGetTwoFactorAuthenticationUserAsync()
{
var signInManager = CreateSignInManagerMock();
var sut = new AdminController(null, signInManager.Object, null, null, null);
await sut.SendCode(It.IsAny<SendCodeViewModel>());
signInManager.Verify(x => x.GetTwoFactorAuthenticationUserAsync(), Times.Once);
}
示例7: SendCodeGetReturnsSendCodeViewModelWithCorrectData
public async Task SendCodeGetReturnsSendCodeViewModelWithCorrectData()
{
const string returnUrl = "returnUrl";
const bool rememberMe = true;
var userFactors = new List<string> { "userFactor1", "userFactor2" };
var expectedProviders = userFactors.Select(factor => new SelectListItem { Text = factor, Value = factor }).ToList();
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).Returns(() => Task.FromResult(new ApplicationUser()));
userManager.Setup(x => x.GetValidTwoFactorProvidersAsync(It.IsAny<ApplicationUser>())).ReturnsAsync(userFactors);
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
var result = await sut.SendCode(returnUrl, rememberMe) as ViewResult;
var modelResult = result.ViewData.Model as SendCodeViewModel;
Assert.Equal(modelResult.ReturnUrl, returnUrl);
Assert.Equal(modelResult.RememberMe, rememberMe);
Assert.Equal(expectedProviders, modelResult.Providers, new SelectListItemComparer());
}
示例8: SendCodeGetInvokesGetValidTwoFactorProvidersAsyncWithCorrectUser
public async Task SendCodeGetInvokesGetValidTwoFactorProvidersAsyncWithCorrectUser()
{
var applicationUser = new ApplicationUser();
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).Returns(() => Task.FromResult(applicationUser));
userManager.Setup(x => x.GetValidTwoFactorProvidersAsync(It.IsAny<ApplicationUser>())).ReturnsAsync(new List<string>());
var sut = new AdminController(userManager.Object, signInManager.Object, null, null, null);
await sut.SendCode(null, It.IsAny<bool>());
userManager.Verify(x => x.GetValidTwoFactorProvidersAsync(applicationUser), Times.Once);
}
示例9: SendCodeGetReturnsErrorViewWhenCannotFindUser
public async Task SendCodeGetReturnsErrorViewWhenCannotFindUser()
{
var signInManager = CreateSignInManagerMock();
var sut = new AdminController(null, signInManager.Object, null, null, null);
var result = await sut.SendCode(null, It.IsAny<bool>()) as ViewResult;
Assert.Equal(result.ViewName, "Error");
}
示例10: SendCodePostInvokesSendSmsAsyncWithCorrectParametersWhenSelectedProviderIsPhone
public async Task SendCodePostInvokesSendSmsAsyncWithCorrectParametersWhenSelectedProviderIsPhone()
{
const string token = "token";
const string usersPhoneNumber = "usersPhoneNumber";
var message = $"Your security code is: {token}";
var applicationUser = new ApplicationUser();
var model = new SendCodeViewModel { SelectedProvider = "Phone" };
var userManager = CreateUserManagerMock();
var signInManager = CreateSignInManagerMock(userManager);
var smsSender = new Mock<ISmsSender>();
userManager.Setup(x => x.GenerateTwoFactorTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).ReturnsAsync(token);
userManager.Setup(x => x.GetPhoneNumberAsync(applicationUser)).ReturnsAsync(usersPhoneNumber);
signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(applicationUser);
var sut = new AdminController(userManager.Object, signInManager.Object, null, smsSender.Object, null, null);
await sut.SendCode(model);
smsSender.Verify(x => x.SendSmsAsync(usersPhoneNumber, message));
}