-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2144 from SkillsFundingAgency/FAT2-295_fatv1_deco…
…missioning FAT2-295 fatv1 decomissioning
- Loading branch information
Showing
31 changed files
with
629 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...oyerFinance.UnitTests/Infrastructure/OuterApiRequests/WhenBuildingGetFrameworksRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...loyerFinance.UnitTests/Infrastructure/OuterApiRequests/WhenBuildingGetProvidersRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...loyerFinance.UnitTests/Infrastructure/OuterApiRequests/WhenBuildingGetStandardsRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...inance.UnitTests/Infrastructure/OuterApiRequests/WhenBuildingTheGetProviderByIdRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/SFA.DAS.EmployerFinance.UnitTests/Infrastructure/WhenHandlingAGetRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.