public async Task SendShouldCreateInvite_WhenUserIsOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignByCampaignIdQuery>())).ReturnsAsync(campaign); var userManager = UserManagerMockHelper.CreateUserManagerMock(); userManager.Setup(x => x.GetUserAsync(It.IsAny <ClaimsPrincipal>())).ReturnsAsync(new ApplicationUser()); var sut = new CampaignManagerInviteController(mockMediator.Object, userManager.Object); sut.MakeUserAnOrgAdmin(organizationId: "1"); var invite = new CampaignManagerInviteViewModel { CampaignId = 1, InviteeEmailAddress = "*****@*****.**", CustomMessage = "test message" }; // Act IActionResult result = await sut.Send(campaignId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.Is <CreateCampaignManagerInviteCommand>(c => c.Invite == invite)), Times.Once); }
public async Task SendShouldNotCreateInvite_WhenAnInviteAlreadyExistsForInviteeEmailAddress() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignByCampaignIdQuery>())).ReturnsAsync(campaign); mockMediator.Setup(mock => mock.SendAsync(It.IsAny <UserHasCampaignManagerInviteQuery>())).ReturnsAsync(true); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin(organizationId: "1"); var invite = new CampaignManagerInviteViewModel { CampaignId = 1, InviteeEmailAddress = "*****@*****.**", CustomMessage = "test message" }; // Act IActionResult result = await sut.Send(invite.CampaignId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.Is <CreateCampaignManagerInviteCommand>(c => c.Invite == invite)), Times.Never); }
public async Task CancelReturnsNotFoundResult_WhenInviteIsMissing() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin("1"); // Act var result = await sut.Cancel(5); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task SendReturnsUnauthorizedResult_WhenUserIsNotOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new CampaignManagerInviteViewModel() { CampaignId = campaignId, OrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteQuery>())).ReturnsAsync(campaign); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin(organizationId: "2"); // Act IActionResult result = await sut.Send(campaignId); // Assert Assert.IsType <UnauthorizedResult>(result); }
public async Task DetailsReturnsView_WhenUserIsOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var invite = new CampaignManagerInviteDetailsViewModel() { Id = inviteId, OrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteDetailQuery>())).ReturnsAsync(invite); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin(organizationId: "1"); // Act IActionResult result = await sut.Details(inviteId); // Assert Assert.IsType <ViewResult>(result); }
public async Task CancelReturnsRedirectResult_WhenInviteIsOk() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new CampaignManagerInviteDetailsViewModel() { CampaignId = campaignId, OrganizationId = 1, Id = 5 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteDetailQuery>())).ReturnsAsync(campaign); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin("1"); // Act var result = await sut.Cancel(5); // Assert Assert.IsType <RedirectToActionResult>(result); }
public async Task SendShouldNotCreateInvite_WhenUserIsAllreadyManagerForEvent() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignByCampaignIdQuery>())).ReturnsAsync(campaign); mockMediator.Setup(mock => mock.SendAsync(It.IsAny <UserHasCampaignManagerInviteQuery>())).ReturnsAsync(false); var mockUserManger = UserManagerMockHelper.CreateUserManagerMock(); mockUserManger.Setup(mock => mock.FindByEmailAsync(It.Is <string>(e => e == "*****@*****.**"))).ReturnsAsync(new ApplicationUser { ManagedCampaigns = new List <CampaignManager> { new CampaignManager() { CampaignId = 1 } }, }); var sut = new CampaignManagerInviteController(mockMediator.Object, mockUserManger.Object); sut.MakeUserAnOrgAdmin(organizationId: "1"); var invite = new CampaignManagerInviteViewModel { CampaignId = 1, InviteeEmailAddress = "*****@*****.**", CustomMessage = "test message" }; // Act IActionResult result = await sut.Send(invite.CampaignId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.Is <CreateCampaignManagerInviteCommand>(c => c.Invite == invite)), Times.Never); }
public async Task SendShouldNotCreateInvite_WhenUserIsNotOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignByCampaignIdQuery>())).ReturnsAsync(campaign); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin(organizationId: "2"); var invite = new CampaignManagerInviteViewModel(); // Act IActionResult result = await sut.Send(campaignId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task DetailsPassesCorrectViewModelToView() { // Arrange var mockMediator = new Mock <IMediator>(); var invite = new CampaignManagerInviteDetailsViewModel() { Id = inviteId, OrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteDetailQuery>())).ReturnsAsync(invite); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserAnOrgAdmin(organizationId: "1"); // Act IActionResult result = await sut.Details(inviteId); // Assert ViewResult view = result as ViewResult; var model = Assert.IsType <CampaignManagerInviteDetailsViewModel>(view.ViewData.Model); Assert.Equal(inviteId, model.Id); }