public async Task DetailsReturnsHttpNotFoundResultWhenEventIsNull()
        {
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(null).Verifiable();

            var controller = new ItineraryController(mockMediator.Object, null);
            Assert.IsType<NotFoundResult>(await controller.Details(It.IsAny<int>()));
        }
        public async Task DetailsSendsEventDetailQueryWithCorrectEventId()
        {
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(null).Verifiable();

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

            mockMediator.Verify(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>()), Times.Once);
        }
        public async Task DetailsReturnsHttpUnauthorizedResultWhenUserIsNotOrgAdmin()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(new ItineraryDetailsViewModel());

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

            Assert.IsType<UnauthorizedResult>(await sut.Details(It.IsAny<int>()));
        }
        public async Task DetailsReturnsCorrectViewAndViewModelWhenEventIsNotNullAndUserIsOrgAdmin()
        {
            const int orgId = 1;
            var viewModel = new ItineraryDetailsViewModel { OrganizationId = orgId };

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(viewModel);

            var sut = new ItineraryController(mediator.Object, null);
            sut.MakeUserAnOrgAdmin(orgId.ToString());

            var result = await sut.Details(It.IsAny<int>()) as ViewResult;
            Assert.Equal(result.ViewName, "Details");

            var resultViewModel = result.ViewData.Model;
            Assert.IsType<ItineraryDetailsViewModel>(resultViewModel);

            Assert.Equal(resultViewModel, viewModel);
        }
        public async Task DetailsPost_ReturnsViewModelWithCorrectRequestListData()
        {
            const int orgId = 1;
            var fullList = new List<RequestListViewModel> {new RequestListViewModel {Id = Guid.NewGuid()}};
            var filteredList = new List<RequestListViewModel> {new RequestListViewModel {Id = Guid.NewGuid()}};
            var viewModel = new ItineraryDetailsViewModel { OrganizationId = orgId, Requests = fullList};

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(viewModel);
            mediator.Setup(x => x.SendAsync(It.IsAny<RequestListItemsQuery>())).ReturnsAsync(filteredList);

            var sut = new ItineraryController(mediator.Object, null);
            sut.MakeUserAnOrgAdmin(orgId.ToString());
            var result = await sut.Details(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<RequestStatus?>()) as ViewResult;

            var model = (ItineraryDetailsViewModel) result.ViewData.Model;

            Assert.Equal(model.Requests, filteredList);
        }
        public async Task DetailsPost_SendsRequestListQueryWithCorrectData()
        {
            const int orgId = 1;
            const int itineraryId = 2;
            const string keywords = "search";
            const RequestStatus status = RequestStatus.Assigned;
            var viewModel = new ItineraryDetailsViewModel { OrganizationId = orgId, Id = 2 };
            var requestList = new List<RequestListViewModel>();

            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(viewModel);
            mediator.Setup(x => x.SendAsync(It.IsAny<RequestListItemsQuery>())).ReturnsAsync(requestList);

            var sut = new ItineraryController(mediator.Object, null);
            sut.MakeUserAnOrgAdmin(orgId.ToString());
            await sut.Details(itineraryId, keywords, status);

            mediator.Verify(x => x.SendAsync(It.Is<RequestListItemsQuery>(
                y => y.Criteria.ItineraryId == itineraryId &&
                     y.Criteria.Keywords == keywords &&
                     y.Criteria.Status == status)), Times.Once);
        }