本文整理汇总了C#中AllReady.Areas.Admin.Controllers.CampaignController.Index方法的典型用法代码示例。如果您正苦于以下问题:C# CampaignController.Index方法的具体用法?C# CampaignController.Index怎么用?C# CampaignController.Index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Areas.Admin.Controllers.CampaignController
的用法示例。
在下文中一共展示了CampaignController.Index方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexReturnsCorrectDataWhenUserIsOrgAdmin
private static void IndexReturnsCorrectDataWhenUserIsOrgAdmin()
{
const int organizationId = 99;
var mockMediator = new Mock<IMediator>();
mockMediator.Setup(x => x.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == organizationId)))
.Returns((CampaignListQuery q) =>
{
var ret = new List<CampaignSummaryViewModel>
{
new CampaignSummaryViewModel { OrganizationId = organizationId }
};
return ret;
}
);
var controller = new CampaignController(mockMediator.Object, null);
controller.MakeUserAnOrgAdmin(organizationId.ToString());
var view = (ViewResult)controller.Index();
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == organizationId)));
// Org admin should only see own campaigns
var viewModel = (IEnumerable<CampaignSummaryViewModel>)view.ViewData.Model;
Assert.NotNull(viewModel);
Assert.Equal(viewModel.Count(), 1);
Assert.Equal(viewModel.First().OrganizationId, organizationId);
}
示例2: IndexReturnsCorrectDataWhenUserIsOrgAdmin
public void IndexReturnsCorrectDataWhenUserIsOrgAdmin()
{
int OrganizationId = 99;
var mockMediator = new Mock<IMediator>();
mockMediator.Setup(x => x.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == OrganizationId)))
.Returns((CampaignListQuery q) => {
List<CampaignSummaryModel> ret = new List<CampaignSummaryModel>();
ret.Add(new CampaignSummaryModel { OrganizationId = OrganizationId });
return ret;
}
);
CampaignController controller = new CampaignController(mockMediator.Object, null);
List<Claim> claims = new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, OrganizationId.ToString())
};
controller.SetClaims(claims);
ViewResult view = (ViewResult)controller.Index();
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == OrganizationId)));
// Org admin should only see own campaigns
IEnumerable<CampaignSummaryModel> viewModel = (IEnumerable<CampaignSummaryModel>)view.ViewData.Model;
Assert.NotNull(viewModel);
Assert.Equal(viewModel.Count(), 1);
Assert.Equal(viewModel.First().OrganizationId, OrganizationId);
}
示例3: IndexSendsIndexQueryWithCorrectData_WhenUserIsNotOrgAdmin
public async Task IndexSendsIndexQueryWithCorrectData_WhenUserIsNotOrgAdmin()
{
var mockMediator = new Mock<IMediator>();
var sut = new CampaignController(mockMediator.Object, null);
sut.MakeUserNotAnOrgAdmin();
await sut.Index();
mockMediator.Verify(mock => mock.SendAsync(It.Is<IndexQuery>(q => q.OrganizationId == null)));
}
示例4: IndexSendsCampaignListQueryWithCorrectDataWhenUserIsOrgAdmin
public void IndexSendsCampaignListQueryWithCorrectDataWhenUserIsOrgAdmin()
{
const int organizationId = 99;
var mockMediator = new Mock<IMediator>();
var controller = new CampaignController(mockMediator.Object, null);
controller.MakeUserAnOrgAdmin(organizationId.ToString());
controller.Index();
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(q => q.OrganizationId == organizationId)));
}
示例5: IndexSendsCampaignListQueryWithCorrectDataWhenUserIsNotOrgAdmin
public void IndexSendsCampaignListQueryWithCorrectDataWhenUserIsNotOrgAdmin()
{
var mockMediator = new Mock<IMediator>();
var controller = new CampaignController(mockMediator.Object, null);
var claims = new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
};
controller.SetClaims(claims);
controller.Index();
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(q => q.OrganizationId == null)));
}
示例6: IndexSendsCampaignListQueryWithCorrectDataWhenUserIsOrgAdmin
public void IndexSendsCampaignListQueryWithCorrectDataWhenUserIsOrgAdmin()
{
int OrganizationId = 99;
var mockMediator = new Mock<IMediator>();
var mockImageService = new Mock<IImageService>();
CampaignController controller = new CampaignController(mockMediator.Object, mockImageService.Object);
List<Claim> claims = new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
new Claim(AllReady.Security.ClaimTypes.Organization, OrganizationId.ToString())
};
controller.SetClaims(claims);
controller.Index();
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(q => q.OrganizationId == OrganizationId)));
}
示例7: IndexReturnsCorrectDataWhenUserIsNotOrgAdmin
private void IndexReturnsCorrectDataWhenUserIsNotOrgAdmin()
{
const int organizationId = 99;
var mockMediator = new Mock<IMediator>();
mockMediator.Setup(x => x.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == null)))
.Returns((CampaignListQuery q) =>
{
// return some models
var ret = new List<CampaignSummaryViewModel>
{
new CampaignSummaryViewModel { OrganizationId = organizationId },
new CampaignSummaryViewModel { OrganizationId = organizationId + 1 }
};
return ret;
}
);
var controller = new CampaignController(mockMediator.Object, null);
var claims = new List<Claim>
{
new Claim(AllReady.Security.ClaimTypes.UserType, UserType.SiteAdmin.ToString()),
};
controller.SetClaims(claims);
// All campaigns returned when not OrgAdmin
var view = (ViewResult)controller.Index();
// verify the fetch was called
mockMediator.Verify(mock => mock.Send(It.Is<CampaignListQuery>(c => c.OrganizationId == null)));
// Site admin should only see all campaigns
var viewModel = (IEnumerable<CampaignSummaryViewModel>)view.ViewData.Model;
Assert.NotNull(viewModel);
Assert.Equal(viewModel.Count(), 2);
}