Exemple #1
0
        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");
        }
Exemple #2
0
        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.");
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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)));
        }
Exemple #5
0
        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");
        }
Exemple #6
0
        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");
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }