public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfNothingToDeleteIfThereWasNoExistingImage() { var campaignSummaryViewModel = new CampaignSummaryViewModel { OrganizationId = 1 }; var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); mediatorMock.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, true, false, false)); 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 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); mediatorMock.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, true, false, false)); 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 DeleteCampaignImageReturnsJsonObjectWithStatusOfSuccessIfImageDeletedSuccessfully() { 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()); var result = await sut.DeleteCampaignImage(It.IsAny <int>()); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("Success"); }
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 DeleteCampaignImageReturnsJsonObjectWithStatusOfUnauthorizedIfUserIsNotAuthorized() { var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryViewModel()); mediatorMock.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, false, false, false)); var imageServiceMock = new Mock <IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); 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((CampaignSummaryViewModel)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"); }
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 DeleteCampaignImageCallsDeleteImageAsyncWithCorrectData() { var campaignSummaryViewModel = new CampaignSummaryViewModel { OrganizationId = 1, ImageUrl = "URL!" }; var mediatorMock = new Mock <IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny <CampaignSummaryQuery>())).ReturnsAsync(campaignSummaryViewModel); mediatorMock.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, true, false, false)); var imageServiceMock = new Mock <IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserAnOrgAdmin(campaignSummaryViewModel.OrganizationId.ToString()); await sut.DeleteCampaignImage(It.IsAny <int>()); imageServiceMock.Verify(i => i.DeleteImageAsync(It.Is <string>(f => f == "URL!")), Times.Once); }