public async Task DetailConfirmedRedirectsToCorrectActionWithCorrectRouteValuesWhenUserIsOrgAdmin()
        {
            const int organizationId = 1;

            var viewModel = new DeleteViewModel { Id = 100, UserIsOrgAdmin = true };

            var sut = new CampaignController(Mock.Of<IMediator>(), null);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());

            var routeValues = new Dictionary<string, object> { ["area"] = "Admin" };

            var result = await sut.DeleteConfirmed(viewModel) as RedirectToActionResult;
            Assert.Equal(result.ActionName, nameof(CampaignController.Index));
            Assert.Equal(result.RouteValues, routeValues);
        }
        public async Task DetailConfirmedSendsDeleteCampaignCommandWithCorrectCampaignIdWhenUserIsOrgAdmin()
        {
            const int organizationId = 1;

            var mockMediator = new Mock<IMediator>();

            var viewModel = new DeleteViewModel { Id = 100, UserIsOrgAdmin = true };

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

            await sut.DeleteConfirmed(viewModel);

            mockMediator.Verify(mock => mock.SendAsync(It.Is<DeleteCampaignCommand>(i => i.CampaignId == viewModel.Id)), Times.Once);
        }
Ejemplo n.º 3
0
        public async Task<IActionResult> DeleteConfirmed(DeleteViewModel viewModel)
        {
            if (!viewModel.UserIsOrgAdmin)
            {
                return Unauthorized();
            }

            await _mediator.SendAsync(new DeleteCampaignCommand { CampaignId = viewModel.Id });

            return RedirectToAction(nameof(Index), new { area = "Admin" });
        }
        public async Task DeleteConfirmedSendsDeleteCampaignCommandWithCorrectCampaignId()
        {
            var viewModel = new DeleteViewModel { Id = 1 };

            var mediator = new Mock<IMediator>();
            var sut = new CampaignController(mediator.Object, null);
            await sut.DeleteConfirmed(viewModel);

            mediator.Verify(mock => mock.SendAsync(It.Is<DeleteCampaignCommand>(i => i.CampaignId == viewModel.Id)), Times.Once);
        }
        public async Task DeleteConfirmedSendsDeleteCampaignCommandWithCorrectCampaignId()
        {
            var viewModel = new DeleteViewModel {Id = 1 , OrganizationId = 1};

            var mediator = new Mock<IMediator>();
            mediator.Setup(a => a.SendAsync(It.IsAny<DeleteCampaignCommand>())).Verifiable();
            var sut = new CampaignController(mediator.Object, null);
            sut.MakeUserAnOrgAdmin(viewModel.OrganizationId.ToString());
            await sut.DeleteConfirmed(viewModel);

            mediator.Verify(mock => mock.SendAsync(It.Is<DeleteCampaignCommand>(i => i.CampaignId == viewModel.Id)), Times.Once);
        }