public async Task WhenBodyCalledWithPageNumberGreaterThanTheNumberOfPages__Then_ReturnLastPage() { var pageSettings = Options.Create(new PageSettings() { PageSize = 1 }); var controller = new MatchesController(_compositeSettings, _sessionService, pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>() { { "page", "10" } }); _sessionService.GetUserSession() .ReturnsForAnyArgs(MockHelpers.GetUserSession(true, true, true)); var result = await controller.Body() as ViewResult; result.Should().NotBeNull(); result.Should().BeOfType <ViewResult>(); result.ViewData.Model.As <MatchesCompositeViewModel>().CurrentPage.Should().Be(1); }
public async Task WhenTotalResultsIsGreaterThanPageAndModuleOfResultByPagesISLessThan5_Then_CorrectTotalPagesNumberReturned() { var userSession = MockHelpers.GetUserSession(true, true, true); var x = 1; var occs = new GetOccupationsWithMatchingSkillsResponse { MatchingOccupations = new List <GetOccupationsWithMatchingSkillsResponse.MatchedOccupation>() }; while (x < 10) { occs.MatchingOccupations.Add(new GetOccupationsWithMatchingSkillsResponse.MatchedOccupation() { JobProfileTitle = $"Mock Title{x}", JobProfileUri = "http://mockjoburl", LastModified = DateTime.UtcNow, TotalOccupationEssentialSkills = 12, MatchingEssentialSkills = 6, TotalOccupationOptionalSkills = 4, MatchingOptionalSkills = 2, Uri = "MatchUri", } ); x++; } var handlerMock = MockHelpers.GetMockMessageHandler(JsonConvert.SerializeObject(occs)); var restClient = new RestClient(handlerMock.Object); _serviceTaxonomy = new ServiceTaxonomyRepository(restClient); var pageSettings = Options.Create(new PageSettings() { PageSize = 5 }); var controller = new MatchesController(_compositeSettings, _sessionService, pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>() { { "page", "1" } }); _sessionService.GetUserSession() .ReturnsForAnyArgs(userSession); var result = await controller.Body() as ViewResult; result.Should().NotBeNull(); result.Should().BeOfType <ViewResult>(); result.ViewData.Model.As <MatchesCompositeViewModel>().CurrentPage.Should().Be(1); result.ViewData.Model.As <MatchesCompositeViewModel>().TotalPages.Should().Be(2); }
public async Task WhenBodyCalledWithOutPage_ReturnCurrentPageAs1() { var controller = new MatchesController(_compositeSettings, _sessionService, _pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>() { }); _sessionService.GetUserSession().ReturnsForAnyArgs(MockHelpers.GetUserSession(true, true, true)); var result = await controller.Body() as ViewResult; result.Should().NotBeNull(); result.Should().BeOfType <ViewResult>(); result.ViewData.Model.As <MatchesCompositeViewModel>().CurrentPage.Should().Be(1); }
public async Task When_ChangingOrderType_Then_UpdateTheChoiceInSession() { var controller = new MatchesController(_compositeSettings, _sessionService, _pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>() { { "page", "0" }, { "sortBy", "Alphabetically" }, { "direction", "ascending" } }); _sessionService.GetUserSession().ReturnsForAnyArgs(MockHelpers.GetUserSession(true, true, true)); var result = await controller.Body() as ViewResult; await _sessionService.Received().UpdateUserSessionAsync(Arg.Is <UserSession>(x => x.MatchesSortBy == SortBy.Alphabetically && x.MatchesSortDirection == SortDirection.Ascending)); }
public async Task WhenOrdering_Then_ReturnResultsInCorrectOrder(string sortBy, string direction, string expected) { var userSession = MockHelpers.GetUserSession(true, false, true); var match1 = "Mock Title1"; var match2 = "Mock Title2"; var occs = new GetOccupationsWithMatchingSkillsResponse { MatchingOccupations = new List <GetOccupationsWithMatchingSkillsResponse.MatchedOccupation>() }; occs.MatchingOccupations.Add(new GetOccupationsWithMatchingSkillsResponse.MatchedOccupation { JobProfileTitle = match1, JobProfileUri = "http://mockjoburl", LastModified = DateTime.UtcNow, TotalOccupationEssentialSkills = 12, MatchingEssentialSkills = 8, TotalOccupationOptionalSkills = 4, MatchingOptionalSkills = 2, Uri = "MatchUri", } ); occs.MatchingOccupations.Add(new GetOccupationsWithMatchingSkillsResponse.MatchedOccupation { JobProfileTitle = match2, JobProfileUri = "http://mockjoburl", LastModified = DateTime.UtcNow, TotalOccupationEssentialSkills = 12, MatchingEssentialSkills = 6, TotalOccupationOptionalSkills = 4, MatchingOptionalSkills = 2, Uri = "MatchUri", } ); var handlerMock = MockHelpers.GetMockMessageHandler(JsonConvert.SerializeObject(occs)); var restClient = new RestClient(handlerMock.Object); _serviceTaxonomy = new ServiceTaxonomyRepository(restClient); var pageSettings = Options.Create(new PageSettings() { PageSize = 10 }); var controller = new MatchesController(_compositeSettings, _sessionService, pageSettings, _dysacSettigs, _serviceTaxSettings, _serviceTaxonomy); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; controller.HttpContext.Request.Query = new QueryCollection(new Dictionary <string, StringValues>() { { "page", "1" }, { "sortBy", sortBy }, { "direction", direction } }); _sessionService.GetUserSession() .ReturnsForAnyArgs(userSession); var result = await controller.Body() as ViewResult; result.Should().NotBeNull(); result.Should().BeOfType <ViewResult>(); result.ViewData.Model.As <MatchesCompositeViewModel>().CareerMatches.First().JobProfile.Title.Should() .Be(expected); }