本文整理汇总了C#中AllReady.Areas.Admin.Controllers.SiteController.AssignOrganizationAdmin方法的典型用法代码示例。如果您正苦于以下问题:C# SiteController.AssignOrganizationAdmin方法的具体用法?C# SiteController.AssignOrganizationAdmin怎么用?C# SiteController.AssignOrganizationAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Areas.Admin.Controllers.SiteController
的用法示例。
在下文中一共展示了SiteController.AssignOrganizationAdmin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignOrganizationAdminPostRedirectsToCorrectActionIsUserIsNull
public async Task AssignOrganizationAdminPostRedirectsToCorrectActionIsUserIsNull()
{
var mediator = new Mock<IMediator>();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234"
};
ApplicationUser nullUser = null;
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(nullUser);
var controller = new SiteController(null, null, mediator.Object);
var result = (RedirectToActionResult)await controller.AssignOrganizationAdmin(model);
Assert.Equal("Index", result.ActionName);
}
示例2: AssignOrganizationAdminGetReturnsCorrectViewModel
public void AssignOrganizationAdminGetReturnsCorrectViewModel()
{
var mediator = new Mock<IMediator>();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Returns(user);
List<Organization> orgs = new List<Organization>();
orgs.Add(new Organization() { Id = 2, Name = "Borg" });
orgs.Add(new Organization() { Id = 1, Name = "Aorg" });
mediator.Setup(x => x.Send(It.IsAny<AllOrganizationsQuery>())).Returns(orgs);
var controller = new SiteController(null, null, mediator.Object);
var result = (ViewResult)controller.AssignOrganizationAdmin(user.Id);
Assert.IsType<AssignOrganizationAdminViewModel>(result.Model);
}
示例3: AssignOrganizationAdminPostSendsUserByUserIdQueryWithCorrectUserId
public async Task AssignOrganizationAdminPostSendsUserByUserIdQueryWithCorrectUserId()
{
var mediator = new Mock<IMediator>();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234"
};
var controller = new SiteController(null, null, mediator.Object);
await controller.AssignOrganizationAdmin(model);
mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId)), Times.Once);
}
示例4: AssignOrganizationAdminGetSendsAllOrganizationsQuery
public void AssignOrganizationAdminGetSendsAllOrganizationsQuery()
{
var mediator = new Mock<IMediator>();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Returns(user);
var controller = new SiteController(null, null, mediator.Object);
var result = controller.AssignOrganizationAdmin(user.Id);
mediator.Verify(m => m.Send(It.IsAny<AllOrganizationsQuery>()), Times.Once);
}
示例5: AssignOrganizationAdminGetAddsCorrectSelectListItemToOrganizationsOnViewBag
public void AssignOrganizationAdminGetAddsCorrectSelectListItemToOrganizationsOnViewBag()
{
var mediator = new Mock<IMediator>();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Returns(user);
List<Organization> orgs = new List<Organization>();
orgs.Add(new Organization() { Id = 2, Name = "Borg" });
orgs.Add(new Organization() { Id = 1, Name = "Aorg" });
mediator.Setup(x => x.Send(It.IsAny<AllOrganizationsQuery>())).Returns(orgs);
var controller = new SiteController(null, null, mediator.Object);
var result = controller.AssignOrganizationAdmin(user.Id);
List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> viewBagOrgs =
((IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem>)controller.ViewBag.Organizations).ToList();
Assert.Equal(3, viewBagOrgs.Count);
Assert.Equal("0", viewBagOrgs[0].Value); // Select One item added in controller
Assert.Equal("1", viewBagOrgs[1].Value); // sorted items
Assert.Equal("2", viewBagOrgs[2].Value);
}
示例6: AssignOrganizationAdminGetSendsUserByUserIdQueryWithCorrectUserId
public void AssignOrganizationAdminGetSendsUserByUserIdQueryWithCorrectUserId()
{
var mediator = new Mock<IMediator>();
string userId = "1234";
var controller = new SiteController(null, null, mediator.Object);
controller.AssignOrganizationAdmin(userId);
mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)), Times.Once);
}
示例7: AssignOrganizationAdminGetRedirectsToCorrectActionWhenUserIsASiteAdmin
public void AssignOrganizationAdminGetRedirectsToCorrectActionWhenUserIsASiteAdmin()
{
var mediator = new Mock<IMediator>();
var user = new ApplicationUser()
{
Id = "1234"
};
user.Claims.Add(new Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim<string>()
{
ClaimType = AllReady.Security.ClaimTypes.UserType,
ClaimValue = Enum.GetName(typeof(UserType), UserType.SiteAdmin)
});
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Returns(user);
var controller = new SiteController(null, null, mediator.Object);
var result = (RedirectToActionResult)controller.AssignOrganizationAdmin(user.Id);
Assert.Equal("Index", result.ActionName);
}
示例8: AssignOrganizationAdminPostAddsCorrectKeyAndErrorMessageToModelStateWhenOrganzationNotFound
public async Task AssignOrganizationAdminPostAddsCorrectKeyAndErrorMessageToModelStateWhenOrganzationNotFound()
{
var mediator = new Mock<IMediator>();
var userManager = CreateApplicationUserMock();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234",
OrganizationId = 5678
};
ApplicationUser user = new ApplicationUser() { UserName = "name" };
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(user);
List<Organization> orgs = new List<Organization>();
orgs.Add(new Organization() { Id = 9123, Name = "Borg" });
mediator.Setup(x => x.Send(It.IsAny<AllOrganizationsQuery>())).Returns(orgs);
var controller = new SiteController(userManager.Object, null, mediator.Object);
var result = await controller.AssignOrganizationAdmin(model);
Assert.False(controller.ModelState.IsValid);
Assert.True(controller.ModelState.ContainsKey("OrganizationId"));
Assert.True(controller.ModelState.GetErrorMessagesByKey("OrganizationId").FirstOrDefault(x => x.ErrorMessage.Equals("Invalid Organization. Please contact support.")) != null);
}
示例9: AssignOrganizationAdminPostReturnsAView
public async Task AssignOrganizationAdminPostReturnsAView()
{
var mediator = new Mock<IMediator>();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234",
OrganizationId = 0
};
ApplicationUser user = new ApplicationUser() { UserName = "name" };
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(user);
var controller = new SiteController(null, null, mediator.Object);
var result = (IActionResult) await controller.AssignOrganizationAdmin(model);
Assert.IsType<ViewResult>(result);
}
示例10: CreateApplicationUserMock
public async Task AssignOrganizationAdminPostRedirectsToCorrectActionWhenOrganizationIdOnModelMatchesAnyExistingOrganization()
{
var mediator = new Mock<IMediator>();
var userManager = CreateApplicationUserMock();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234",
OrganizationId = 5678
};
ApplicationUser user = new ApplicationUser() { UserName = "name" };
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(user);
List<Organization> orgs = new List<Organization>();
orgs.Add(new Organization() { Id = 5678, Name = "Borg" });
mediator.Setup(x => x.Send(It.IsAny<AllOrganizationsQuery>())).Returns(orgs);
var controller = new SiteController(userManager.Object, null, mediator.Object);
var result = (RedirectToActionResult) await controller.AssignOrganizationAdmin(model);
Assert.Equal("Index", result.ActionName);
}
示例11: AssignOrganizationAdminPostSendsAllOrganizationsQueryWhenModelStateIsValid
public async Task AssignOrganizationAdminPostSendsAllOrganizationsQueryWhenModelStateIsValid()
{
var mediator = new Mock<IMediator>();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234",
OrganizationId = 5678
};
ApplicationUser user = new ApplicationUser() { UserName = "name" };
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(user);
var controller = new SiteController(null, null, mediator.Object);
var result = await controller.AssignOrganizationAdmin(model);
mediator.Verify(x => x.Send(It.IsAny<AllOrganizationsQuery>()), Times.Once);
}
示例12: AssignOrganizationAdminPostAddsCorrectKeyAndErrorMessageToModelStateWhenOrganizationIdIsZero
public async Task AssignOrganizationAdminPostAddsCorrectKeyAndErrorMessageToModelStateWhenOrganizationIdIsZero()
{
var mediator = new Mock<IMediator>();
AssignOrganizationAdminViewModel model = new AssignOrganizationAdminViewModel()
{
UserId = "1234"
};
ApplicationUser user = new ApplicationUser() { UserName = "name" };
mediator.Setup(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == model.UserId))).Returns(user);
var controller = new SiteController(null, null, mediator.Object);
var result = await controller.AssignOrganizationAdmin(model);
Assert.False(controller.ModelState.IsValid);
Assert.True(controller.ModelState.ContainsKey("OrganizationId"));
Assert.True(controller.ModelState.GetErrorMessagesByKey("OrganizationId").FirstOrDefault(x => x.ErrorMessage.Equals("You must pick a valid organization.")) != null);
}
示例13: 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);
}