public void Init() { _settings = Options.Create(new ServiceTaxonomySettings()); _compositeSettings = Options.Create(new CompositeSettings()); _settings.Value.ApiUrl = "https://dev.api.nationalcareersservice.org.uk/servicetaxonomy"; _settings.Value.ApiKey = "mykeydoesnotmatterasitwillbemocked"; _settings.Value.EscoUrl = "http://data.europa.eu/esco"; _settings.Value.SearchOccupationInAltLabels = "true"; const string skillsJson = "{\"occupations\": [{\"uri\": \"http://data.europa.eu/esco/occupation/114e1eff-215e-47df-8e10-45a5b72f8197\",\"occupation\": \"renewable energy consultant\",\"alternativeLabels\": [\"alt 1\"],\"lastModified\": \"03-12-2019 00:00:01\"}]}"; var handlerMock = MockHelpers.GetMockMessageHandler(skillsJson); var restClient = new RestClient(handlerMock.Object); _serviceTaxonomyRepository = new ServiceTaxonomyRepository(restClient); //Cosmos Settings _cosmosSettings = Options.Create(new CosmosSettings() { ApiUrl = "https://test-account-not-real.documents.azure.com:443/", ApiKey = "VGhpcyBpcyBteSB0ZXN0", DatabaseName = "DatabaseName", UserSessionsCollection = "UserSessions" }); _client = new Mock <CosmosClient>(); _cosmosService = Substitute.For <ICosmosService>(); //Session Settings _sessionService = Substitute.For <ISessionService>(); _sessionConfig = Options.Create(new SessionConfig() { Salt = "ThisIsASalt" }); }
public async Task When_GetAllSkillsForOccupation_Then_ShouldReturnSkillsList(string url, string apiKey) { // ARRANGE const string skillsJson = "{skills:[" + "{\"type\": \"competency\",\"relationshipType\": \"essential\",\"skill\": \"collect biological data\",\"alternativeLabels\": [\"biological data analysing\", \"analysing biological records\"],\"uri\": \"aaa\"}," + "{\"type\": \"competency\",\"relationshipType\": \"essential\",\"skill\": \"collect biological info\",\"alternativeLabels\": [\"biological data analysing\", \"analysing biological records\"],\"uri\": \"aaa\"}," + "{\"type\": \"competency\",\"relationshipType\": \"optional\",\"skill\": \"collect samples\",\"alternativeLabels\": [\"biological data collection\", \"analysing biological records\"],\"uri\": \"aaa\"}]}"; var handlerMock = MockHelpers.GetMockMessageHandler(skillsJson, HttpStatusCode.OK); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); var vm = new SelectSkillsCompositeViewModel(); // ACTs var result = await subjectUnderTest.GetAllSkillsForOccupation <Skill[]>(url, apiKey, "http://data.europa.eu/esco/occupation/114e1eff-215e-47df-8e10-45a5b72f8197"); vm.Skills = result.ToList(); // ASSERT result.Should().NotBeNull(); result.Length.Should().Be(3); handlerMock.Protected().Verify( "SendAsync", Times.Once(), // we expected a single external request ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post ), ItExpr.IsAny <CancellationToken>() ); }
public async Task When_MockServiceSearchSkills_Then_ShouldReturnFilteredSkillsList(string url, string apiKey) { // ARRANGE const string skillsJson = "{skills:[{\"skillType\": \"competency\",\"skill\": \"collect biological data\",\"alternativeLabels\": [\"biological data analysing\", \"analysing biological records\"],\"uri\": \"aaa\"},{\"skillType\": \"competency\",\"skill\": \"collect biological info\",\"alternativeLabels\": [\"biological data analysing\", \"analysing biological records\"],\"uri\": \"aaa\"},{\"skillType\": \"competency\",\"skill\": \"collect samples\",\"alternativeLabels\": [\"biological data collection\", \"analysing biological records\"],\"uri\": \"aaa\"}]}"; var handlerMock = GetMockMessageHandler(skillsJson, HttpStatusCode.OK); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); // ACTs var result = await subjectUnderTest.SearchSkills <Skill[]>(url, apiKey, "biological"); // ASSERT result.Should().NotBeNull(); result.Length.Should().Be(2); 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>() ); }
public async Task When_MockServiceGetOccupations_Then_ShouldReturnOccupationsObject(string url, string apiKey) { // ARRANGE const string skillsJson = "{\"occupations\": [{\"uri\": \"http://data.europa.eu/esco/occupation/114e1eff-215e-47df-8e10-45a5b72f8197\",\"occupation\": \"renewable energy consultant\",\"alternativeLabels\": [\"alt 1\"],\"lastModified\": \"03-12-2019 00:00:01\"}]}"; var handlerMock = GetMockMessageHandler(skillsJson); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); // ACTs var result = await subjectUnderTest.GetAllOccupations <Occupation[]>(url, apiKey); // ASSERT result.Should().NotBeNull(); result[0].Name.Should().Be("Renewable energy consultant"); 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>() ); }
public async Task WhenGetSkillsGapForOccupationAndGivenSkills_Then_ShouldReturnSKillsAnalysis(string url, string apiKey) { // ARRANGE const string skillsJson = "{ \"occupation\": \"grants management officer\", \"missingSkills\": [{ \"relationshipType\": \"essential\", " + "\"skill\": \"keep grant applicant informed\", \"lastModified\": \"2016-12-20T20:16:59Z\", \"alternativeLabels\": [\"keep grant applicant notified\", \"keep scholarship applicant notified\", \"keep grant applicant advised\", \"keep grant applicant briefed\", \"keep scholarship applicant advised\", \"keep scholarship applicant briefed\"], \"type\": \"competency\", \"uri\": \"http://data.europa.eu/esco/skill/c0f8207c-2377-4fe2-abc4-b173cc4c31c8\", \"skillReusability\": \"occupation-specific\" }, { \"relationshipType\": \"essential\", " + "\"skill\": \"grant concessions\", \"lastModified\": \"2016-12-20T20:13:59Z\", \"alternativeLabels\": [\"issue concessions\", \"develop concessionary policies\", \"allow concessionary policies\", \"agree concessionary policies\", \"agree concessions\", \"allow concessions\", \"enable concessions\", \"enable concessionary policies\"], \"type\": \"competency\", \"uri\": \"http://data.europa.eu/esco/skill/1ccf5bda-d904-4d00-9c71-9b8f0196e9f9\", \"skillReusability\": \"sector-specific\" }, { \"relationshipType\": \"essential\", " + "\"skill\": \"report on grants\", \"lastModified\": \"2016-12-20T20:16:12Z\", \"alternativeLabels\": [\"summarise grants\", \"administer allocations\", \"report donor and recipient\", \"detail grants\", \"administer grants summarise grants\", \"summarise allocations\", \"detail allocations\"], \"type\": \"competency\", \"uri\": \"http://data.europa.eu/esco/skill/0b6cc8e4-b34d-4631-9061-3ba839ecc640\", \"skillReusability\": \"occupation-specific\" }], " + "\"jobProfileTitle\": null, \"matchingSkills\": [], \"lastModified\": \"2017-02-02T10:53:11Z\", \"alternativeLabels\": [\"proposals manager\", \"grants officer\"], \"jobProfileUri\": null, \"uri\": \"http://data.europa.eu/esco/occupation/89330b57-6a30-40e1-b623-50f47a4b0c34\"}"; var handlerMock = GetMockMessageHandler(skillsJson, HttpStatusCode.OK); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); // ACTs var result = await subjectUnderTest.GetSkillsGapForOccupationAndGivenSkills <SkillsGapAnalysis>(url, apiKey, null, null); // ASSERT result.Should().NotBeNull(); result.CareerTitle.Should().Be("grants management officer"); var description = result.CareerDescription; result.MissingSkills.Length.Should().Be(3); handlerMock.Protected().Verify( "SendAsync", Times.Once(), // we expected a single external request ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post ), ItExpr.IsAny <CancellationToken>() ); }
public async Task When_GetSkillsByLabel_Then_ShouldReturnSkillsList(string url, string apiKey) { // ARRANGE const string skillsJson = "{ " + "\"skills\": [" + "{ \"skillType\": \"knowledge\", \"skill\": \"toxicology\", \"lastModified\": \"2016-12-20T19:32:45Z\", \"alternativeLabels\": [\"study of toxicity\", \"chemical toxicity\", \"study of adverse effects of chemicals\", \"studies of toxicity\"], \"uri\": \"http:\\/\\/data.europa.eu\\/esco\\/skill\\/b70ab677-5781-40b5-9198-d98f4a34310f\", \"matches\": { \"hiddenLabels\": []," + " \"skill\": [\"toxicology\"], \"alternativeLabels\": [\"study of toxicity\", \"chemical toxicity\", \"studies of toxicity\"] }, \"skillReusability\": \"cross-sectoral\" }, " + "{ \"skillType\": \"competency\", \"skill\": \"perform toxicological studies\", \"lastModified\": \"2016-12-20T19:37:05Z\", \"alternativeLabels\": [\"apply toxicological testing methods\", \"perform toxicological tests\", \"perform toxicological study\", \"carry out toxicological studies\"], \"uri\": \"http:\\/\\/data.europa.eu\\/esco\\/skill\\/000bb1e4-89f0-4b86-be05-05ece3641724\", \"matches\": { \"hiddenLabels\": [], \"skill\": [\"perform toxicological studies\"], \"alternativeLabels\": [\"apply toxicological testing methods\", \"perform toxicological tests\", \"perform toxicological study\", \"carry out toxicological studies\"] }, \"skillReusability\": \"cross-sectoral\" }, " + "{ \"skillType\": \"knowledge\", \"skill\": \"food toxicity\", \"lastModified\": \"2016-12-20T19:05:31Z\", \"alternativeLabels\": [\"food spoilage\", \"prevention of food poisoning\", \"toxicity of foods\", \"food poisoning\", \"the toxicity of food\"], \"uri\": \"http:\\/\\/data.europa.eu\\/esco\\/skill\\/4e081e0a-e25f-4f6e-9c75-e9043ba08aad\", \"matches\": { \"hiddenLabels\": [], \"skill\": [\"food toxicity\"], \"alternativeLabels\": [\"toxicity of foods\", \"the toxicity of food\"] }, \"skillReusability\": \"sector-specific\" }]}"; var handlerMock = GetMockMessageHandler(skillsJson, HttpStatusCode.OK); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); // ACTs var result = await subjectUnderTest.GetSkillsByLabel <Skill[]>(url, apiKey, "toxic"); // ASSERT result.Should().NotBeNull(); result.Length.Should().Be(3); handlerMock.Protected().Verify( "SendAsync", Times.Once(), // we expected a single external request ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post ), ItExpr.IsAny <CancellationToken>() ); }
public void Init() { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); _settings.ApiUrl = config.GetSection("ServiceTaxonomySettings").GetSection("ApiUrl").Value; _settings.ApiKey = config.GetSection("ServiceTaxonomySettings").GetSection("ApiKey").Value; _subjectUnderTest = new ServiceTaxonomyRepository(); }
public void When_GetOccupationIdFromName_Then_ShouldReturnOccupationId() { var handlerMock = MockHelpers.GetMockMessageHandler(SkillsJson); var restClient = new RestClient(handlerMock.Object); _serviceTaxonomyRepository = new ServiceTaxonomyRepository(restClient); var sut = new OccupationSearchController(_serviceTaxonomyRepository, _settings, _compositeSettings, _sessionService); var result = sut.GetOccupationIdFromName("Renewable energy consultant"); result.Result.Should().Be("http://data.europa.eu/esco/occupation/114e1eff-215e-47df-8e10-45a5b72f8197"); }
public async Task When_OccupationSearchAutoFails_Then_ShouldReturnNoContent() { // @ToDo: Do this properly. For now we'll set up a local mock for this test. var m = MockHelpers.GetMockMessageHandler("{}"); var rc = new RestClient(m.Object); var str = new ServiceTaxonomyRepository(rc); var sut = new OccupationSearchController(str, _settings, _compositeSettings, _sessionService); var occupations = await sut.OccupationSearchAuto("fgsdhfgsdf"); occupations.Should().NotBeNull(); occupations.Should().BeOfType <NoContentResult>(); }
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); _serviceTaxonomyRepository = new ServiceTaxonomyRepository(restClient); _sessionService.GetUserSession().ReturnsForAnyArgs(new UserSession()); }
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>() * ); */ }
public void When_SearchSkill_Then_RedirectToSelectSkillsView() { var _sessionService = Substitute.For <ISessionService>(); var handlerMock = MockHelpers.GetMockMessageHandler(SkillsJson); var restClient = new RestClient(handlerMock.Object); _serviceTaxonomyRepository = new ServiceTaxonomyRepository(restClient); var sut = new OccupationSearchController(_serviceTaxonomyRepository, _settings, _compositeSettings, _sessionService); sut.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; sut.ControllerContext = MockHelpers.GetControllerContext(); _sessionService.GetUserSession().ReturnsForAnyArgs(MockHelpers.GetUserSession(false)); sut.GetSkillsForOccupation("Renewable energy consultant"); }
public async Task WhenGetSkillsGapForOccupationAndGivenSkills_WithNullParams_Then_ShouldReturnNoContent(string url, string apiKey) { // ARRANGE var handlerMock = GetMockMessageHandler("", HttpStatusCode.NoContent); var restClient = new RestClient(handlerMock.Object); var subjectUnderTest = new ServiceTaxonomyRepository(restClient); // ACTs var result = await subjectUnderTest.GetSkillsGapForOccupationAndGivenSkills <SkillsGapAnalysis>(url, apiKey, null, null); // ASSERT result.Should().BeNull(); handlerMock.Protected().Verify( "SendAsync", Times.Once(), // we expected a single external request ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post ), ItExpr.IsAny <CancellationToken>() ); }