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


C# SiteController.EditUser方法代码示例

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


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

示例1: EditUserGetReturnsCorrectViewModelWhenOrganizationIdIsNull

        public void EditUserGetReturnsCorrectViewModelWhenOrganizationIdIsNull()
        {
            {
                var mediator = new Mock<IMediator>();                

                string userId = It.IsAny<string>();
                mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)))
                                .Returns(new ApplicationUser());
                var controller = new SiteController(null, null, mediator.Object);

                var result = controller.EditUser(userId);
                var model = ((ViewResult)result).ViewData.Model as EditUserModel;

                Assert.Equal(model.Organization, null);
                Assert.IsType<EditUserModel>(model);
            }
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:17,代码来源:SiteAdminControllerShould.cs

示例2: EditUserPostRedirectsToCorrectAction

        public async Task EditUserPostRedirectsToCorrectAction()
        {
            var mediator = new Mock<IMediator>();

            string userId = It.IsAny<string>();
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)))
                            .Returns(new ApplicationUser());
            var controller = new SiteController(null, null, mediator.Object);

            var result = await controller.EditUser(new EditUserViewModel());

            Assert.IsType<RedirectToActionResult>(result);
            Assert.Equal("Index", ((RedirectToActionResult)result).ActionName);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:14,代码来源:SiteAdminControllerShould.cs

示例3: EditUserGetSendsUserByUserIdQueryWithCorrectUserId

        public void EditUserGetSendsUserByUserIdQueryWithCorrectUserId()
        {
            var mediator = new Mock<IMediator>();
            var logger = new Mock<ILogger<SiteController>>();

            string userId = It.IsAny<string>();
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)))
                .Returns(new ApplicationUser());
            var controller = new SiteController(null, logger.Object, mediator.Object);

            controller.EditUser(userId);
            mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)), Times.Once);
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:13,代码来源:SiteAdminControllerShould.cs

示例4: EditUserPostInvokesRemoveClaimAsyncWithCorrectParametersWhenUserIsAnOrganizationAdmin

        public async Task EditUserPostInvokesRemoveClaimAsyncWithCorrectParametersWhenUserIsAnOrganizationAdmin()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            EditUserViewModel model = new EditUserViewModel()
            {
                IsOrganizationAdmin = false,
                UserId = It.IsAny<string>()
            };
            var user = new ApplicationUser()
            {
                Id = model.UserId,
                Email = "[email protected]"
            };
            user.Claims.Add(new Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>()
                                    {
                                        ClaimType = AllReady.Security.ClaimTypes.UserType,
                                        ClaimValue = Enum.GetName(typeof(UserType), UserType.OrgAdmin)
                                    });

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

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            var result = await controller.EditUser(model);

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

示例5: CreateApplicationUserMock

        public async Task EditUserPostReturnsRedirectResultWithCorrectUrlWhenUserIsAnOrganizationAdminAndRemovClaimAsyncDoesNotSucceed()
        {
            var mediator = new Mock<IMediator>();
            var userManager = CreateApplicationUserMock();
            EditUserViewModel model = new EditUserViewModel()
            {
                IsOrganizationAdmin = false,
                UserId = It.IsAny<string>()
            };
            var user = new ApplicationUser()
            {
                Id = model.UserId,
                Email = "[email protected]"
            };
            user.Claims.Add(new Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>()
            {
                ClaimType = AllReady.Security.ClaimTypes.UserType,
                ClaimValue = Enum.GetName(typeof(UserType), UserType.OrgAdmin)
            });

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

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            var result = await controller.EditUser(model);

            Assert.IsType<RedirectResult>(result);
            Assert.Equal("Error", ((RedirectResult)result).Url);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:31,代码来源: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

示例7: EditUserPostSendsUpdateUserWithCorrectUserWhenUsersAssociatedSkillsAreNotNull

        public async Task EditUserPostSendsUpdateUserWithCorrectUserWhenUsersAssociatedSkillsAreNotNull()
        {
            var mediator = new Mock<IMediator>();
            EditUserViewModel model = new EditUserViewModel()
            {
                UserId = It.IsAny<string>(),
                AssociatedSkills = new List<UserSkill>() { new UserSkill() {Skill = It.IsAny<Skill>() } }
            };
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)))
                .Returns(new ApplicationUser());
            var controller = new SiteController(null, null, mediator.Object);

            await controller.EditUser(model);
            mediator.Verify(m => m.SendAsync(It.Is<UpdateUser>(q => q.User.AssociatedSkills[0].Skill == model.AssociatedSkills[0].Skill)), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:15,代码来源:SiteAdminControllerShould.cs

示例8: EditUserViewModel

        public async Task EditUserPostInvokesUpdateUserWithCorrectUserWhenUsersAssociatedSkillsAreNotNullAndThereIsAtLeastOneAssociatedSkillForTheUser()
        {
            var mediator = new Mock<IMediator>();
            EditUserViewModel model = new EditUserViewModel()
            {
                UserId = It.IsAny<string>(),
                AssociatedSkills = new List<UserSkill>() { new UserSkill() { SkillId = 1, Skill = new Skill() { Id = 1 } } }
            };
            var user = new ApplicationUser()
            {
                Id = model.UserId,
                AssociatedSkills = new List<UserSkill>() { new UserSkill() { SkillId = 2, Skill = new Skill() { Id = 2 } } }
            };
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)))
                .Returns(user);

            var controller = new SiteController(null, null, mediator.Object);

            await controller.EditUser(model);
            mediator.Verify(m => m.SendAsync(It.Is<UpdateUser>(q => q.User.AssociatedSkills[0] == model.AssociatedSkills[0])), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:21,代码来源:SiteAdminControllerShould.cs

示例9: EditUserPostSendsUserByUserIdQueryWithCorrectUserId

        public async Task EditUserPostSendsUserByUserIdQueryWithCorrectUserId()
        {
            var mediator = new Mock<IMediator>();
            EditUserViewModel model = new EditUserViewModel()
            {
                UserId = "1234",
            };
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)))
                .Returns(new ApplicationUser());
            var controller = new SiteController(null, null, mediator.Object);

            await controller.EditUser(model);
            mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:14,代码来源:SiteAdminControllerShould.cs

示例10: EditUserPostReturnsSameViewAndViewModelWhenModelStateIsInvalid

 public async Task EditUserPostReturnsSameViewAndViewModelWhenModelStateIsInvalid()
 {
     EditUserViewModel model = new EditUserViewModel()
     {
         UserId = "1234",
     };
     var controller = new SiteController(null, null, null);
     controller.ModelState.AddModelError("FakeKey", "FakeMessage");
     var result = (ViewResult)await controller.EditUser(model);
     Assert.Equal(result.Model, model);
 }
开发者ID:mheggeseth,项目名称:allReady,代码行数:11,代码来源:SiteAdminControllerShould.cs

示例11: EditUserGetReturnsCorrectValueForOrganiztionOnViewModelWhenOrganizationIdIsNotNull

        public void EditUserGetReturnsCorrectValueForOrganiztionOnViewModelWhenOrganizationIdIsNotNull()
        {
            var mediator = new Mock<IMediator>();
            var user = new ApplicationUser();
            int orgId = 99;
            string orgName = "Test Org";
            var org = new Organization() { Id = orgId, Name = orgName };
            string userId = It.IsAny<string>();
            user.Claims.Add(new Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>()
            {
                ClaimType = AllReady.Security.ClaimTypes.Organization,
                ClaimValue = orgId.ToString()
            });
            mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)))
                            .Returns(user);

            mediator.Setup(x => x.Send(It.Is<OrganizationByIdQuery>(q => q.OrganizationId == orgId)))
                            .Returns(org);

            var controller = new SiteController(null, null, mediator.Object);

            var result = controller.EditUser(userId);
            var model = ((ViewResult)result).ViewData.Model as EditUserViewModel;

            Assert.NotNull(model.Organization);
            Assert.IsType<EditUserViewModel>(model);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:27,代码来源:SiteAdminControllerShould.cs

示例12: CreateApplicationUserMock

        public async Task EditUserPostReturnsRedirectResultWithCorrectUrlWhenUserIsAnOrganizationAdminAndRemovClaimAsyncDoesNotSucceed()
        {
            var model = new EditUserViewModel { IsOrganizationAdmin = false, UserId = It.IsAny<string>() };

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

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).ReturnsAsync(user);

            var userManager = CreateApplicationUserMock();
            userManager.Setup(x => x.RemoveClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Failed(null)));

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            var result = await controller.EditUser(model);

            Assert.IsType<RedirectResult>(result);
            Assert.Equal("Error", ((RedirectResult)result).Url);
        }
开发者ID:ChrisDobby,项目名称:allReady,代码行数:19,代码来源:SiteAdminControllerShould.cs

示例13: EditUserPostInvokesRemoveClaimAsyncWithCorrectParameters_WhenUserIsAnOrganizationAdmin

        public async Task EditUserPostInvokesRemoveClaimAsyncWithCorrectParameters_WhenUserIsAnOrganizationAdmin()
        {
            var model = new EditUserViewModel { IsOrganizationAdmin = false, UserId = It.IsAny<string>() };

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

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).ReturnsAsync(user);

            var userManager = CreateApplicationUserMock();
            userManager.Setup(x => x.RemoveClaimAsync(It.IsAny<ApplicationUser>(), It.IsAny<Claim>())).Returns(() => Task.FromResult(IdentityResult.Success));

            var controller = new SiteController(userManager.Object, null, mediator.Object);
            await controller.EditUser(model);

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


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