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


C# SiteController.SetDefaultHttpContext方法代码示例

本文整理汇总了C#中AllReady.Areas.Admin.Controllers.SiteController.SetDefaultHttpContext方法的典型用法代码示例。如果您正苦于以下问题:C# SiteController.SetDefaultHttpContext方法的具体用法?C# SiteController.SetDefaultHttpContext怎么用?C# SiteController.SetDefaultHttpContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AllReady.Areas.Admin.Controllers.SiteController的用法示例。


在下文中一共展示了SiteController.SetDefaultHttpContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResetPasswordReturnsAView

        public async Task ResetPasswordReturnsAView()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            var user = new ApplicationUser()
            {
                Id = "1234",
                Email = "[email protected]",
                UserName = "auser"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
                .Returns(user);
            string code = "passcode";
            userManager.Setup(u => u.GeneratePasswordResetTokenAsync(user)).ReturnsAsync(code);

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            controller.Url = GetMockUrlHelper("any");
            var result = (ViewResult)await controller.ResetPassword(user.Id);

            Assert.IsType<ViewResult>(result);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:23,代码来源:SiteAdminControllerShould.cs

示例2: ResetPasswordAddsCorrectSuccessMessagetoViewBagWhenUserIsNotNull

        public async Task ResetPasswordAddsCorrectSuccessMessagetoViewBagWhenUserIsNotNull()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            var user = new ApplicationUser()
            {
                Id = "1234",
                Email = "[email protected]",
                UserName = "auser"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
                .Returns(user);
            string code = "passcode";
            userManager.Setup(u => u.GeneratePasswordResetTokenAsync(user)).ReturnsAsync(code);

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            controller.Url = GetMockUrlHelper("any");
            var result = await controller.ResetPassword(user.Id);
            Assert.Equal($"Sent password reset email for {user.UserName}.", controller.ViewBag.SuccessMessage);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:22,代码来源:SiteAdminControllerShould.cs

示例3: ResetPasswordSendsSendResetPasswordEmailWithCorrectDataWhenUserIsNotNull

        public async Task ResetPasswordSendsSendResetPasswordEmailWithCorrectDataWhenUserIsNotNull()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            var user = new ApplicationUser()
            {
                Id = "1234",
                Email = "[email protected]"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
                .Returns(user);
            string code = "passcode";
            userManager.Setup(u => u.GeneratePasswordResetTokenAsync(user)).ReturnsAsync(code);
            string url = String.Format("Admin/ResetPassword?userId={0}&code={1}", user.Id, code);
            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            controller.Url = GetMockUrlHelper(url);
            var result = await controller.ResetPassword(user.Id);

            mediator.Verify(x => x.SendAsync(It.Is<AllReady.Areas.Admin.Features.Site.SendResetPasswordEmail>(e => e.Email == user.Email && e.CallbackUrl == url)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:22,代码来源:SiteAdminControllerShould.cs

示例4: ResetPasswordInvokesGeneratePasswordResetTokenAsyncWithCorrectUserWhenUserIsNotNull

        public async Task ResetPasswordInvokesGeneratePasswordResetTokenAsyncWithCorrectUserWhenUserIsNotNull()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            var user = new ApplicationUser()
            {
                Id = "1234",
                Email = "[email protected]"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
                .Returns(user);

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            controller.Url = GetMockUrlHelper("any");
            var result = await controller.ResetPassword(user.Id);

            userManager.Verify(u => u.GeneratePasswordResetTokenAsync(user));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:20,代码来源:SiteAdminControllerShould.cs

示例5: CreateApplicationUserMock

        public async Task EditUserPostSendsSendAccountApprovalEmailWithCorrectDataWhenModelsIsOrganizationAdminIsTrueAndOrganizationAdminClaimWasAddedSuccessfully()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            EditUserViewModel model = new EditUserViewModel()
            {
                IsOrganizationAdmin = true,
                UserId = It.IsAny<string>()

            };
            var user = new ApplicationUser()
            {
                Id = model.UserId,
                Email = "[email protected]"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)))
                .Returns(user);
            userManager.Setup(x => x.AddClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>()))
                .Returns(() => Task.FromResult(IdentityResult.Success));

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            var expectedUrl = String.Format("Login/Admin?Email={0}", user.Email);
            controller.Url = GetMockUrlHelper(expectedUrl);
            await controller.EditUser(model);

            mediator.Verify(m => m.SendAsync(It.Is<SendAccountApprovalEmail>(q => q.Email == user.Email && q.CallbackUrl == expectedUrl ))
                            , Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:30,代码来源:SiteAdminControllerShould.cs

示例6: EditUserPostInvokesAddClaimAsyncWhenModelsIsOrganizationAdminIsTrue

        public async Task EditUserPostInvokesAddClaimAsyncWhenModelsIsOrganizationAdminIsTrue()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            EditUserViewModel model = new EditUserViewModel()
            {
                IsOrganizationAdmin = true,
                UserId = It.IsAny<string>()
                
            };
            var user = new ApplicationUser()
            {
                Id = model.UserId,
                Email = "[email protected]"
            };

            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)))
                .Returns(user);
            userManager.Setup(x => x.AddClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>()))
                .Returns(() => Task.FromResult(IdentityResult.Success));

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            controller.SetDefaultHttpContext();
            controller.Url = GetMockUrlHelper("any");
            await controller.EditUser(model);

            userManager.Verify(x => x.AddClaimAsync(user, It.Is<Claim>(c => c.Value == "OrgAdmin")), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:28,代码来源:SiteAdminControllerShould.cs


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