public async Task SendEventManagerInviteShouldCreateInvite_WhenUserIsOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var @event = new Event { Campaign = new Campaign() { ManagingOrganizationId = 1 } }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(@event); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.MakeUserAnOrgAdmin(organizationId: "1"); var invite = new InviteViewModel { EventId = 1, InviteeEmailAddress = "*****@*****.**", CustomMessage = "test message" }; // Act IActionResult result = await sut.SendEventManagerInvite(invite.EventId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.Is <CreateEventManagerInviteCommand>(c => c.Invite == invite)), Times.Once); }
public async Task SendEventManagerInvitePostReturnsUnauthorizedResult_WhenUserIsNotOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var @event = new Event { Campaign = new Campaign() { ManagingOrganizationId = 1 } }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(@event); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.MakeUserAnOrgAdmin(organizationId: "2"); var invite = new InviteViewModel(); // Act IActionResult result = await sut.SendEventManagerInvite(eventId, invite); // Assert Assert.IsType <UnauthorizedResult>(result); }
public async Task SendEventManagerInviteShouldNotCreateInvite_WhenUserIsNotOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var @event = new Event { Campaign = new Campaign() { ManagingOrganizationId = 1 } }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(@event); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.MakeUserAnOrgAdmin(organizationId: "2"); var invite = new InviteViewModel(); // Act IActionResult result = await sut.SendEventManagerInvite(eventId, invite); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task SendEventManagerInviteReturnsPassesCorrectViewModelToView() { // Arrange var mockMediator = new Mock <IMediator>(); var @event = new Event(); @event.Campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(@event); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.MakeUserAnOrgAdmin(organizationId: "1"); // Act IActionResult result = await sut.SendEventManagerInvite(eventId); // Assert ViewResult view = result as ViewResult; var model = Assert.IsType <InviteViewModel>(view.ViewData.Model); Assert.Equal(eventId, model.EventId); Assert.Equal("Send Event Manager Invite", model.Title); Assert.Equal("SendEventManagerInvite", model.FormAction); }
public async Task SendEventManagerInviteReturnsSendView_WhenUserIsOrgAdminForCampaign() { // Arrange var mockMediator = new Mock <IMediator>(); var @event = new Event(); @event.Campaign = new Campaign() { ManagingOrganizationId = 1 }; mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(@event); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.MakeUserAnOrgAdmin(organizationId: "1"); // Act IActionResult result = await sut.SendEventManagerInvite(eventId); // Assert Assert.IsType <ViewResult>(result); ViewResult view = result as ViewResult; Assert.Equal(view.ViewName, "Send"); }
public async Task SendEventManagerInviteShouldNotCreateInvite_WhenViewModelIsNull() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); // Act IActionResult result = await sut.SendEventManagerInvite(eventId, null); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task SendEventManagerInviteReturnsBadRequestResult_WhenViewModelIsNull() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); // Act IActionResult result = await sut.SendEventManagerInvite(eventId, null); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task SendEventManagerInviteSendsEventByEventIdQueryWithCorrectEventId() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); // Act await sut.SendEventManagerInvite(eventId); // Assert mockMediator.Verify(mock => mock.SendAsync(It.Is <EventByEventIdQuery>(e => e.EventId == eventId))); }
public async Task SendEventManagerInviteShouldNotCreateInvite_WhenModelStateIsNotValid() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.ModelState.AddModelError("Error", "Message"); // Act var result = await sut.SendEventManagerInvite(eventId, new InviteViewModel()); // Assert mockMediator.Verify(x => x.SendAsync(It.IsAny <CreateCampaignManagerInviteCommand>()), Times.Never); }
public async Task SendEventManagerInviteReturnsBadRequestResult_WhenNoCampaignMatchesId() { // Arrange var mockMediator = new Mock <IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(null); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); var invite = new InviteViewModel(); // Act var result = await sut.SendEventManagerInvite(eventId, invite); // Assert Assert.IsType <BadRequestResult>(result); }
public async Task SendEventManagerInviteReturnsNotFoundResult_WhenNoEventMatchesId() { // Arrange var mockMediator = new Mock <IMediator>(); mockMediator.Setup(mock => mock.SendAsync(It.IsAny <EventByEventIdQuery>())).ReturnsAsync(null); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); // Act IActionResult result = await sut.SendEventManagerInvite(eventId); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task SendEventManagerInviteReturnsSendView_WhenModelStateIsNotValid() { // Arrange var mockMediator = new Mock <IMediator>(); var sut = new InviteController(mockMediator.Object, new FakeUserManager()); sut.ModelState.AddModelError("Error", "Message"); // Act var result = await sut.SendEventManagerInvite(eventId, new InviteViewModel()); // Assert var view = Assert.IsType <ViewResult>(result); Assert.Equal("Send", view.ViewName); }