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


C# AdminController.SendCode方法代码示例

本文整理汇总了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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:23,代码来源:AdminControllerTests.cs

示例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");
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:12,代码来源:AdminControllerTests.cs

示例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)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:21,代码来源:AdminControllerTests.cs

示例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");
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:9,代码来源:AdminControllerTests.cs

示例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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:15,代码来源:AdminControllerTests.cs

示例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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:8,代码来源:AdminControllerTests.cs

示例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());
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:23,代码来源:AdminControllerTests.cs

示例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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:16,代码来源:AdminControllerTests.cs

示例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");
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:8,代码来源:AdminControllerTests.cs

示例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));
        }
开发者ID:mmoore99,项目名称:allReady,代码行数:22,代码来源:AdminControllerTests.cs


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