public async Task IndexSendsIndexQueryWithCorrectData_WhenUserIsNotOrgAdmin() { var mockMediator = new Mock<IMediator>(); var sut = new CampaignController(mockMediator.Object, null); sut.MakeUserNotAnOrgAdmin(); await sut.Index(); mockMediator.Verify(mock => mock.SendAsync(It.Is<IndexQuery>(q => q.OrganizationId == null))); }
public async Task DeleteReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin() { var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<DeleteViewModelQuery>())).ReturnsAsync(new DeleteViewModel()); var sut = new CampaignController(mediator.Object, null); sut.MakeUserNotAnOrgAdmin(); Assert.IsType<UnauthorizedResult>(await sut.Delete(It.IsAny<int>())); }
public async Task DeleteCampaignImageReturnsJsonObjectWithStatusOfUnauthorizedIfUserIsNotOrganizationAdmin() { var mediatorMock = new Mock<IMediator>(); mediatorMock.Setup(m => m.SendAsync(It.IsAny<CampaignSummaryQuery>())).ReturnsAsync(new CampaignSummaryViewModel()); var imageServiceMock = new Mock<IImageService>(); var sut = new CampaignController(mediatorMock.Object, imageServiceMock.Object); sut.MakeUserNotAnOrgAdmin(); var result = await sut.DeleteCampaignImage(It.IsAny<int>()); result.Value.GetType() .GetProperty("status") .GetValue(result.Value) .ShouldBe("Unauthorized"); }