public async Task DetailConfirmedRedirectsToCorrectActionWithCorrectRouteValuesWhenUserIsOrgAdmin() { const int organizationId = 1; const int campaignId = 100; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryViewModel { OrganizationId = organizationId }); var sut = new CampaignController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(organizationId.ToString()); var routeValues = new Dictionary<string, object> { ["area"] = "Admin" }; var result = await sut.DeleteConfirmed(campaignId) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(CampaignController.Index)); Assert.Equal(result.RouteValues, routeValues); }
public async Task DeleteConfirmedSendsCampaignSummaryQueryWithCorrectCampaignId() { const int campaignId = 1; var mediator = new Mock<IMediator>(); var sut = new CampaignController(mediator.Object, null); await sut.DeleteConfirmed(campaignId); mediator.Verify(mock => mock.SendAsync(It.Is<CampaignSummaryQuery>(i => i.CampaignId == campaignId)), Times.Once); }
public async Task DetailConfirmedSendsDeleteCampaignCommandWithCorrectCampaignIdWhenUserIsOrgAdmin() { const int organizationId = 1; const int campaignId = 100; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryViewModel { OrganizationId = organizationId }); var sut = new CampaignController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(organizationId.ToString()); await sut.DeleteConfirmed(campaignId); mockMediator.Verify(mock => mock.SendAsync(It.Is<DeleteCampaignCommand>(i => i.CampaignId == campaignId)), Times.Once); }
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); }
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 DetailConfirmedReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin() { var sut = new CampaignController(Mock.Of<IMediator>(), null); Assert.IsType<UnauthorizedResult>(await sut.DeleteConfirmed(new DeleteViewModel { UserIsOrgAdmin = false })); }
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 void CampaignDetailConfirmedMockChecksForAdminUser() { const int tenantId = 1; const int campaignId = 100; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(mock => mock.Send(It.IsAny<CampaignSummaryQuery>())) .Returns(() => new CampaignSummaryModel { TenantId = tenantId }) .Verifiable(); mockMediator.Setup(mock => mock.Send(It.IsAny<DeleteCampaignCommand>())) .Verifiable(); var mockImageService = new Mock<IImageService>(); var mockDataAccess = new Mock<IAllReadyDataAccess>(); var controller = new CampaignController( mockMediator.Object, mockImageService.Object, mockDataAccess.Object); var mockHttpContext = new Mock<HttpContext>(); mockHttpContext.Setup(mock => mock.User) .Returns(() => GetClaimsPrincipal(UserType.TenantAdmin.ToString(), tenantId)); var mockContext = new Mock<ActionContext>(); mockContext.Object.HttpContext = mockHttpContext.Object; controller.ActionContext = mockContext.Object; var result = controller.DeleteConfirmed(campaignId); Assert.IsType<RedirectToActionResult>(result); mockMediator.Verify(mock => mock.Send(It.Is<CampaignSummaryQuery>(i => i.CampaignId == campaignId)), Times.Once); mockMediator.Verify(mock => mock.Send(It.Is<DeleteCampaignCommand>(i => i.CampaignId == campaignId)), Times.Once); }
public async Task DetailConfirmedSendsDeleteCampaignCommandWithCorrectCampaignIdWhenUserIsOrgAdmin() { const int organizationId = 1; const int campaignId = 100; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryModel { OrganizationId = organizationId }); var sut = new CampaignController(mockMediator.Object, null); sut.SetClaims(new List<Claim> { new Claim(AllReady.Security.ClaimTypes.UserType, UserType.OrgAdmin.ToString()), new Claim(AllReady.Security.ClaimTypes.Organization, organizationId.ToString()) }); await sut.DeleteConfirmed(campaignId); mockMediator.Verify(mock => mock.SendAsync(It.Is<DeleteCampaignCommand>(i => i.CampaignId == campaignId)), 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); }