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 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_WhenViewModelIsNull() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); // Act IActionResult result = await sut.Send(campaignId, null); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task SendSendsCampaignByCampaignIdQueryWithCorrectCampaignId() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); // Act await sut.Send(campaignId); // Assert mockMediator.Verify(mock => mock.SendAsync(It.Is <CampaignManagerInviteQuery>(c => c.CampaignId == campaignId))); }
public async Task SendReturnsBadRequestResult_WhenViewModelIsNull() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); // Act IActionResult result = await sut.Send(campaignId, null); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task SendShouldNotCreateInvite_WhenModelStateIsNotValid() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.ModelState.AddModelError("Error", "Message"); // Act var result = await sut.Send(campaignId, new CampaignManagerInviteViewModel()); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task SendReturnsNotFoundResult_WhenNoCampaignMatchesId() { // Arrange var mockMediator = new Mock <IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteQuery>())).ReturnsAsync(null); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); // Act IActionResult result = await sut.Send(campaignId); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task SendReturnsSendView_WhenModelStateIsNotValid() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.ModelState.AddModelError("Error", "Message"); // Act var result = await sut.Send(campaignId, new CampaignManagerInviteViewModel()); // Assert var view = Assert.IsType <ViewResult>(result); Assert.Equal("Send", view.ViewName); }
public async Task SendReturnsUnauthorizedResult_WhenUserIsNotOrgAdmin() { // Arrange var mockMediator = new Mock <IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignManagerInviteQuery>())).ReturnsAsync(new CampaignManagerInviteViewModel() { CampaignId = campaignId }); var sut = new CampaignManagerInviteController(mockMediator.Object, UserManagerMockHelper.CreateUserManagerMock().Object); sut.MakeUserNotAnOrgAdmin(); // Act IActionResult result = await sut.Send(campaignId); // Assert Assert.IsType <UnauthorizedResult>(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 SendPostReturnsUnauthorizedResult_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 Assert.IsType <UnauthorizedResult>(result); }
public async Task SendPassesCorrectViewModelToView() { // 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: "1"); // Act IActionResult result = await sut.Send(campaignId); // Assert ViewResult view = result as ViewResult; var model = Assert.IsType <CampaignManagerInviteViewModel>(view.ViewData.Model); Assert.Equal(campaignId, model.CampaignId); }
public async Task SendReturnsSendView_WhenUserIsOrgAdminForCampaign() { // 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: "1"); // Act IActionResult result = await sut.Send(campaignId); // Assert Assert.IsType <ViewResult>(result); ViewResult view = result as ViewResult; Assert.Equal(view.ViewName, "Send"); }