public async Task RemoveTeamMemberRedirectsToCorrectActionWithCorrectRouteValues_WhenOrganizationIdIsNotZero_AndUserIsOrgAdmin()
        {
            const int itineraryId = 1;
            var viewModel = new TaskSignupSummaryViewModel { ItineraryId = itineraryId, UserIsOrgAdmin = true };
            var routeValueDictionary = new RouteValueDictionary { ["id"] = viewModel.ItineraryId };

            var mediator = new Mock<IMediator>();

            var sut = new ItineraryController(mediator.Object, null);
            var result = await sut.RemoveTeamMember(viewModel) as RedirectToActionResult;

            Assert.Equal(result.ActionName, nameof(ItineraryController.Details));
            Assert.Equal(result.RouteValues, routeValueDictionary);
        }
        public async Task RemoveTeamMemberReturnsHttpUnauthorizedWhenUserIsNotOrgAdmin()
        {
            var viewModel = new TaskSignupSummaryViewModel { UserIsOrgAdmin = false };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(1);

            var sut = new ItineraryController(mockMediator.Object, null);

            Assert.IsType<UnauthorizedResult>(await sut.RemoveTeamMember(viewModel));
        }
        public async Task RemoveTeamMemberSendsRemoveTeamMemberCommandWithCorrectTaskSignupId_WhenOrganizationIsNotZero_AndUserIsOrgAdmin()
        {
            const int taskSignupId = 1;

            var viewModel = new TaskSignupSummaryViewModel { TaskSignupId = taskSignupId, UserIsOrgAdmin = true };

            var mockMediator = new Mock<IMediator>();

            var sut = new ItineraryController(mockMediator.Object, null);

            await sut.RemoveTeamMember(viewModel);

            mockMediator.Verify(x => x.SendAsync(It.Is<RemoveTeamMemberCommand>(y => y.TaskSignupId == taskSignupId)), Times.Once);
        }
Exemplo n.º 4
0
        public async Task<IActionResult> RemoveTeamMember(TaskSignupSummaryViewModel viewModel)
        {
            if (!viewModel.UserIsOrgAdmin)
            {
                return Unauthorized();
            }

            await _mediator.SendAsync(new RemoveTeamMemberCommand { TaskSignupId = viewModel.TaskSignupId });

            return RedirectToAction(nameof(Details), new { id = viewModel.ItineraryId });
        }