public async Task<IActionResult> PublishConfirmed(PublishViewModel viewModel) { if (!viewModel.UserIsOrgAdmin) { return Unauthorized(); } await _mediator.SendAsync(new PublishCampaignCommand { CampaignId = viewModel.Id }); return RedirectToAction(nameof(Index), new { area = "Admin" }); }
public async Task PublishConfirmedSendsPublishCampaignCommandWithCorrectCampaignIdWhenUserIsOrgAdmin() { const int organizationId = 1; var mockMediator = new Mock<IMediator>(); var viewModel = new PublishViewModel { Id = 100, UserIsOrgAdmin = true }; var sut = new CampaignController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(organizationId.ToString()); await sut.PublishConfirmed(viewModel); mockMediator.Verify(mock => mock.SendAsync(It.Is<PublishCampaignCommand>(i => i.CampaignId == viewModel.Id)), Times.Once); }
public async Task PublishConfirmedRedirectsToCorrectActionWithCorrectRouteValuesWhenUserIsOrgAdmin() { const int organizationId = 1; var viewModel = new PublishViewModel { 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.PublishConfirmed(viewModel) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(CampaignController.Index)); Assert.Equal(result.RouteValues, routeValues); }
public async Task PublishConfirmedSendsPublishCampaignCommandWithCorrectCampaignId() { var viewModel = new PublishViewModel { Id = 1 }; var mediator = new Mock<IMediator>(); var sut = new CampaignController(mediator.Object, null); await sut.PublishConfirmed(viewModel); mediator.Verify(mock => mock.SendAsync(It.Is<PublishCampaignCommand>(i => i.CampaignId == viewModel.Id)), Times.Once); }