本文整理汇总了C#中AllReady.Models.ApplicationUser.MakeOrgAdmin方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUser.MakeOrgAdmin方法的具体用法?C# ApplicationUser.MakeOrgAdmin怎么用?C# ApplicationUser.MakeOrgAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Models.ApplicationUser
的用法示例。
在下文中一共展示了ApplicationUser.MakeOrgAdmin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsOrgAdmin
public void RedirectToCorrectActionResultWithCorrectRouteValues_WhenReturnUrlIsNotALocalUrl_AndUserIsOrgAdmin()
{
var applicationUser = new ApplicationUser();
applicationUser.MakeOrgAdmin();
//applicationUser.Claims.Add(new IdentityUserClaim<string>
//{
// ClaimType = AllReady.Security.ClaimTypes.UserType,
// ClaimValue = Enum.GetName(typeof(UserType), UserType.OrgAdmin)
//});
var urlHelper = new Mock<IUrlHelper>();
urlHelper.Setup(x => x.IsLocalUrl(It.IsAny<string>())).Returns(false);
var routeValueDictionary = new RouteValueDictionary
{
["area"] = "Admin"
};
var sut = new RedirectAccountControllerRequests();
var result = sut.RedirectToLocal(It.IsAny<string>(), applicationUser, urlHelper.Object) as RedirectToActionResult;
Assert.Equal(result.ActionName, nameof(AllReady.Areas.Admin.Controllers.CampaignController.Index));
Assert.Equal(result.ControllerName, "Campaign");
Assert.Equal(result.RouteValues, routeValueDictionary);
}
示例2: ApplicationUser
public async Task LoginPostReturnsErrorViewWithCorrectTextInViewData_WhenUserIsNotNull_AndUserIsAnOrgAdmin_AndUsersEmailIsNotConfirmed()
{
var applicationUser = new ApplicationUser();
applicationUser.MakeOrgAdmin();
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<ApplicationUserQuery>())).ReturnsAsync(applicationUser);
var userManager = MockHelper.CreateUserManagerMock();
userManager.Setup(x => x.IsEmailConfirmedAsync(applicationUser)).ReturnsAsync(false).Verifiable();
var signInManager = MockHelper.CreateSignInManagerMock(userManager);
signInManager.Setup(x => x.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Failed);
var sut = new AccountController(userManager.Object, signInManager.Object, null, mediator.Object, null, null);
var result = await sut.Login(new LoginViewModel()) as ViewResult;
Assert.Equal(result.ViewData["Message"], "You must have a confirmed email to log on.");
Assert.Equal(result.ViewName, "Error");
}
示例3: AssignOrganizationAdminGetRedirectsToCorrectActionWhenUserIsAnOrganizationAdmin
public async Task AssignOrganizationAdminGetRedirectsToCorrectActionWhenUserIsAnOrganizationAdmin()
{
var user = new ApplicationUser { Id = "1234" };
user.MakeOrgAdmin();
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.ReturnsAsync(user);
var controller = new SiteController(null, null, mediator.Object);
var result = (RedirectToActionResult) await controller.AssignOrganizationAdmin(user.Id);
Assert.Equal("Index", result.ActionName);
}
示例4: 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);
}
示例5: 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);
}