示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }