Skip to content

Commit

Permalink
Merge pull request #2144 from SkillsFundingAgency/FAT2-295_fatv1_deco…
Browse files Browse the repository at this point in the history
…missioning

FAT2-295 fatv1 decomissioning
  • Loading branch information
SijiOdun authored Feb 10, 2021
2 parents a04d9a5 + 7f2a9da commit 73de817
Show file tree
Hide file tree
Showing 31 changed files with 629 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@
<PackageReference Include="SFA.DAS.Activities.Client">
<Version>1.2.71</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.Apprenticeships.Api.Client">
<Version>0.11.98</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.Audit.Client">
<Version>1.0.0.20553</Version>
</PackageReference>
Expand Down Expand Up @@ -269,9 +266,6 @@
<PackageReference Include="SFA.DAS.Provider.Events.Api.Client">
<Version>2.1.97</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.Providers.Api.Client">
<Version>0.11.39</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.ReferenceData.Api.Client">
<Version>1.1.82</Version>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
<PackageReference Include="SFA.DAS.ActiveDirectory">
<Version>1.0.3</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.Apprenticeships.Api.Types">
<Version>0.11.98</Version>
</PackageReference>
<PackageReference Include="SFA.DAS.Audit.Client">
<Version>1.0.0.20553</Version>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static IContainer Initialize()
return new Container(c =>
{
c.AddRegistry<ConfigurationRegistry>();
c.AddRegistry<ManageApprenticeshipsOuterApiRegistry>();
c.AddRegistry<DataRegistry>();
c.AddRegistry<DateTimeRegistry>();
c.AddRegistry<LoggerRegistry>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="SFA.DAS.EmployerAccounts.Types" Version="1.6.2103" />
<PackageReference Include="SFA.DAS.EmployerFinance.Types" Version="0.2.37" />
<PackageReference Include="SFA.DAS.Testing" Version="1.0.14" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.165" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.169" />
<PackageReference Include="SFA.DAS.Testing.EntityFramework" Version="2.0.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SFA.DAS.EmployerFinance.Data;
using SFA.DAS.EmployerFinance.DependencyResolution;
using SFA.DAS.UnitOfWork.EntityFramework.StructureMap;
using SFA.DAS.UnitOfWork.NServiceBus.DependencyResolution.StructureMap;
using SFA.DAS.UnitOfWork.EntityFramework.StructureMap;
using SFA.DAS.UnitOfWork.NServiceBus.DependencyResolution.StructureMap;
using StructureMap;

namespace SFA.DAS.EmployerFinance.MessageHandlers.DependencyResolution
Expand Down Expand Up @@ -29,6 +29,7 @@ public static IContainer Initialize()
c.AddRegistry<NotificationsRegistry>();
c.AddRegistry<NServiceBusUnitOfWorkRegistry>();
c.AddRegistry<PaymentsRegistry>();
c.AddRegistry<ManageApprenticeshipsOuterApiRegistry>();
c.AddRegistry<ProvidersRegistry>();
c.AddRegistry<TokenServiceRegistry>();
c.AddRegistry<StartupRegistry>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public void Arrange()
_mockDasLevyRepository = new Mock<IDasLevyRepository>();
_mockLog = new Mock<ILog>();
_mockInProcessCache = new Mock<IInProcessCache>();
var config = new EmployerFinanceConfiguration { ApprenticeshipInfoService = new ApprenticeshipInfoServiceConfiguration { BaseUrl = "http://BaseUrl.education.gov.uk" } };
var config = new EmployerFinanceConfiguration{ManageApprenticeshipsOuterApiConfiguration = new ManageApprenticeshipsOuterApiConfiguration { BaseUrl = "http://BaseUrl.education.gov.uk" , Key="123" }};

_container = new Container(c =>
{
c.AddRegistry<ManageApprenticeshipsOuterApiRegistry>();
c.AddRegistry<ProvidersRegistry>();
c.For<IDasLevyRepository>().Use(_mockDasLevyRepository.Object);
c.For<EmployerFinanceConfiguration>().Use(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure.OuterApiRequests
{
public class WhenBuildingGetFrameworksRequest
{
[Test]
public void Then_The_Url_Is_Correctly_Constructed()
{
//Arrange
var actual = new GetFrameworksRequest();

//Act
actual.GetUrl.Should().Be("TrainingCourses/frameworks");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure.OuterApiRequests
{
public class WhenBuildingGetProvidersRequest
{
[Test]
public void Then_The_Url_Is_Correctly_Constructed()
{
//Arrange
var actual = new GetProvidersRequest();

//Act
actual.GetUrl.Should().Be("providers");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentAssertions;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure.OuterApiRequests
{
public class WhenBuildingGetStandardsRequest
{
[Test]
public void Then_The_Url_Is_Correctly_Constructed()
{
//Arrange
var actual = new GetStandardsRequest();

//Act
actual.GetUrl.Should().Be("TrainingCourses/standards");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FluentAssertions;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure.OuterApiRequests
{
public class WhenBuildingTheGetProviderByIdRequest
{
[Test]
public void Then_The_Url_Is_Correctly_Constructed()
{
//Arrange
var id = 123;
var actual = new GetProviderRequest(id);

//Act
actual.GetUrl.Should().Be($"providers/{id}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using Moq.Protected;
using Newtonsoft.Json;
using NUnit.Framework;
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Infrastructure;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;

namespace SFA.DAS.EmployerFinance.UnitTests.Infrastructure
{
public class WhenHandlingAGetRequest
{
[Test]
public async Task Then_The_Endpoint_Is_Called_With_Authentication_Header_And_Data_Returned()
{
//Arrange
var key = "123-abc-567";
var getTestRequest = new GetTestRequest();
var testObject = new List<string>();
var config = new ManageApprenticeshipsOuterApiConfiguration {BaseUrl = "http://valid-url/", Key = key};

var response = new HttpResponseMessage
{
Content = new StringContent(JsonConvert.SerializeObject(testObject)),
StatusCode = HttpStatusCode.Accepted
};
var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, $"{config.BaseUrl}{getTestRequest.GetUrl}", config.Key);
var client = new HttpClient(httpMessageHandler.Object);
var apiClient = new ApiClient(client, config);

//Act
var actual = await apiClient.Get<List<string>>(getTestRequest);

//Assert
actual.Should().BeEquivalentTo(testObject);
}

[Test]
public void Then_If_It_Is_Not_Successful_An_Exception_Is_Thrown()
{
//Arrange
var key = "123-abc-567";
var getTestRequest = new GetTestRequest();
var config = new ManageApprenticeshipsOuterApiConfiguration {BaseUrl = "http://valid-url/", Key = key };
var response = new HttpResponseMessage
{
Content = new StringContent(""),
StatusCode = HttpStatusCode.BadRequest
};

var httpMessageHandler = MessageHandler.SetupMessageHandlerMock(response, $"{config.BaseUrl}{getTestRequest.GetUrl}", config.Key);
var client = new HttpClient(httpMessageHandler.Object);
var apiClient = new ApiClient(client, config);

//Act Assert
Assert.ThrowsAsync<HttpRequestException>(() => apiClient.Get<List<string>>(getTestRequest));

}

public class GetTestRequest : IGetApiRequest
{
public string GetUrl => "test-url/get";
}
}
public static class MessageHandler
{
public static Mock<HttpMessageHandler> SetupMessageHandlerMock(HttpResponseMessage response, string url, string key)
{
var httpMessageHandler = new Mock<HttpMessageHandler>();
httpMessageHandler.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(c =>
c.Method.Equals(HttpMethod.Get)
&& c.Headers.Contains("Ocp-Apim-Subscription-Key")
&& c.Headers.GetValues("Ocp-Apim-Subscription-Key").First().Equals(key)
&& c.Headers.Contains("X-Version")
&& c.Headers.GetValues("X-Version").First().Equals("1")
&& c.RequestUri.AbsoluteUri.Equals(url)),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync((HttpRequestMessage request, CancellationToken token) => response);
return httpMessageHandler;
}
}
}
Loading

0 comments on commit 73de817

Please sign in to comment.