public async Task EditGet_ReturnsViewResult_WhenRequestIsFoundAndUserIsOrgAdmin()
        {
            const int orgId = 1;

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EditRequestQuery>())).ReturnsAsync(new EditRequestViewModel { OrganizationId = orgId, Name = "test" });

            var sut = new RequestController(mockMediator.Object);
            sut.MakeUserAnOrgAdmin(orgId.ToString());

            var result = await sut.Edit(Guid.NewGuid());

            var objResult = Assert.IsType<ViewResult>(result);
            objResult.ViewName.ShouldBe("Edit");
            objResult.ViewData["Title"].ShouldBe("Edit test");
        }
        public async Task EditPost_ReturnsRedirectToAction_WhenEventIsNotNullAndUserIsOrgAdmin()
        {
            const int eventId = 1;
            const int orgId = 1;
            var viewModel = new EventSummaryViewModel { Id = eventId, OrganizationId = orgId };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);

            mockMediator.Setup(x => x.SendAsync(It.IsAny<EditRequestCommand>())).ReturnsAsync(Guid.NewGuid());

            var sut = new RequestController(mockMediator.Object);
            sut.MakeUserAnOrgAdmin(orgId.ToString());

            var result = await sut.Edit(new EditRequestViewModel { EventId = eventId });

            var objResult = Assert.IsType<RedirectToActionResult>(result);
            objResult.ActionName.ShouldBe("Requests");
            objResult.ControllerName.ShouldBe("Event");
        }
        public async Task EditPost_ReturnsViewResult_WhenModelStateIsNotValid()
        {
            const int eventId = 1;
            const int orgId = 1;
            var viewModel = new EventSummaryViewModel { Id = eventId, OrganizationId = orgId };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);

            var sut = new RequestController(mockMediator.Object);
            sut.MakeUserAnOrgAdmin(orgId.ToString());
            sut.ModelState.AddModelError("test", "test error");

            var result = await sut.Edit(new EditRequestViewModel { EventId = eventId });

            var objResult = Assert.IsType<ViewResult>(result);
            objResult.ViewName.ShouldBe("Edit");
        }
        public async Task EditPost_SendsEditRequestCommand_WhenEventIsNotNullAndUserIsOrgAdmin()
        {
            const int eventId = 1;
            const int orgId = 1;
            var viewModel = new EventSummaryViewModel { Id = eventId, OrganizationId = orgId };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);

            EditRequestCommand editRequestCommand = null; // will be assigned from the Moq callback
            mockMediator.Setup(x => x.SendAsync(It.IsAny<EditRequestCommand>())).ReturnsAsync(Guid.NewGuid()).Callback<EditRequestCommand>(cmd => editRequestCommand = cmd).Verifiable();

            var sut = new RequestController(mockMediator.Object);
            sut.MakeUserAnOrgAdmin(orgId.ToString());

            await sut.Edit(new EditRequestViewModel { EventId = eventId });

            mockMediator.Verify(x => x.SendAsync(It.IsAny<EditRequestCommand>()), Times.Once);

            editRequestCommand.RequestModel.EventId.ShouldBe(eventId);
        }
        public async Task Create_ReturnsCorrectViewAndViewModel_WhenEventIsNotNullAndUserIsOrgAdmin()
        {
            const int eventId = 1;
            const int orgId = 1;
            var viewModel = new EventSummaryViewModel { Id = eventId, OrganizationId = orgId };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(viewModel);

            var sut = new RequestController(mockMediator.Object);
            sut.MakeUserAnOrgAdmin(orgId.ToString());

            var result = await sut.Create(It.IsAny<int>());

            var objResult = Assert.IsType<ViewResult>(result);

            objResult.ViewName.ShouldBe("Edit");

            var resultViewModel = Assert.IsType<EditRequestViewModel>(objResult.ViewData.Model);
            resultViewModel.EventId.ShouldBe(viewModel.Id);
            resultViewModel.OrganizationId.ShouldBe(viewModel.OrganizationId);

            var viewBagTitle = objResult.ViewData["Title"];
            viewBagTitle.ShouldNotBeNull();
            viewBagTitle.ShouldBe(RequestController.CreateRequestTitle);
        }