private DeleteCampaignImage ( int campaignId ) : Task |
||
campaignId | int | |
return | Task |
public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfNothingToDeleteIfThereWasNoExistingImage() { var mediatorMock = new Mock<IMediator>(); var campaignSummaryViewModel = new CampaignSummaryViewModel { OrganizationId = 1 }; mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var result = await sut.DeleteCampaignImage(It.IsAny<int>()); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("NothingToDelete"); }
public async Task DeleteCampaignImageCallsEditCampaignCommandWithCorrectData() { var mediatorMock = new Mock<IMediator>(); var campaignSummaryViewModel = new CampaignSummaryViewModel { OrganizationId = 1, ImageUrl = "URL!" }; mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); await sut.DeleteCampaignImage(It.IsAny<int>()); mediatorMock.Verify(m => m.SendAsync(It.Is<EditCampaignCommand>(s => s.Campaign == campaignSummaryViewModel)), Times.Once); }
public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfDateInvalidIfCampaignEndDateIsLessThanStartDate() { var mediatorMock = new Mock<IMediator>(); var campaignSummaryViewModel = new CampaignSummaryViewModel { OrganizationId = 1, StartDate = DateTimeOffset.Now.AddDays(10), EndDate = DateTimeOffset.Now }; mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); var result = await sut.DeleteCampaignImage(It.IsAny<int>()); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("DateInvalid"); result.Value.GetType() .GetProperty("message") .GetValue(result.Value) .ShouldBe("The end date must fall on or after the start date."); }
public async Task DeleteCampaignSendsTheCorrectIdToCampaignSummaryQuery() { var mediatorMock = new Mock<IMediator>(); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); const int campaignId = 2; await sut.DeleteCampaignImage(campaignId); mediatorMock.Verify(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>()), Times.Once); mediatorMock.Verify(m => m.SendAsync(It.Is<CampaignSummaryQuery>(s => s.CampaignId == campaignId))); }
public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfUnauthorizedIfUserIsNotOrganizationAdmin() { var mediatorMock = new Mock<IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryViewModel()); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserNotAnOrgAdmin(); var result = await sut.DeleteCampaignImage(It.IsAny<int>()); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("Unauthorized"); }
public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfNotFound() { var mediatorMock = new Mock<IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(null); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); var result = await sut.DeleteCampaignImage(It.IsAny<int>()); result.ShouldNotBeNull(); result.ShouldBeOfType<JsonResult>(); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("NotFound"); }