public async Task PublishConfirmedReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin() { var sut = new CampaignController(Mock.Of <IMediator>(), null); Assert.IsType <UnauthorizedResult>(await sut.PublishConfirmed(new PublishViewModel { UserIsOrgAdmin = false })); }
public async Task PublishConfirmedReturnsForbiddResultWhenUserIsNotAuthorized() { var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, false, false, false)); var sut = new CampaignController(mediator.Object, null); Assert.IsType <ForbidResult>(await sut.PublishConfirmed(new PublishViewModel { UserIsOrgAdmin = false })); }
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); }
public async Task PublishConfirmedSendsPublishCampaignCommandWithCorrectCampaignId() { var viewModel = new PublishViewModel { Id = 1 }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, true, false, false, 1)); 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); }
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 PublishConfirmedRedirectsToCorrectActionWithCorrectRouteValuesWhenUserIsAuthorized() { var viewModel = new PublishViewModel { Id = 100, UserIsOrgAdmin = true }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <AuthorizableCampaignQuery>())).ReturnsAsync(new FakeAuthorizableCampaign(false, true, false, false)); var sut = new CampaignController(mediator.Object, null); var routeValues = new Dictionary <string, object> { ["area"] = "Admin" }; var result = await sut.PublishConfirmed(viewModel) as RedirectToActionResult; Assert.Equal(nameof(CampaignController.Index), result.ActionName); Assert.Equal(result.RouteValues, routeValues); }
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); }