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


C# Controllers.AccountController类代码示例

本文整理汇总了C#中AllReady.Controllers.AccountController的典型用法代码示例。如果您正苦于以下问题:C# AccountController类的具体用法?C# AccountController怎么用?C# AccountController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AccountController类属于AllReady.Controllers命名空间,在下文中一共展示了AccountController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExternalLoginConfirmationInvokesSignInAsyncWithCorrectParameters_WhenExternalLoginIsAddedSuccessfully

        public async Task ExternalLoginConfirmationInvokesSignInAsyncWithCorrectParameters_WhenExternalLoginIsAddedSuccessfully()
        {
            var userManager = CreateUserManagerMockWithSucessIdentityResult();
            var signInManager = CreateSignInManagerMock(userManager);
            SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
            SetupSignInManagerWithDefaultSignInAsync(signInManager);
            var urlHelperMock = CreateUrlHelperMockObject();
            SetupUrlHelperMockToReturnTrueForLocalUrl(urlHelperMock);
            var viewModel = CreateExternalLoginConfirmationViewModel();

            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeUser("userId");
            sut.Url = urlHelperMock.Object;

            await sut.ExternalLoginConfirmation(viewModel, "testUrl");

            signInManager.Verify(s => s.SignInAsync(It.Is<ApplicationUser>(au => au.Email == viewModel.Email
                && au.FirstName == viewModel.FirstName
                && au.LastName == viewModel.LastName
                && au.PhoneNumber == viewModel.PhoneNumber),
                It.Is<bool>(p => p == false),
                It.Is<string>(auth => auth == null)));
        }
开发者ID:,项目名称:,代码行数:26,代码来源:

示例2: CreateUserManagerMock

        public async Task ForgotPasswordPostReturnsForgotPasswordConfirmationView_WhenModelStateIsValid_AndUserIsNotNull_AndUsersEmailHasBeenVerified()
        {
            const string email = "[email protected]";
            var vm = new ForgotPasswordViewModel { Email = email };
            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.IsEmailConfirmedAsync(user)).Returns(() => Task.FromResult(true));
            userManager.Setup(x => x.GeneratePasswordResetTokenAsync(user)).Returns(() => Task.FromResult(It.IsAny<string>()));

            var sut = new AccountController(userManager.Object, null, null, Mock.Of<IMediator>(), null);
            sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
            sut.Url = Mock.Of<IUrlHelper>();
            var result = await sut.ForgotPassword(vm) as ViewResult;

            Assert.Equal(result.ViewName, "ForgotPasswordConfirmation");
        }
开发者ID:,项目名称:,代码行数:18,代码来源:

示例3: ConfirmEmailInvokesConfirmEmailAsyncWithTheCorrectParameters_WhenUserAndUserIdAndTokenAreNotNull

        public async Task ConfirmEmailInvokesConfirmEmailAsyncWithTheCorrectParameters_WhenUserAndUserIdAndTokenAreNotNull()
        {
            const string userId = "userId";
            const string token = "someToken";
            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            await sut.ConfirmEmail(userId, token);

            userManager.Verify(x => x.ConfirmEmailAsync(It.Is<ApplicationUser>(y => y == user), It.Is<string>(y => y == token)), Times.Once);
        }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例4: ConfirmEmailReturnsConfirmEmailView_WhenUsersEmailCanBeConfirmed

        public async Task ConfirmEmailReturnsConfirmEmailView_WhenUsersEmailCanBeConfirmed()
        {
            const string userId = "userId";
            const string token = "someToken";
            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ConfirmEmailAsync(user, token)).Returns(() => Task.FromResult(IdentityResult.Success));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            var result = await sut.ConfirmEmail(userId, token) as ViewResult;

            Assert.Equal(result.ViewName, "ConfirmEmail");
        }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例5: RegisterPostInvokesCreateAsyncWithTheCorrectParameters_WhenModelStateIsValid

        public async Task RegisterPostInvokesCreateAsyncWithTheCorrectParameters_WhenModelStateIsValid()
        {
            const string defaultTimeZone = "DefaultTimeZone";

            var model = new RegisterViewModel { Email = "email", Password = "Password" };

            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = defaultTimeZone });

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));

            var sut = new AccountController(userManager.Object, null, generalSettings.Object, null, null);
            await sut.Register(model);

            userManager.Verify(x => x.CreateAsync(It.Is<ApplicationUser>(au =>
                au.UserName == model.Email &&
                au.Email == model.Email &&
                au.TimeZoneId == defaultTimeZone),
                model.Password), Times.Once);
        }
开发者ID:,项目名称:,代码行数:21,代码来源:

示例6: GeneralSettings

        public async Task RegisterPostInvokesUrlActionWithTheCorrectParameters_WhenModelStateIsValid_AndUserCreationIsSuccessful()
        {
            const string requestScheme = "requestScheme";

            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
            userManager.Setup(x => x.GenerateEmailConfirmationTokenAsync(It.IsAny<ApplicationUser>())).Returns(() => Task.FromResult(It.IsAny<string>()));
            userManager.Setup(x => x.GenerateChangePhoneNumberTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(It.IsAny<string>()));

            var signInManager = CreateSignInManagerMock(userManager);

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeHttpRequestSchemeTo(requestScheme);
            var urlHelper = new Mock<IUrlHelper>();
            sut.Url = urlHelper.Object;

            await sut.Register(new RegisterViewModel());

            urlHelper.Verify(mock => mock.Action(It.Is<UrlActionContext>(uac =>
                uac.Action == "ConfirmEmail" &&
                uac.Controller == "Account" &&
                uac.Protocol == requestScheme)),
                Times.Once);
        }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例7: ExternalLoginConfirmationAddsIdentityResultErrorsToModelStateError_WhenUserIsCreatedSuccessfully

        public async Task ExternalLoginConfirmationAddsIdentityResultErrorsToModelStateError_WhenUserIsCreatedSuccessfully()
        {
            var userManager = CreateUserManagerMock();
            userManager.Setup(u => u.CreateAsync(It.IsAny<ApplicationUser>())).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddLoginAsync(It.IsAny<ApplicationUser>(), It.IsAny<ExternalLoginInfo>()))
                .Returns(Task.FromResult(IdentityResult.Failed(
                    new IdentityError { Code = "TestCode1", Description = "TestDescription1" },
                    new IdentityError { Code = "TestCode2", Description = "TestDescription2" }
                )));

            var signInManager = CreateSignInManagerMock(userManager);
            SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
            SetupSignInManagerWithDefaultSignInAsync(signInManager);
            var urlHelperMock = CreateUrlHelperMockObject();
            SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
            var viewModel = CreateExternalLoginConfirmationViewModel();
            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeUser("userId");
            sut.Url = urlHelperMock.Object;
            var result = await sut.ExternalLoginConfirmation(viewModel, "http://localUrl") as ViewResult;

            Assert.Equal(result.ViewData.ModelState.ErrorCount, 2);
            var firstModelStateError = result.ViewData.ModelState.Values.FirstOrDefault().Errors.FirstOrDefault();
            var secondModelStateError = result.ViewData.ModelState.Values.FirstOrDefault().Errors.Skip(1).FirstOrDefault();
            Assert.Equal(firstModelStateError.ErrorMessage, "TestDescription1");
            Assert.Equal(secondModelStateError.ErrorMessage, "TestDescription2");
        }
开发者ID:,项目名称:,代码行数:30,代码来源:

示例8: AccountController

        private static AccountController AccountController(Microsoft.AspNetCore.Identity.SignInResult signInResult = default(Microsoft.AspNetCore.Identity.SignInResult))
        {
            var userManagerMock = CreateUserManagerMock();
            var signInManagerMock = CreateSignInManagerMock(userManagerMock);
            signInManagerMock.Setup(mock => mock.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
                .ReturnsAsync(signInResult == default(Microsoft.AspNetCore.Identity.SignInResult) ? Microsoft.AspNetCore.Identity.SignInResult.Success : signInResult);

            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock.Setup(mock => mock.IsLocalUrl(It.Is<string>(x => x.StartsWith("http")))).Returns(false);
            urlHelperMock.Setup(mock => mock.IsLocalUrl(It.Is<string>(x => !x.StartsWith("http")))).Returns(true);
            var controller = new AccountController(userManagerMock.Object, signInManagerMock.Object, Mock.Of<IOptions<GeneralSettings>>(), Mock.Of<IMediator>(), null)
            {
                Url = urlHelperMock.Object
            };

            return controller;
        }
开发者ID:,项目名称:,代码行数:17,代码来源:

示例9: CreateUserManagerMockWithSucessIdentityResult

        public async Task ExternalLoginConfirmationRedirectsToCorrectActionAndContrller_WhenUrlIsNotLocalUrl_AndUserIsNeitherSiteAdminOrOrgAdmin()
        {
            var userManager = CreateUserManagerMockWithSucessIdentityResult();
            var signInManager = CreateSignInManagerMock(userManager);
            SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
            SetupSignInManagerWithDefaultSignInAsync(signInManager);
            var urlHelperMock = CreateUrlHelperMockObject();
            SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
            var viewModel = CreateExternalLoginConfirmationViewModel();
            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeUser("userId");
            sut.Url = urlHelperMock.Object;
            var result = await sut.ExternalLoginConfirmation(viewModel, "http://localUrl") as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(HomeController.Index));
            Assert.Equal(result.ControllerName, "Home");
        }
开发者ID:,项目名称:,代码行数:20,代码来源:

示例10: ExternalLoginConfirmationRedirectsToCorrectUrl_WhenUrlIsLocalUrl

        public async Task ExternalLoginConfirmationRedirectsToCorrectUrl_WhenUrlIsLocalUrl()
        {
            const string returnUrl = "localUrl";

            var userManager = CreateUserManagerMockWithSucessIdentityResult();
            var signInManager = CreateSignInManagerMock(userManager);
            SetupSignInManagerWithTestExternalLoginValue(signInManager, "test", "testKey", "testDisplayName");
            SetupSignInManagerWithDefaultSignInAsync(signInManager);
            var urlHelperMock = CreateUrlHelperMockObject();
            SetupUrlHelperMockToReturnResultBaseOnLineBegining(urlHelperMock);
            var viewModel = CreateExternalLoginConfirmationViewModel();

            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings { DefaultTimeZone = "DefaultTimeZone" });

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeUser("userId");
            sut.Url = urlHelperMock.Object;

            var result = await sut.ExternalLoginConfirmation(viewModel, returnUrl) as RedirectResult;

            Assert.Equal(result.Url, returnUrl);
        }
开发者ID:,项目名称:,代码行数:23,代码来源:

示例11: ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId_WhenUserIdAndTokenAreNotNull

        public async Task ConfirmEmailInvokesFindByIdAsyncWithCorrectUserId_WhenUserIdAndTokenAreNotNull()
        {
            const string userId = "userId";
            const string token = "someToken";
            var userManager = CreateUserManagerMock();
            var sut = new AccountController(userManager.Object, null, null, null, null);

            await sut.ConfirmEmail(userId, token);

            userManager.Verify(x => x.FindByIdAsync(It.Is<string>(y => y == userId)), Times.Once);
        }
开发者ID:,项目名称:,代码行数:11,代码来源:

示例12: ConfirmEmailReturnsErrorView_WhenUserIsNull_AndUserIdAndTokenAreNotNull

        public async Task ConfirmEmailReturnsErrorView_WhenUserIsNull_AndUserIdAndTokenAreNotNull()
        {
            const string userId = "userId";
            const string token = "someToken";

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.FindByIdAsync(userId)).Returns(() => Task.FromResult((ApplicationUser)null));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            var result = await sut.ConfirmEmail(userId, token) as ViewResult;

            Assert.Equal("Error", result.ViewName);
        }
开发者ID:,项目名称:,代码行数:13,代码来源:

示例13: RegisterPostRedirectsToCorrectActionAndController_WhenModelStateIsValid_AndUserCreationIsSuccessful

        public async Task RegisterPostRedirectsToCorrectActionAndController_WhenModelStateIsValid_AndUserCreationIsSuccessful()
        {
            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
            userManager.Setup(x => x.GenerateEmailConfirmationTokenAsync(It.IsAny<ApplicationUser>())).Returns(() => Task.FromResult(It.IsAny<string>()));
            userManager.Setup(x => x.GenerateChangePhoneNumberTokenAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(It.IsAny<string>()));

            var signInManager = CreateSignInManagerMock(userManager);

            var urlHelper = new Mock<IUrlHelper>();
            urlHelper.Setup(x => x.Action(It.IsAny<UrlActionContext>())).Returns(It.IsAny<string>());

            userManager.Setup(x => x.AddClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Success));
            signInManager.Setup(x => x.SignInAsync(It.IsAny<ApplicationUser>(), It.IsAny<bool>(), null)).Returns(() => Task.FromResult(It.IsAny<Task>()));

            var sut = new AccountController(userManager.Object, signInManager.Object, generalSettings.Object, Mock.Of<IMediator>(), null);
            sut.SetFakeHttpRequestSchemeTo(It.IsAny<string>());
            sut.Url = urlHelper.Object;

            var result = await sut.Register(new RegisterViewModel()) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(HomeController.Index));
            Assert.Equal(result.ControllerName, "Home");
        }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例14: ForgotPasswordPostInvokesIsEmailConfirmedAsyncWithThecorrectUser_WhenModelStateIsValid

        public async Task ForgotPasswordPostInvokesIsEmailConfirmedAsyncWithThecorrectUser_WhenModelStateIsValid()
        {
            const string email = "[email protected]";
            var vm = new ForgotPasswordViewModel { Email = email };

            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user)).Verifiable();

            var sut = new AccountController(userManager.Object, null, null, null, null);
            await sut.ForgotPassword(vm);

            userManager.Verify(m => m.IsEmailConfirmedAsync(user), Times.Once);
        }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例15: RegisterPostAddsIdentityResultErrorsToModelStateError_WhenUserCreationFails

        public async Task RegisterPostAddsIdentityResultErrorsToModelStateError_WhenUserCreationFails()
        {
            var generalSettings = new Mock<IOptions<GeneralSettings>>();
            generalSettings.Setup(x => x.Value).Returns(new GeneralSettings());

            var identityResult = IdentityResult.Failed(new IdentityError { Description = "IdentityErrorDescription" });

            var userManager = CreateUserManagerMock();
            userManager.Setup(x => x.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>())).Returns(() => Task.FromResult(identityResult));

            var sut = new AccountController(userManager.Object, null, generalSettings.Object, null, null);

            await sut.Register(new RegisterViewModel());

            var errorMessages = sut.ModelState.GetErrorMessages();
            Assert.Equal(errorMessages.Single(), identityResult.Errors.Select(x => x.Description).Single());
        }
开发者ID:,项目名称:,代码行数:17,代码来源:


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