public async Task MarkCompleteSendsRequestStatusChangeCommandWithCorrectRequestIdWhenOrganizationIsNotZero_AndUserIsOrgAdmin() { var requestId = Guid.NewGuid(); const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.MarkComplete(It.IsAny<int>(), requestId); mockMediator.Verify(x => x.SendAsync(It.Is<ChangeRequestStatusCommand>(y => y.RequestId == requestId)), Times.Once); }
public async Task ConfirmRemoveTeamMemberReturnsHttpNotFound_WhenTaskSignupSummaryModelIsNull() { const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mockMediator.Setup(x => x.SendAsync(It.IsAny<TaskSignupSummaryQuery>())).ReturnsAsync(null); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); Assert.IsType<NotFoundResult>(await sut.ConfirmRemoveTeamMember(It.IsAny<int>(), It.IsAny<int>())); }
public async Task ConfirmRemoveTeamMemberReturnsTheCorrectViewAndViewModel() { const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mockMediator.Setup(x => x.SendAsync(It.IsAny<TaskSignupSummaryQuery>())).ReturnsAsync(new TaskSignupSummaryViewModel { TaskSignupId = It.IsAny<int>(), VolunteerEmail = "*****@*****.**", VolunteerName = "Test McTesterson" }); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.ConfirmRemoveTeamMember(It.IsAny<int>(), It.IsAny<int>()) as ViewResult; Assert.Equal(result.ViewName, "ConfirmRemoveTeamMember"); var resultViewModel = result.ViewData.Model; Assert.IsType<TaskSignupSummaryViewModel>(resultViewModel); }
public async Task AddRequestsSendsAddRequestsCommandWhenThereAreSelectedRequests() { const int orgId = 1; var itineraryId = It.IsAny<int>(); var selectedRequests = new List<string> { "request1", "request2" }; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddRequestsToItineraryCommand>())).ReturnsAsync(true); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.AddRequests(itineraryId, selectedRequests); mockMediator.Verify(x => x.SendAsync(It.Is<AddRequestsToItineraryCommand>(y => y.RequestIdsToAdd.Equals(selectedRequests))), Times.Once); }
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 CreateReturnsOkResultWhenUserIsOrgAdmin() { const int orgId = 1; //var sut = GetItineraryControllerWithEventSummaryQuery(UserType.OrgAdmin.ToString(), 1); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(new EventSummaryViewModel { OrganizationId = orgId }); mediator.Setup(x => x.SendAsync(It.IsAny<EditItineraryCommand>())).ReturnsAsync(orgId); var sut = new ItineraryController(mediator.Object, MockSuccessValidation().Object); sut.MakeUserAnOrgAdmin(orgId.ToString()); Assert.IsType<OkObjectResult>(await sut.Create(new ItineraryEditViewModel())); }
public async Task AddTeamMemberRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndIdOrSelectedTeamMemberIsNotZero() { const int itineraryId = 1; const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.AddTeamMember(itineraryId, 1) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(ItineraryController.Details)); Assert.Equal(result.RouteValues, new Dictionary<string, object> { ["id"] = itineraryId }); }
public async Task ConfirmRemoveRequestReturnsNotFoundResult_WhenViewModelIsNull() { const int orgId = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.ConfirmRemoveRequest(It.IsAny<int>(), It.IsAny<Guid>()); Assert.IsType<NotFoundResult>(result); }
public async Task ConfirmRemoveRequestSendsRequestSummaryQueryWithCorrectRequestId() { const int orgId = 1; var requestId = Guid.NewGuid(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.ConfirmRemoveRequest(It.IsAny<int>(), requestId); mediator.Verify(x => x.SendAsync(It.Is<RequestSummaryQuery>(y => y.RequestId == requestId))); }
public async Task RemoveTeamMemberRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin() { const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.RemoveTeamMember(It.IsAny<int>(), It.IsAny<int>()); //TODO: this assertion does not assert what the title of this unit test says it does. Please fix to assert that the redirect action and route values are correct //mockMediator.Verify(x => x.SendAsync(It.Is<RemoveTeamMemberCommand>(y => y.TaskSignupId == taskSignupId)), Times.Once); }
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 AddRequestsSendsAddRequestsCommandWhenThereAreSelectedRequests() { const int orgId = 1; var itineraryId = It.IsAny<int>(); var selectedRequests = new[]{ "request1", "request2" }; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.AddRequests(itineraryId, selectedRequests); //TODO: need a way to verify that the RequestIdsToAdd List<string> is the same as the string array selectedRequests. Only problem is that .ToList() is called on selectedRequests in the AddRequests action method, creating a new List<string> //mockMediator.Verify(x => x.SendAsync(It.Is<AddRequestsCommand>(y => y.RequestIdsToAdd == selectedRequests.ToList())), Times.Once); }
public async Task AddTeamMemberReturnsCorrectJsonWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndIdOrSelectedTeamMemberIsNotZero() { const int itineraryId = 1; const int orgId = 1; const int teamMemberId = 1; string volunteerEmail = "*****@*****.**"; var mockMediator = new Mock<IMediator>(); var itineraryDetailsViewModel = new ItineraryDetailsViewModel { PotentialTeamMembers = new List<SelectListItem>(), TeamMembers = new List<TeamListViewModel> { new TeamListViewModel {VolunteerEmail = volunteerEmail} } }; mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mockMediator.Setup(x => x.SendAsync(It.IsAny<ItineraryDetailQuery>())).ReturnsAsync(itineraryDetailsViewModel); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var jsonResult = await sut.AddTeamMember(itineraryId, teamMemberId) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var teamMembers = jsonResult.GetValueForProperty<IEnumerable<TeamListViewModel>>("teamMembers").ToList(); var potentialMembers = jsonResult.GetValueForProperty<IEnumerable<SelectListItem>>("potentialTeamMembers").ToList(); Assert.True(successStatus); Assert.NotNull(teamMembers); Assert.NotNull(potentialMembers); Assert.Equal(1, teamMembers.Count); Assert.Equal(volunteerEmail, teamMembers[0].VolunteerEmail); }
public async Task AddTeamMemberReturnsCorrectJsonWhenIdIsZeroOrSelectedTeamMemberIsZero() { const int itineraryId = 0; const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<AddTeamMemberCommand>())).ReturnsAsync(true); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var jsonResult = await sut.AddTeamMember(itineraryId, 0) as JsonResult; var successStatus = jsonResult.GetValueForProperty<bool>("isSuccess"); var errors = jsonResult.GetValueForProperty<string[]>("errors"); Assert.False(successStatus); Assert.NotNull(errors); Assert.Equal(1, errors.Length); Assert.Equal("Invalid selection.", errors[0]); }
public async Task MarkCompleteReturnsRedirectToActionWhenOrganizationIsNotZero_AndUserIsOrgAdmin() { const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.MarkComplete(It.IsAny<int>(), It.IsAny<Guid>()); Assert.IsType<RedirectToActionResult>(result); }
public async Task ConfirmRemoveRequestAssignsCorrectTitleOnViewModel() { const int orgId = 1; var requestId = Guid.NewGuid(); var viewModel = new RequestSummaryViewModel { Name = "ViewModelName" }; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mediator.Setup(x => x.SendAsync(It.IsAny<RequestSummaryQuery>())).ReturnsAsync(viewModel); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.ConfirmRemoveRequest(It.IsAny<int>(), requestId) as ViewResult; var resultViewModel = result.ViewData.Model as RequestSummaryViewModel; Assert.Equal(resultViewModel.Title, $"Remove request: {viewModel.Name}"); }
public async Task MarkCompleteReturnsRedirectToAction_WithActionName_Details() { const int orgId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.MarkComplete(It.IsAny<int>(), It.IsAny<Guid>()); var actionResult = (RedirectToActionResult)result; Assert.Equal("Details", actionResult.ActionName); }
public async Task ConfirmRemoveRequestSetsUserIsOrgAdminToTrue_WhenUserIsOrgAdmin() { const int orgId = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mediator.Setup(x => x.SendAsync(It.IsAny<RequestSummaryQuery>())).ReturnsAsync(new RequestSummaryViewModel()); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.ConfirmRemoveRequest(It.IsAny<int>(), It.IsAny<Guid>()) as ViewResult; var resultViewModel = result.ViewData.Model as RequestSummaryViewModel; Assert.True(resultViewModel.UserIsOrgAdmin); }
public async Task CreateReturnsHttpBadRequestResultWhenModelStateHasError() { const int orgId = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<EventSummaryQuery>())).ReturnsAsync(new EventSummaryViewModel { OrganizationId = orgId }); var sut = new ItineraryController(mediator.Object, MockSuccessValidation().Object); sut.MakeUserAnOrgAdmin(orgId.ToString()); sut.AddModelStateError(); var result = await sut.Create(new ItineraryEditViewModel()); Assert.IsType<BadRequestObjectResult>(result); }
public async Task ConfirmRemoveRequestRetrunsCorrectViewAndViewModel() { const int orgId = 1; var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); mediator.Setup(x => x.SendAsync(It.IsAny<RequestSummaryQuery>())).ReturnsAsync(new RequestSummaryViewModel()); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.ConfirmRemoveRequest(It.IsAny<int>(), It.IsAny<Guid>()) as ViewResult; var resultViewModel = result.ViewData.Model as RequestSummaryViewModel; Assert.Equal(result.ViewName, "ConfirmRemoveRequest"); Assert.IsType<RequestSummaryViewModel>(resultViewModel); }
public async Task SelectRequestsPostWithSingleParameterSetsSelectItineraryRequestsModelWithTheCorrectData() { const int organizationId = 4; var itinerary = GetItineraryForSelectRequestHappyPathTests(); var returnedRequests = GetRequestsForSelectRequestHappyPathTests(); var mediator = new Mock<IMediator>(); mediator.Setup(x => x.SendAsync(It.Is<ItineraryDetailQuery>(y => y.ItineraryId == itinerary.Id))).ReturnsAsync(itinerary); mediator.Setup(x => x.SendAsync(It.IsAny<RequestListItemsQuery>())).ReturnsAsync(returnedRequests); mediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(organizationId); var sut = new ItineraryController(mediator.Object, null); sut.MakeUserAnOrgAdmin(organizationId.ToString()); var view = await sut.SelectRequests(itinerary.Id, new SelectItineraryRequestsViewModel()); RunSelectRequestsHappyPathTests(view, itinerary, returnedRequests); }
public async Task ConfirmRemoveTeamMemberSendsTaskSignupSummaryQueryWithCorrectTaskSignupIdWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin() { const int orgId = 1; const int taskSignupId = 1; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); await sut.ConfirmRemoveTeamMember(It.IsAny<int>(), taskSignupId); mockMediator.Verify(x => x.SendAsync(It.Is<TaskSignupSummaryQuery>(y => y.TaskSignupId == taskSignupId)), Times.Once); }
public async Task AddRequestsRedirectsToCorrectActionWithCorrectRouteValuesWhenOrganizationIdIsNotZero_AndUserIsOrgAdmin_AndThereAreSelectedRequests() { const int orgId = 1; var itineraryId = It.IsAny<int>(); var selectedRequests = new List<string> { "request1", "request2" }; var mockMediator = new Mock<IMediator>(); mockMediator.Setup(x => x.SendAsync(It.IsAny<OrganizationIdQuery>())).ReturnsAsync(orgId); var sut = new ItineraryController(mockMediator.Object, null); sut.MakeUserAnOrgAdmin(orgId.ToString()); var result = await sut.AddRequests(itineraryId, selectedRequests) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(ItineraryController.Details)); Assert.Equal(result.RouteValues, new Dictionary<string, object> { ["id"] = itineraryId }); }
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); }