本文整理汇总了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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}