コード例 #1
0
 public SearchOccupationResults(IServiceTaxonomySearcher serviceTaxonomy, IOptions <ServiceTaxonomySettings> settings)
 {
     Throw.IfNull(serviceTaxonomy, nameof(serviceTaxonomy));
     Throw.IfNull(settings, nameof(settings));
     _serviceTaxonomy = serviceTaxonomy ?? new ServiceTaxonomyRepository();
     _settings        = settings.Value;
 }
コード例 #2
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 MatchDetailsController(IServiceTaxonomySearcher serviceTaxonomy,
                               IOptions <ServiceTaxonomySettings> settings, IOptions <CompositeSettings> compositeSettings,
                               ISessionService sessionService) : base(compositeSettings, sessionService)
 {
     Throw.IfNull(serviceTaxonomy, nameof(serviceTaxonomy));
     Throw.IfNull(settings, nameof(settings));
     _serviceTaxonomy = serviceTaxonomy ?? new ServiceTaxonomyRepository();
     _settings        = settings.Value;
 }
コード例 #4
0
        public void Init()
        {
            _sessionService    = Substitute.For <ISessionService>();
            _compositeSettings = Options.Create(new CompositeSettings());

            _serviceTaxonomy         = new ServiceTaxonomyRepository();
            _serviceTaxonomySettings = Options.Create(new ServiceTaxonomySettings());
            _controller = new MatchDetailsController(_serviceTaxonomy, _serviceTaxonomySettings, _compositeSettings, _sessionService);
            _controller.ControllerContext.HttpContext = new DefaultHttpContext();
        }
コード例 #5
0
 public MatchesController(IOptions <CompositeSettings> compositeSettings,
                          ISessionService sessionService, IOptions <PageSettings> pageSettings, IOptions <DysacSettings> dysacSettings, IOptions <ServiceTaxonomySettings> serviceTaxonomySettings, IServiceTaxonomySearcher serviceTaxonomy)
     : base(compositeSettings, sessionService)
 {
     _pageSize                = pageSettings.Value.PageSize;
     _compositeSettings       = compositeSettings;
     _serviceTaxonomy         = serviceTaxonomy;
     _serviceTaxonomySettings = serviceTaxonomySettings.Value;
     ViewModel.DysacSaveUrl   = dysacSettings.Value.DysacSaveUrl;
 }
        public SelectSkillsController(IServiceTaxonomySearcher serviceTaxonomy,
                                      IOptions <ServiceTaxonomySettings> settings, IOptions <CompositeSettings> compositeSettings,
                                      ISessionService sessionService) : base(compositeSettings, sessionService)
        {
            Throw.IfNull(serviceTaxonomy, nameof(serviceTaxonomy));
            Throw.IfNull(settings, nameof(settings));

            Throw.IfNull(settings.Value.ApiUrl, nameof(settings.Value.ApiUrl));
            Throw.IfNull(settings.Value.ApiKey, nameof(settings.Value.ApiKey));
            Throw.IfNull(sessionService, nameof(sessionService));

            _serviceTaxonomy = serviceTaxonomy ?? new ServiceTaxonomyRepository();
            _sessionService  = sessionService;
            _settings        = settings.Value;
        }
コード例 #7
0
        public RelatedSkillsController(IServiceTaxonomySearcher serviceTaxonomy,
                                       IOptions <ServiceTaxonomySettings> settings, IOptions <CompositeSettings> compositeSettings, ISessionService sessionService)
            : base(compositeSettings, sessionService)
        {
            Throw.IfNull(serviceTaxonomy, nameof(serviceTaxonomy));
            Throw.IfNull(settings, nameof(settings));

            Throw.IfNull(settings.Value.ApiUrl, nameof(settings.Value.ApiUrl));
            Throw.IfNull(settings.Value.ApiKey, nameof(settings.Value.ApiKey));

            _serviceTaxonomy = serviceTaxonomy ?? new ServiceTaxonomyRepository();
            _sessionService  = sessionService;
            _apiUrl          = settings.Value.ApiUrl;
            _apiKey          = settings.Value.ApiKey;
            ViewModel.CDN    = compositeSettings.Value.CDN ?? "";
        }
        public void Init()
        {
            _settings = Options.Create(new ServiceTaxonomySettings());
            _settings.Value.ApiUrl = "https://dev.api.nationalcareersservice.org.uk/servicetaxonomy";
            _settings.Value.ApiKey = "mykeydoesnotmatterasitwillbemocked";
            _settings.Value.SearchOccupationInAltLabels = "true";

            _sessionService    = Substitute.For <ISessionService>();
            _compositeSettings = Options.Create(new CompositeSettings());

            var handlerMock = MockHelpers.GetMockMessageHandler(_skillsJson);
            var restClient  = new RestClient(handlerMock.Object);

            _serviceTaxonomySearcher = new ServiceTaxonomyRepository(restClient);

            _sessionService.GetUserSession().ReturnsForAnyArgs(new UserSession());
        }
コード例 #9
0
        public void Init()
        {
            _sessionService     = Substitute.For <ISessionService>();
            _serviceTaxonomy    = Substitute.For <IServiceTaxonomySearcher>();
            _compositeSettings  = Options.Create(new CompositeSettings());
            _dysacSettigs       = Options.Create(new DysacSettings());
            _pageSettings       = Options.Create(new PageSettings());
            _serviceTaxSettings = Options.Create(new ServiceTaxonomySettings
            {
                ApiKey = "test",
                ApiUrl = "https://www.api.com"
            });

            var handlerMock = MockHelpers.GetMockMessageHandler(SkillsJson);
            var restClient  = new RestClient(handlerMock.Object);

            _serviceTaxonomy = new ServiceTaxonomyRepository(restClient);
        }
コード例 #10
0
        public async Task WhenBodyCalled_ReturnHtmlWithSkills()
        {
            var userSession = new UserSession
            {
                Occupations = new HashSet <UsOccupation>(1)
                {
                    new UsOccupation("id", "id")
                },
                Skills = new HashSet <UsSkill>(1)
                {
                    new UsSkill("id", "id")
                },
                OccupationMatches = new List <OccupationMatch>()
                {
                    new OccupationMatch()
                    {
                        Uri           = "id",
                        JobProfileUri = "id"
                    }
                }
            };

            _sessionService.GetUserSession().Returns(userSession);
            _serviceTaxonomy = Substitute.For <IServiceTaxonomySearcher>();
            _serviceTaxonomy.GetSkillsGapForOccupationAndGivenSkills <SkillsGap>(Arg.Any <string>(), Arg.Any <string>(),
                                                                                 Arg.Any <string>(), Arg.Any <string[]>()).Returns(new SkillsGap()
            {
                MatchingSkills = new [] { "test" }, MissingSkills = new[] { "test2" }, OptionalMatchingSkills = new [] { "test" }, OptionalMissingSkills = new[] { "test2" }
            });
            _controller = new MatchDetailsController(_serviceTaxonomy, _serviceTaxonomySettings, _compositeSettings, _sessionService);

            var result = await _controller.Body("id") as ViewResult;

            var model = result.Model as MatchDetailsCompositeViewModel;

            model.MatchingSkills.Count(x => x.Value == false && x.Key == "test2").Should().BeGreaterOrEqualTo(1);
            model.MatchingSkills.Count(x => x.Value && x.Key == "test").Should().BeGreaterOrEqualTo(1);
            model.OptionalMatchingSkills.Count(x => x.Value == false && x.Key == "test2").Should().BeGreaterOrEqualTo(1);
            model.OptionalMatchingSkills.Count(x => x.Value && x.Key == "test").Should().BeGreaterOrEqualTo(1);
            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();
            result.ViewName.Should().BeNull();
        }
コード例 #11
0
        public async Task WhenBodyCalled_ReturnHtml()
        {
            var userSession = new UserSession
            {
                Occupations = new HashSet <UsOccupation>(1)
                {
                    new UsOccupation("id", "id")
                },
                Skills = new HashSet <UsSkill>(1)
                {
                    new UsSkill("id", "id")
                },
                OccupationMatches = new List <OccupationMatch>()
                {
                    new OccupationMatch()
                    {
                        Uri           = "id",
                        JobProfileUri = "id"
                    }
                }
            };

            _sessionService.GetUserSession().Returns(userSession);
            _serviceTaxonomy = Substitute.For <IServiceTaxonomySearcher>();
            _serviceTaxonomy.GetSkillsGapForOccupationAndGivenSkills <SkillsGap>(Arg.Any <string>(), Arg.Any <string>(),
                                                                                 Arg.Any <string>(), Arg.Any <string[]>()).Returns(new SkillsGap()
            {
            });
            _controller = new MatchDetailsController(_serviceTaxonomy, _serviceTaxonomySettings, _compositeSettings, _sessionService);

            var result = await _controller.Body("id") as ViewResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <ViewResult>();
            result.ViewName.Should().BeNull();
        }
コード例 #12
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);
        }