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


C# CampaignController.Edit方法代码示例

本文整理汇总了C#中AllReady.Areas.Admin.Controllers.CampaignController.Edit方法的典型用法代码示例。如果您正苦于以下问题:C# CampaignController.Edit方法的具体用法?C# CampaignController.Edit怎么用?C# CampaignController.Edit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AllReady.Areas.Admin.Controllers.CampaignController的用法示例。


在下文中一共展示了CampaignController.Edit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EditPostReturnsCorrectViewModelWhenInvalidImageFormatIsSupplied

        public async Task EditPostReturnsCorrectViewModelWhenInvalidImageFormatIsSupplied()
        {
            const int organizationId = 100;
            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var file = FormFile("audio/mpeg3");
            var model = MassiveTrafficLightOutage_model;
            model.OrganizationId = organizationId;

            var view = (ViewResult)(await sut.Edit(model, file));
            var viewModel = (CampaignSummaryViewModel)view.ViewData.Model;
            Assert.True(Object.ReferenceEquals(model, viewModel));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:17,代码来源:CampaignAdminControllerTests.cs

示例2: EditPostUploadsImageToImageService

        public async Task EditPostUploadsImageToImageService()
        {
            const int organizationId = 1;
            const int campaignId = 100;

            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var file = FormFile("image/jpeg");

            await sut.Edit(new CampaignSummaryViewModel { Name = "Foo", OrganizationId = organizationId, Id = campaignId}, file);

            mockImageService.Verify(mock => mock.UploadCampaignImageAsync(
                        It.Is<int>(i => i == organizationId),
                        It.Is<int>(i => i == campaignId),
                It.Is<IFormFile>(i => i == file)), Times.Once);
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:20,代码来源:CampaignAdminControllerTests.cs

示例3: EditPostAddsCorrectKeyAndErrorMessageToModelStateWhenCampaignEndDateIsLessThanCampainStartDate

        public async Task EditPostAddsCorrectKeyAndErrorMessageToModelStateWhenCampaignEndDateIsLessThanCampainStartDate()
        {
            var campaignSummaryModel = new CampaignSummaryViewModel { OrganizationId = 1, StartDate = DateTime.Now.AddDays(1), EndDate = DateTime.Now.AddDays(-1)};

            var sut = new CampaignController(null, null);
            sut.MakeUserAnOrgAdmin(campaignSummaryModel.OrganizationId.ToString());

            await sut.Edit(campaignSummaryModel, null);
            var modelStateErrorCollection = sut.ModelState.GetErrorMessagesByKey(nameof(CampaignSummaryViewModel.EndDate));

            Assert.Equal(modelStateErrorCollection.Single().ErrorMessage, "The end date must fall on or after the start date.");
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:12,代码来源:CampaignAdminControllerTests.cs

示例4: EditPostInsertsCampaign

        public async Task EditPostInsertsCampaign()
        {
            var OrganizationId = 99;
            var NewCampaignId = 100;
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EditCampaignCommand>()))
                .Returns((EditCampaignCommand q) => Task.FromResult<int>(NewCampaignId) );

            var mockImageService = new Mock<IImageService>();
            var controller = new CampaignController(mockMediator.Object, mockImageService.Object);
            controller.MakeUserAnOrgAdmin(OrganizationId.ToString());

            var model = MassiveTrafficLightOutage_model;
            model.OrganizationId = OrganizationId;

            // verify the model is valid
            var validationContext = new ValidationContext(model, null, null);
            var validationResults = new List<ValidationResult>();
            Validator.TryValidateObject(model, validationContext, validationResults);
            Assert.Equal(0, validationResults.Count());

            var file = FormFile("image/jpeg");
            var view = (RedirectToActionResult) await controller.Edit(model, file);

            // verify the edit(add) is called
            mockMediator.Verify(mock => mock.SendAsync(It.Is<EditCampaignCommand>(c => c.Campaign.OrganizationId == OrganizationId)));

            // verify that the next route
            Assert.Equal(view.RouteValues["area"], "Admin");
            Assert.Equal(view.RouteValues["id"], NewCampaignId);

        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:32,代码来源:CampaignAdminControllerTests.cs

示例5: EditPostDoesNotInvokeDeleteImageAsync__WhenCampaignDoesNotHaveAnImage

        public async Task EditPostDoesNotInvokeDeleteImageAsync__WhenCampaignDoesNotHaveAnImage()
        {
            const int organizationId = 1;
            const int campaignId = 100;

            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var file = FormFile("image/jpeg");
            mockImageService.Setup(x => x.UploadCampaignImageAsync(It.IsAny<int>(), It.IsAny<int>(), file)).ReturnsAsync("newImageUrl");

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var campaignSummaryViewModel = new CampaignSummaryViewModel
            {
                OrganizationId = organizationId,
                Id = campaignId,
                StartDate = new DateTimeOffset(new DateTime(2016, 2, 13)),
                EndDate = new DateTimeOffset(new DateTime(2016, 2, 14)),
            };

            await sut.Edit(campaignSummaryViewModel, file);
            mockImageService.Verify(mock => mock.DeleteImageAsync(It.IsAny<string>()), Times.Never);
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:25,代码来源:CampaignAdminControllerTests.cs

示例6: EditGetSendsCampaignSummaryQueryWithCorrectCampaignId

        public async Task EditGetSendsCampaignSummaryQueryWithCorrectCampaignId()
        {
            var CAMPAIGN_ID = 100;
            var mockMediator = new Mock<IMediator>();

            // model is not null
            mockMediator.Setup(mock => mock.SendAsync(It.Is<CampaignSummaryQuery>(c => c.CampaignId == CAMPAIGN_ID))).ReturnsAsync(new CampaignSummaryViewModel { Id = CAMPAIGN_ID });

            var controller = new CampaignController(mockMediator.Object, null);
            controller.SetClaims(new List<Claim>()); // create a User for the controller
            var view = await controller.Edit(CAMPAIGN_ID);
            mockMediator.Verify(mock => mock.SendAsync(It.Is<CampaignSummaryQuery>(c => c.CampaignId == CAMPAIGN_ID)));
        }
开发者ID:mheggeseth,项目名称:allReady,代码行数:13,代码来源:CampaignAdminControllerTests.cs

示例7: EditPostRedirectsToCorrectActionWithCorrectRouteValuesWhenModelStateIsValid

        public async Task EditPostRedirectsToCorrectActionWithCorrectRouteValuesWhenModelStateIsValid()
        {
            const int organizationId = 99;
            const int campaignId = 100;

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EditCampaignCommand>())).ReturnsAsync(campaignId);
            var sut = new CampaignController(mockMediator.Object, new Mock<IImageService>().Object);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var result = (RedirectToActionResult) await sut.Edit(new CampaignSummaryViewModel { Name = "Foo", OrganizationId = organizationId, Id = campaignId }, null);

            Assert.Equal(result.ActionName, "Details");
            Assert.Equal(result.RouteValues["area"], "Admin");
            Assert.Equal(result.RouteValues["id"], campaignId);
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:16,代码来源:CampaignAdminControllerTests.cs

示例8: CampaignController

        public async Task EditPostInvokesUploadCampaignImageAsyncWithTheCorrectParameters_WhenFileUploadIsNotNull_AndFileIsAcceptableContentType()
        {
            const int organizationId = 1;
            const int campaignId = 100;

            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var file = FormFile("image/jpeg");

            await sut.Edit(new CampaignSummaryViewModel { Name = "Foo", OrganizationId = organizationId, Id = campaignId}, file);

            mockImageService.Verify(mock => mock.UploadCampaignImageAsync(
                It.Is<int>(i => i == organizationId),
                It.Is<int>(i => i == campaignId),
                It.Is<IFormFile>(i => i == file)), Times.Once);
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:20,代码来源:CampaignAdminControllerTests.cs

示例9: EditGetSendsCampaignSummaryQueryWithCorrectCampaignId

        public async Task EditGetSendsCampaignSummaryQueryWithCorrectCampaignId()
        {
            const int campaignId = 100;
            var mockMediator = new Mock<IMediator>();

            var sut = new CampaignController(mockMediator.Object, null);
            await sut.Edit(campaignId);

            mockMediator.Verify(mock => mock.SendAsync(It.Is<CampaignSummaryQuery>(c => c.CampaignId == campaignId)));
        }
开发者ID:nicolastarzia,项目名称:allReady,代码行数:10,代码来源:CampaignAdminControllerTests.cs

示例10: CampaignEditPostUploadsImageToImageService

        public async void CampaignEditPostUploadsImageToImageService()
        {
            const int tenantId = 1;
            const int campaignId = 100;
            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();
            mockImageService
                .Setup(mock => mock.UploadCampaignImageAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<IFormFile>()))
                .Returns(() => Task.FromResult(""))
                .Verifiable();
            var mockDataAccess = new Mock<IAllReadyDataAccess>();
            var controller = new CampaignController(
                mockMediator.Object,
                mockImageService.Object,
                mockDataAccess.Object);

            var mockHttpContext = new Mock<HttpContext>();
            mockHttpContext.Setup(mock => mock.User)
                .Returns(() => GetClaimsPrincipal(UserType.TenantAdmin.ToString(), tenantId));
            var mockContext = new Mock<ActionContext>();
            mockContext.Object.HttpContext = mockHttpContext.Object;
            controller.ActionContext = mockContext.Object;

            var file = FormFile("image/jpeg");

            await controller.Edit(new CampaignSummaryModel
            {
                Name = "Foo",
                TenantId = tenantId,
                Id = campaignId
            }, file);
            mockImageService.Verify(mock => 
                mock.UploadCampaignImageAsync(
                        It.Is<int>(i => i == tenantId), 
                        It.Is<int>(i => i == campaignId), 
                        It.Is<IFormFile>(i => i == file)), 
                Times.Once);
        }
开发者ID:fr33k3r,项目名称:allReady,代码行数:38,代码来源:CampaignControllerTests.cs

示例11: EditPostUploadsImageToImageService

        public async Task EditPostUploadsImageToImageService()
        {
            const int organizationId = 1;
            const int campaignId = 100;

            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.SetClaims(new List<Claim>
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
                new Claim(AllReady.Security.ClaimTypes.Organization, organizationId.ToString())
            });

            var file = FormFile("image/jpeg");

            await sut.Edit(new CampaignSummaryModel { Name = "Foo", OrganizationId = organizationId, Id = campaignId}, file);

            mockImageService.Verify(mock => mock.UploadCampaignImageAsync(
                        It.Is<int>(i => i == organizationId),
                        It.Is<int>(i => i == campaignId),
                It.Is<IFormFile>(i => i == file)), Times.Once);
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:24,代码来源:CampaignAdminControllerTests.cs

示例12: EditPostReturnsCorrectViewModelWhenInvalidImageFormatIsSupplied

        public async Task EditPostReturnsCorrectViewModelWhenInvalidImageFormatIsSupplied()
        {
            int ORGANIZATION_ID = 100;
            var mockMediator = new Mock<IMediator>();
            var mockImageService = new Mock<IImageService>();

            var sut = new CampaignController(mockMediator.Object, mockImageService.Object);
            sut.SetClaims(new List<Claim>
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
                new Claim(AllReady.Security.ClaimTypes.Organization, ORGANIZATION_ID.ToString())
            });

            var file = FormFile("audio/mpeg3");
            CampaignSummaryModel model = MassiveTrafficLightOutage_model;
            model.OrganizationId = ORGANIZATION_ID;

            ViewResult view = (ViewResult)(await sut.Edit(model, file));
            CampaignSummaryModel viewModel = (CampaignSummaryModel)view.ViewData.Model;
            Assert.True(Object.ReferenceEquals(model, viewModel));
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:21,代码来源:CampaignAdminControllerTests.cs

示例13: EditPostAddsCorrectKeyAndErrorMessageToModelStateWhenCampaignEndDateIsLessThanCampainStartDate

        public async Task EditPostAddsCorrectKeyAndErrorMessageToModelStateWhenCampaignEndDateIsLessThanCampainStartDate()
        {
            var campaignSummaryModel = new CampaignSummaryModel { OrganizationId = 1, StartDate = DateTime.Now.AddDays(1), EndDate = DateTime.Now.AddDays(-1)};

            var sut = new CampaignController(null, null);
            sut.SetClaims(new List<Claim>
            {
                new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()),
                new Claim(AllReady.Security.ClaimTypes.Organization, campaignSummaryModel.OrganizationId.ToString())
            });

            await sut.Edit(campaignSummaryModel, null);
            var modelStateErrorCollection = sut.ModelState.GetErrorMessagesByKey(nameof(CampaignSummaryModel.EndDate));

            Assert.Equal(modelStateErrorCollection.Single().ErrorMessage, "The end date must fall on or after the start date.");
        }
开发者ID:yobenzima,项目名称:allReady,代码行数:16,代码来源:CampaignAdminControllerTests.cs


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