本文整理汇总了C#中AllReady.Areas.Admin.Controllers.SiteController.AssignSiteAdmin方法的典型用法代码示例。如果您正苦于以下问题:C# SiteController.AssignSiteAdmin方法的具体用法?C# SiteController.AssignSiteAdmin怎么用?C# SiteController.AssignSiteAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Areas.Admin.Controllers.SiteController
的用法示例。
在下文中一共展示了SiteController.AssignSiteAdmin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignSiteAdminSendsUserByUserIdQueryWithCorrectUserId
public async Task AssignSiteAdminSendsUserByUserIdQueryWithCorrectUserId()
{
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);
await controller.AssignSiteAdmin(userId);
mediator.Verify(m => m.Send(It.Is<UserByUserIdQuery>(q => q.UserId == userId)), Times.Once);
}
示例2: AssignSiteAdminReturnsAViewWhenExceptionIsThrown
public async Task AssignSiteAdminReturnsAViewWhenExceptionIsThrown()
{
var mediator = new Mock<IMediator>();
var logger = new Mock<ILogger<SiteController>>();
var userManager = CreateApplicationUserMock();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Throws<Exception>();
var controller = new SiteController(userManager.Object, logger.Object, mediator.Object);
var result = await controller.AssignSiteAdmin(user.Id);
Assert.IsType<ViewResult>(result);
}
示例3: AssignSiteAdminAddsCorrectErrorMessageToViewBagWhenExceptionIsThrown
public async Task AssignSiteAdminAddsCorrectErrorMessageToViewBagWhenExceptionIsThrown()
{
var mediator = new Mock<IMediator>();
var logger = new Mock<ILogger<SiteController>>();
var userManager = CreateApplicationUserMock();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Throws<Exception>();
var controller = new SiteController(userManager.Object, logger.Object, mediator.Object);
var result = await controller.AssignSiteAdmin(user.Id);
Assert.Equal($"Failed to assign site admin for {user.Id}. Exception thrown.", controller.ViewBag.ErrorMessage);
}
示例4: AssignSiteAdminInvokesLogErrorWhenExceptionIsThrown
public async Task AssignSiteAdminInvokesLogErrorWhenExceptionIsThrown()
{
var mediator = new Mock<IMediator>();
var logger = new Mock<ILogger<SiteController>>();
var user = new ApplicationUser()
{
Id = "1234"
};
mediator.Setup(x => x.Send(It.Is<UserByUserIdQuery>(q => q.UserId == user.Id)))
.Throws<Exception>();
var controller = new SiteController(null, logger.Object, mediator.Object);
var result = await controller.AssignSiteAdmin(user.Id);
logger.Verify(l => l.Log<object>(LogLevel.Error, 0,
It.IsAny<Microsoft.Extensions.Logging.Internal.FormattedLogValues>(), null,
It.IsAny<Func<object, Exception, string>>()));
}
示例5: 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);
}
示例6: AssignSiteAdminInvokesAddClaimAsyncWithCorrrectParameters
public async Task AssignSiteAdminInvokesAddClaimAsyncWithCorrrectParameters()
{
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);
var controller = new SiteController(userManager.Object, null, mediator.Object);
await controller.AssignSiteAdmin(user.Id);
userManager.Verify(x => x.AddClaimAsync(user, It.Is<Claim>(c =>
c.Value == UserType.SiteAdmin.ToName() &&
c.Type == AllReady.Security.ClaimTypes.UserType)), Times.Once);
}