Exemplo n.º 1
0
        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 void When_GetOccupationsWithMatchingSkillsResponseCreated_Then_SkillsListShouldBeInitialised()
        {
            // Arrange


            // Act
            var x = new GetOccupationsWithMatchingSkillsResponse();

            // Assert
            x.MatchingOccupations.Should().NotBeNull();
            x.MatchingOccupations.Should().HaveCount(0);
        }
        public async Task When_SkillMatchInitialised_Then_SkillResultShouldBePopulated(string url, string apiKey)
        {
            // ARRANGE
            var stresponse = new GetOccupationsWithMatchingSkillsResponse();

            stresponse.MatchingOccupations.Add(
                new GetOccupationsWithMatchingSkillsResponse.MatchedOccupation()
            {
                JobProfileTitle                = "Baggage Handler",
                JobProfileUri                  = "http://jobprofile",
                LastModified                   = DateTime.UtcNow,
                MatchingEssentialSkills        = 5,
                MatchingOptionalSkills         = 3,
                TotalOccupationEssentialSkills = 10,
                TotalOccupationOptionalSkills  = 4,
            });
            string matchedOccupationJson = JsonConvert.SerializeObject(stresponse);
            var    handlerMock           = GetMockMessageHandler(matchedOccupationJson);
            var    restClient            = new RestClient(handlerMock.Object);
            var    subjectUnderTest      = new ServiceTaxonomyRepository(restClient);
            var    skillIds = new string[]
            {
                "skill1",
                "skill2",
                "skill3"
            };
            var minimumMatchingSkills = 1;

            // ACTs
            var result = await subjectUnderTest.FindOccupationsForSkills(url, apiKey, skillIds, minimumMatchingSkills);

            // ASSERT
            result.Should().NotBeNull();
            result.Should().HaveCount(1);
            result[0].JobProfileTitle.Should().Be("Baggage Handler");

            /*
             * handlerMock.Protected().Verify(
             *  "SendAsync",
             *  Times.Once(), // we expected a single external request
             *  ItExpr.Is<HttpRequestMessage>(req =>
             *          req.Method == HttpMethod.Get // we expected a GET request
             *  ),
             *  ItExpr.IsAny<CancellationToken>()
             * );
             */
        }
Exemplo n.º 4
0
        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);
        }