当前位置: 首页>>代码示例>>C#>>正文


C# CampaignController.Index方法代码示例

本文整理汇总了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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:27,代码来源:CampaignAdminControllerTests.cs

示例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);
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:29,代码来源:CampaignAdminControllerTests.cs

示例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)));
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:10,代码来源:CampaignAdminControllerTests.cs

示例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)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:11,代码来源:CampaignAdminControllerTests.cs

示例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)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:14,代码来源:CampaignAdminControllerTests.cs

示例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)));
        }
开发者ID:codethug,项目名称:allReady,代码行数:17,代码来源:CampaignAdminControllerTests.cs

示例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);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:35,代码来源:CampaignAdminControllerTests.cs


注:本文中的AllReady.Areas.Admin.Controllers.CampaignController.Index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。