Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow outer to run with stubs. #1794

Open
wants to merge 2 commits into
base: FLP-918-GetLearnerRefFromDC
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<PackageVersion Include="System.Security.Cryptography.Xml" Version="4.7.1" />
<PackageVersion Include="System.Net.Security" Version="4.3.1" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="WireMock.Net" Version="1.5.48" />
<PackageVersion Include="WireMock.Net" Version="1.6.7" />
<PackageVersion Include="WireMock.Net.FluentAssertions" Version="1.5.48" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Web" Version="1.2.1" />
Expand Down
23 changes: 14 additions & 9 deletions src/Payments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,30 @@ Most of the application configuration is taken from the [das-employer-config rep
| Name | Description | Stub Value |
| ------------------------------------------------------------- | ------------------------------------------------- |-------------------------------------------|
| LearnerDataApiConfiguration:Url | Url of the data endpoint | https://localhost:4000/learner-data-api |
| LearnerDataApiConfiguration:TokenSettings:Url | Url of the token endpoint | |
| LearnerDataApiConfiguration:TokenSettings:Url | Url of the token endpoint | http://localhost (if using stub api) |
| LearnerDataApiConfiguration:TokenSettings:Scope | Token settings | |
| LearnerDataApiConfiguration:TokenSettings:ClientId | Token settings | |
| LearnerDataApiConfiguration:TokenSettings:Tenant | Token settings | |
| LearnerDataApiConfiguration:TokenSettings:ClientSecret | Token settings | |
| LearnerDataApiConfiguration:TokenSettings:GrantType | Token settings | |
| LearnerDataApiConfiguration:TokenSettings:ShouldSkipForLocal | For local use only, skips calling token endpoint | true |

### Local Running

* Ensure you have the following appsettings.development.json in the API project root:

```
{
"Environment": "LOCAL",
"ConfigurationStorageConnectionString": "UseDevelopmentStorage=true"
}
```

## 🔗 External Dependencies
* Make sure Azure Storage Emulator is running
* Make sure the config above is in Azure Storage
* If you want to use a stub Learner Data api, select the "API with Stubs" Launch Profile (it'll manage config and start the stubs automatically), otherwise just run SFA.DAS.Payments.API with the https launch profile

The Outer API has many external dependancies which can all be configured to use stubs by following the config above.

## Running Locally
## 🔗 External Dependencies

* Make sure Azure Storage Emulator (Azureite) is running
* Make sure the config has been updated to call any Stub APIs required
* Run the [Commitments Stubs](https://github.com/SkillsFundingAgency/das-commitments-stubs)
* Run the Apprenticeships Inner API
* Run the application
The Outer API has many external dependancies which can all be configured to use stubs by following the config above.
46 changes: 29 additions & 17 deletions src/Payments/SFA.DAS.Payments.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53085",
"sslPort": 44373
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5157",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5157"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7157;http://localhost:5157",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7157;http://localhost:5157"
},
"IIS Express": {
"commandName": "IISExpress",
Expand All @@ -35,6 +26,27 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WithStubs": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"LearnerDataApiConfiguration__Url": "http://localhost:6011",
"LearnerDataApiConfiguration__TokenSettings__ShouldSkipForLocal": "true",
"LearnerDataApiConfiguration__TokenSettings__Url": "http://localhost"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7157;http://localhost:5157"
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53085",
"sslPort": 44373
}
}
}
}
1 change: 1 addition & 0 deletions src/Payments/SFA.DAS.Payments.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SFA.DAS.Payments.Api.AppStart;
using SFA.DAS.Payments.Application.Learners;
using SFA.DAS.SharedOuterApi.AppStart;
using SFA.DAS.SharedOuterApi.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

Expand Down
59 changes: 59 additions & 0 deletions src/Payments/SFA.DAS.Payments.Stubs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.Json;
using AutoFixture;
using SFA.DAS.Payments.Models.Responses;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using WireMock.Settings;

namespace SFA.DAS.Payments.Stubs
{
public class Program
{
private static WireMockServer _fakeLearnerDataApi;

static void Main(string[] args)
{
try
{
_fakeLearnerDataApi = WireMockServer.Start(new WireMockServerSettings
{
Urls = new[] { "http://*:6011" },
StartAdminInterface = true,
});

SetupGetLearnersResponse();

Console.WriteLine(("Please RETURN to stop server"));
Console.ReadLine();
}
finally
{
_fakeLearnerDataApi.Stop();
_fakeLearnerDataApi.Dispose();
}
}

private static void SetupGetLearnersResponse()
{
_fakeLearnerDataApi.Given(
Request.Create().WithPath($"/learners/*")
.UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode((int)HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json")
.WithBody(JsonSerializer.Serialize(GetLearnerResponseObject())));
}

private static List<LearnerResponse> GetLearnerResponseObject()
{
return new Fixture().CreateMany<LearnerResponse>().ToList();
}
}
}
19 changes: 19 additions & 0 deletions src/Payments/SFA.DAS.Payments.Stubs/SFA.DAS.Payments.Stubs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" />
<PackageReference Include="WireMock.Net" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SFA.DAS.Payments\SFA.DAS.Payments.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Payments/SFA.DAS.Payments.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{268E0F
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFA.DAS.SharedOuterApi", "..\Shared\SFA.DAS.SharedOuterApi\SFA.DAS.SharedOuterApi.csproj", "{FBFA8D08-A342-4106-8805-5E4F424C3AB7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stubs", "Stubs", "{6B356F86-6F04-48A3-A6FF-0B7B8084862E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFA.DAS.Payments.Stubs", "SFA.DAS.Payments.Stubs\SFA.DAS.Payments.Stubs.csproj", "{DDE95B5D-161B-41DD-A22A-055173988331}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -46,12 +50,17 @@ Global
{FBFA8D08-A342-4106-8805-5E4F424C3AB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBFA8D08-A342-4106-8805-5E4F424C3AB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBFA8D08-A342-4106-8805-5E4F424C3AB7}.Release|Any CPU.Build.0 = Release|Any CPU
{DDE95B5D-161B-41DD-A22A-055173988331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDE95B5D-161B-41DD-A22A-055173988331}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDE95B5D-161B-41DD-A22A-055173988331}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDE95B5D-161B-41DD-A22A-055173988331}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FBFA8D08-A342-4106-8805-5E4F424C3AB7} = {268E0FE2-9159-48C2-A3BF-EDB6502E0011}
{DDE95B5D-161B-41DD-A22A-055173988331} = {6B356F86-6F04-48A3-A6FF-0B7B8084862E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1FBA9471-0084-450A-961B-4B248AA9922B}
Expand Down
16 changes: 16 additions & 0 deletions src/Payments/SFA.DAS.Payments.slnLaunch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"Name": "API with Stubs",
"Projects": [
{
"Path": "SFA.DAS.Payments.Api\\SFA.DAS.Payments.Api.csproj",
"Action": "Start",
"DebugTarget": "WithStubs"
},
{
"Path": "SFA.DAS.Payments.Stubs\\SFA.DAS.Payments.Stubs.csproj",
"Action": "Start"
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public static IConfigurationRoot BuildSharedConfiguration(this IConfiguration co
{
var config = new ConfigurationBuilder()
.AddConfiguration(configuration)
.SetBasePath(Directory.GetCurrentDirectory())
.AddEnvironmentVariables();
.SetBasePath(Directory.GetCurrentDirectory());
#if DEBUG
config.AddJsonFile("appsettings.json", true);
if (!configuration.IsLocalAcceptanceTests())
Expand All @@ -32,6 +31,8 @@ public static IConfigurationRoot BuildSharedConfiguration(this IConfiguration co
);
}

config.AddEnvironmentVariables();

return config.Build();
}

Expand Down