<commit_before>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using NUnit.Framework;
using SFA.DAS.EAS.Portal.Client.Http;
using SFA.DAS.EAS.Portal.Client.Services.DasRecruit;
using SFA.DAS.EAS.Portal.Client.Types;
using SFA.DAS.EAS.Portal.UnitTests.Fakes;
using SFA.DAS.Testing;

namespace SFA.DAS.EAS.Portal.UnitTests.Client.Services.DasRecruit
{
    [TestFixture, Parallelizable]
    internal class DasRecruitServiceTests : FluentTest<DasRecruitServiceTestsFixture>
    {
        [Test]
        public Task GetVacancies_X_y()
        {
            return TestAsync(f => f.ArrangeApiReturnsOk(), f => f.GetVacancies(), (f, r) => r.Should());
        }
    }

    internal class DasRecruitServiceTestsFixture
    {
        public DasRecruitService DasRecruitService { get; set; }
        public ILogger<DasRecruitService> Logger { get; set; }
        public Mock<IRecruitApiHttpClientFactory> RecruitApiHttpClientFactory { get; set; }
        public FakeHttpMessageHandler HttpMessageHandler { get; set; }
        public HttpClient HttpClient { get; set; }
        
        public DasRecruitServiceTestsFixture()
        {
            Logger = new NullLogger<DasRecruitService>();

            HttpMessageHandler = new FakeHttpMessageHandler();
            HttpClient = new HttpClient(HttpMessageHandler) { BaseAddress = new Uri("https://example.com") };

            RecruitApiHttpClientFactory = new Mock<IRecruitApiHttpClientFactory>();
            RecruitApiHttpClientFactory.Setup(f => f.CreateHttpClient()).Returns(HttpClient);
            
            DasRecruitService = new DasRecruitService(RecruitApiHttpClientFactory.Object, Logger);
        }

        public DasRecruitServiceTestsFixture ArrangeApiReturnsOk()
        {
            HttpMessageHandler.HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"Vacancies\":[{\"Title\":\"Seafarer apprenticeship\",\"VacancyReference\":1000004431,\"LegalEntityId\":1234,\"LegalEntityName\":\"<NAME>\",\"EmployerAccountId\":\"ABC1D3\",\"EmployerName\":\"<NAME>\",\"Ukprn\":12345678,\"CreatedDate\":\"2019-06-12T10:35:10.457\",\"Status\":\"Live\",\"ClosingDate\":\"2020-10-10T00:00:00\",\"Duration\":2,\"DurationUnit\":\"Year\",\"ApplicationMethod\":\"ThroughFindAnApprenticeship\",\"ProgrammeId\":\"34\",\"StartDate\":\"2019-11-10T00:00:00\",\"TrainingTitle\":\"Able seafarer (deck)\",\"TrainingType\":\"Standard\",\"TrainingLevel\":\"Intermediate\",\"NoOfNewApplications\":0,\"NoOfSuccessfulApplications\":1,\"NoOfUnsuccessfulApplications\":0,\"FaaVacancyDetailUrl\":\"https://findapprenticeship.service.gov.uk/apprenticeship/1000004431\",\"RaaManageVacancyUrl\":\"https://recruit.apprenticeships.education.gov.uk/12345678/vacancies/eb0d5d5b-6cb9-469e-9423-bdc9db1ef5b9/manage/\"}],\"PageSize\":25,\"PageNo\":1,\"TotalResults\":1,\"TotalPages\":1}"),
                ReasonPhrase = "OK",
                RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.com")
            };
            
            return this;
        }

        public DasRecruitServiceTestsFixture ArrangeApiReturnsInternalServerError()
        {
            HttpMessageHandler.HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent("Kaboom"),
                ReasonPhrase = "Internal server error",
                RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.com")
            };
            
            return this;
        }
        
        public async Task<IEnumerable<Vacancy>> GetVacancies()
        {
            const long accountId = 123L;
            return await DasRecruitService.GetVacancies(accountId);
        }
    }
}<commit_msg>unit test wip<commit_after>﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using NUnit.Framework;
using SFA.DAS.EAS.Portal.Client.Http;
using SFA.DAS.EAS.Portal.Client.Services.DasRecruit;
using SFA.DAS.EAS.Portal.Client.Types;
using SFA.DAS.EAS.Portal.UnitTests.Fakes;
using SFA.DAS.Testing;

namespace SFA.DAS.EAS.Portal.UnitTests.Client.Services.DasRecruit
{
    [TestFixture, Parallelizable]
    internal class DasRecruitServiceTests : FluentTest<DasRecruitServiceTestsFixture>
    {
        [Test]
        public Task GetVacancies_WhenSingleVacancyIsReturnedByApi_ThenCorrectlyMappedVacancyIsReturned()
        {
            return TestAsync(f => f.ArrangeApiReturnsOk(), f => f.GetVacancies(), (f, r) => f.AssertVacancies(r));
        }
    }

    internal class DasRecruitServiceTestsFixture
    {
        public DasRecruitService DasRecruitService { get; set; }
        public ILogger<DasRecruitService> Logger { get; set; }
        public Mock<IRecruitApiHttpClientFactory> RecruitApiHttpClientFactory { get; set; }
        public FakeHttpMessageHandler HttpMessageHandler { get; set; }
        public HttpClient HttpClient { get; set; }
        
        public DasRecruitServiceTestsFixture()
        {
            Logger = new NullLogger<DasRecruitService>();

            HttpMessageHandler = new FakeHttpMessageHandler();
            HttpClient = new HttpClient(HttpMessageHandler) { BaseAddress = new Uri("https://example.com") };

            RecruitApiHttpClientFactory = new Mock<IRecruitApiHttpClientFactory>();
            RecruitApiHttpClientFactory.Setup(f => f.CreateHttpClient()).Returns(HttpClient);
            
            DasRecruitService = new DasRecruitService(RecruitApiHttpClientFactory.Object, Logger);
        }

        public DasRecruitServiceTestsFixture ArrangeApiReturnsOk()
        {
            HttpMessageHandler.HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"Vacancies\":[{\"Title\":\"Seafarer apprenticeship\",\"VacancyReference\":1000004431,\"LegalEntityId\":1234,\"LegalEntityName\":\"<NAME>\",\"EmployerAccountId\":\"ABC1D3\",\"EmployerName\":\"<NAME>\",\"Ukprn\":12345678,\"CreatedDate\":\"2019-06-12T10:35:10.457\",\"Status\":\"Live\",\"ClosingDate\":\"2020-10-10T00:00:00\",\"Duration\":2,\"DurationUnit\":\"Year\",\"ApplicationMethod\":\"ThroughFindAnApprenticeship\",\"ProgrammeId\":\"34\",\"StartDate\":\"2019-11-10T00:00:00\",\"TrainingTitle\":\"Able seafarer (deck)\",\"TrainingType\":\"Standard\",\"TrainingLevel\":\"Intermediate\",\"NoOfNewApplications\":0,\"NoOfSuccessfulApplications\":1,\"NoOfUnsuccessfulApplications\":0,\"FaaVacancyDetailUrl\":\"https://findapprenticeship.service.gov.uk/apprenticeship/1000004431\",\"RaaManageVacancyUrl\":\"https://recruit.apprenticeships.education.gov.uk/12345678/vacancies/eb0d5d5b-6cb9-469e-9423-bdc9db1ef5b9/manage/\"}],\"PageSize\":25,\"PageNo\":1,\"TotalResults\":1,\"TotalPages\":1}"),
                ReasonPhrase = "OK",
                RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.com")
            };
            
            return this;
        }

        public DasRecruitServiceTestsFixture ArrangeApiReturnsInternalServerError()
        {
            HttpMessageHandler.HttpResponseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = new StringContent("Kaboom"),
                ReasonPhrase = "Internal server error",
                RequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://example.com")
            };
            
            return this;
        }
        
        public async Task<IEnumerable<Vacancy>> GetVacancies()
        {
            const long accountId = 123L;
            return await DasRecruitService.GetVacancies(accountId);
        }

        public void AssertVacancies(IEnumerable<Vacancy> vacancies)
        {
            vacancies.Should().BeEquivalentTo(new List<Vacancy>
            {
                new Vacancy
                {
                    Title = "Seafarer apprenticeship",
                    Reference = 1000004431L,
                    Status = VacancyStatus.Live,
                    ClosingDate = new DateTime(2020, 10, 10), 
                    TrainingTitle = "Able seafarer (deck)",
                    NumberOfApplications = 1,
                    ManageVacancyUrl = "https://recruit.apprenticeships.education.gov.uk/12345678/vacancies/eb0d5d5b-6cb9-469e-9423-bdc9db1ef5b9/manage/"
                }
            });
        }
    }
}
{'fraction_non_alphanumeric': 0.13061364415495372, 'fraction_numerical': 0.03165352531139298, 'mean_word_length': 2.978181818181818, 'pattern_counts': {'":': 56, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206743', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2516, 'n_words': 332}