本文整理汇总了C#中AllReady.Areas.Admin.Controllers.SiteController类的典型用法代码示例。如果您正苦于以下问题:C# SiteController类的具体用法?C# SiteController怎么用?C# SiteController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SiteController类属于AllReady.Areas.Admin.Controllers命名空间,在下文中一共展示了SiteController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfirmDeletUserSendsDeleteUserCommandAsync
public async Task ConfirmDeletUserSendsDeleteUserCommandAsync()
{
var mediator = new Mock<IMediator>();
var controller = new SiteController(null, null, null, null, mediator.Object);
const string userId = "foo_id";
await controller.ConfirmDeleteUser(userId);
mediator.Verify(b => b.SendAsync(It.Is<DeleteUserCommand>(u => u.UserId == userId)));
}
示例2: DeleteUserSendsUserQueryWithCorrectUserId
public async Task DeleteUserSendsUserQueryWithCorrectUserId()
{
var mediator = new Mock<IMediator>();
const string userId = "foo_id";
mediator.Setup(x => x.SendAsync(It.Is<UserQuery>(q => q.UserId == userId))).ReturnsAsync(new EditUserModel());
var controller = new SiteController(null, null, mediator.Object);
await controller.DeleteUser(userId);
mediator.Verify(m =>m.SendAsync(It.Is<UserQuery>(q =>q.UserId == userId)), Times.Once);
}
示例3: DeleteUserReturnsTheCorrectViewModel
public async Task DeleteUserReturnsTheCorrectViewModel()
{
var mediator = new Mock<IMediator>();
const string userId = "foo_id";
mediator.Setup(x => x.SendAsync(It.IsAny<UserQuery>())).ReturnsAsync(new EditUserModel());
var controller = new SiteController(null, null, mediator.Object);
var result = await controller.DeleteUser(userId);
var model = ((ViewResult)result).ViewData.Model as DeleteUserModel;
Assert.Equal(model.UserId, userId);
Assert.IsType<DeleteUserModel>(model);
}
示例4: IndexReturnsCorrectViewModel
public async Task IndexReturnsCorrectViewModel()
{
var users = new List<ApplicationUser> { new ApplicationUser { Id = It.IsAny<string>() }, new ApplicationUser { Id = It.IsAny<string>() }};
var viewModel = new IndexViewModel { Users = users };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<IndexQuery>())).ReturnsAsync(viewModel);
var controller = new SiteController(null, null, mediator.Object);
var result = await controller.Index() as ViewResult;
var model = result.ViewData.Model as IndexViewModel;
Assert.Equal(model.Users.Count(), users.Count());
Assert.IsType<IndexViewModel>(model);
}
示例5: IndexReturnsCorrectViewModel
public void IndexReturnsCorrectViewModel()
{
var mediator = new Mock<IMediator>();
var users = new List<ApplicationUser>() {
new ApplicationUser {
Id = It.IsAny<string>()
},
new ApplicationUser {
Id = It.IsAny<string>()
}
};
mediator.Setup(x => x.Send(It.IsAny<AllUsersQuery>())).Returns(users);
var controller = new SiteController(null, null, mediator.Object);
var result = controller.Index();
var model = ((ViewResult)result).ViewData.Model as SiteAdminModel;
Assert.Equal(model.Users.Count(), users.Count());
Assert.IsType<SiteAdminModel>(model);
}
示例6: EditUserPostHasValidateAntiForgeryTokenAttribute
public void EditUserPostHasValidateAntiForgeryTokenAttribute()
{
var controller = new SiteController(null, null, null);
var attribute = controller.GetAttributesOn(x => x.EditUser(It.IsAny<EditUserModel>())).OfType<ValidateAntiForgeryTokenAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
}
示例7: 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);
}
}
示例8: ConfirmDeletUserInvokesFindByIdAsync
public async Task ConfirmDeletUserInvokesFindByIdAsync()
{
const string userId = "userId";
var userManager = CreateApplicationUserMock();
var controller = new SiteController(userManager.Object, null, null);
await controller.ConfirmDeleteUser(userId);
userManager.Verify(x => x.FindByIdAsync(userId), Times.Once);
}
示例9: RevokeOrganizationAdminHasHttpGetAttribute
public void RevokeOrganizationAdminHasHttpGetAttribute()
{
var controller = new SiteController(null, null,null);
var attribute = controller.GetAttributesOn(x => x.RevokeOrganizationAdmin(It.IsAny<string>())).OfType<HttpGetAttribute>().SingleOrDefault();
Assert.NotNull(attribute);
}
示例10: AssignSiteAdminRedirectsToCorrectAction
public async Task AssignSiteAdminRedirectsToCorrectAction()
{
var mediator = new Mock<IMediator>();
var userManager = CreateApplicationUserMock();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.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);
var result = (RedirectToActionResult) await controller.AssignSiteAdmin(user.Id);
Assert.Equal("Index", result.ActionName);
}
示例11: SearchForCorrectUserWhenGeneratingApiKeys
public async Task SearchForCorrectUserWhenGeneratingApiKeys()
{
var mediator = new Mock<IMediator>();
var logger = new Mock<ILogger<SiteController>>();
string userId = Guid.NewGuid().ToString();
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId))).Returns(new ApplicationUser());
var controller = new SiteController(null, logger.Object, mediator.Object);
await controller.GenerateToken(userId);
mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)), Times.Once);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}