From e7a8d945419eb13b1fc0ed237a61b00f7f410852 Mon Sep 17 00:00:00 2001 From: Michael Young Date: Tue, 19 Nov 2024 14:51:23 +0000 Subject: [PATCH 1/2] Allow outer to run with stubs. --- Directory.Packages.props | 2 +- src/Payments/README.md | 9 ++- .../Properties/launchSettings.json | 46 +++++++++------ src/Payments/SFA.DAS.Payments.Api/Startup.cs | 1 + .../SFA.DAS.Payments.Stubs/Program.cs | 59 +++++++++++++++++++ .../SFA.DAS.Payments.Stubs.csproj | 19 ++++++ src/Payments/SFA.DAS.Payments.sln | 9 +++ src/Payments/SFA.DAS.Payments.slnLaunch | 16 +++++ .../AppStart/ConfigurationBuilder.cs | 5 +- 9 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 src/Payments/SFA.DAS.Payments.Stubs/Program.cs create mode 100644 src/Payments/SFA.DAS.Payments.Stubs/SFA.DAS.Payments.Stubs.csproj create mode 100644 src/Payments/SFA.DAS.Payments.slnLaunch diff --git a/Directory.Packages.props b/Directory.Packages.props index 0929fc46bf..2502a4fa9e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -75,7 +75,7 @@ - + diff --git a/src/Payments/README.md b/src/Payments/README.md index 3bf8b624c3..38456ced4e 100644 --- a/src/Payments/README.md +++ b/src/Payments/README.md @@ -38,7 +38,14 @@ Most of the application configuration is taken from the [das-employer-config rep | LearnerDataApiConfiguration:TokenSettings:GrantType | Token settings | | | LearnerDataApiConfiguration:TokenSettings:ShouldSkipForLocal | For local use only, skips calling token endpoint | true | - +* Ensure you have the following appsettings.development.json in the API project root: + +``` +{ + "Environment": "LOCAL", + "ConfigurationStorageConnectionString": "UseDevelopmentStorage=true" +} +``` ## 🔗 External Dependencies diff --git a/src/Payments/SFA.DAS.Payments.Api/Properties/launchSettings.json b/src/Payments/SFA.DAS.Payments.Api/Properties/launchSettings.json index 7850330879..2f14b08f3f 100644 --- a/src/Payments/SFA.DAS.Payments.Api/Properties/launchSettings.json +++ b/src/Payments/SFA.DAS.Payments.Api/Properties/launchSettings.json @@ -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", @@ -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 } } -} +} \ No newline at end of file diff --git a/src/Payments/SFA.DAS.Payments.Api/Startup.cs b/src/Payments/SFA.DAS.Payments.Api/Startup.cs index 969b98454d..00b4731ef5 100644 --- a/src/Payments/SFA.DAS.Payments.Api/Startup.cs +++ b/src/Payments/SFA.DAS.Payments.Api/Startup.cs @@ -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; diff --git a/src/Payments/SFA.DAS.Payments.Stubs/Program.cs b/src/Payments/SFA.DAS.Payments.Stubs/Program.cs new file mode 100644 index 0000000000..5eb7893485 --- /dev/null +++ b/src/Payments/SFA.DAS.Payments.Stubs/Program.cs @@ -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 GetLearnerResponseObject() + { + return new Fixture().CreateMany().ToList(); + } + } +} diff --git a/src/Payments/SFA.DAS.Payments.Stubs/SFA.DAS.Payments.Stubs.csproj b/src/Payments/SFA.DAS.Payments.Stubs/SFA.DAS.Payments.Stubs.csproj new file mode 100644 index 0000000000..2783baadd2 --- /dev/null +++ b/src/Payments/SFA.DAS.Payments.Stubs/SFA.DAS.Payments.Stubs.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/src/Payments/SFA.DAS.Payments.sln b/src/Payments/SFA.DAS.Payments.sln index 0845940dd9..15ca8c5499 100644 --- a/src/Payments/SFA.DAS.Payments.sln +++ b/src/Payments/SFA.DAS.Payments.sln @@ -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 @@ -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} diff --git a/src/Payments/SFA.DAS.Payments.slnLaunch b/src/Payments/SFA.DAS.Payments.slnLaunch new file mode 100644 index 0000000000..52719261b9 --- /dev/null +++ b/src/Payments/SFA.DAS.Payments.slnLaunch @@ -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" + } + ] + } +] \ No newline at end of file diff --git a/src/Shared/SFA.DAS.SharedOuterApi/AppStart/ConfigurationBuilder.cs b/src/Shared/SFA.DAS.SharedOuterApi/AppStart/ConfigurationBuilder.cs index f0ff4260ce..c2064782bb 100644 --- a/src/Shared/SFA.DAS.SharedOuterApi/AppStart/ConfigurationBuilder.cs +++ b/src/Shared/SFA.DAS.SharedOuterApi/AppStart/ConfigurationBuilder.cs @@ -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()) @@ -32,6 +31,8 @@ public static IConfigurationRoot BuildSharedConfiguration(this IConfiguration co ); } + config.AddEnvironmentVariables(); + return config.Build(); } From 9488d807430782acf41a84b8732c8ffae40af20a Mon Sep 17 00:00:00 2001 From: Michael Young Date: Tue, 19 Nov 2024 15:06:41 +0000 Subject: [PATCH 2/2] Updated local running instructions. --- src/Payments/README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Payments/README.md b/src/Payments/README.md index 38456ced4e..ff738b479d 100644 --- a/src/Payments/README.md +++ b/src/Payments/README.md @@ -30,7 +30,7 @@ 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 | | @@ -38,6 +38,8 @@ Most of the application configuration is taken from the [das-employer-config rep | 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: ``` @@ -47,15 +49,11 @@ Most of the application configuration is taken from the [das-employer-config rep } ``` +* 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 -## 🔗 External Dependencies - -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 \ No newline at end of file +The Outer API has many external dependancies which can all be configured to use stubs by following the config above. \ No newline at end of file