From 7f3701ac03151b24e75890ddcd07e2df8c606d37 Mon Sep 17 00:00:00 2001 From: Michael Young Date: Wed, 27 Nov 2024 15:05:47 +0000 Subject: [PATCH 1/2] WiP --- .../Properties/launchSettings.json | 33 +++- .../SFA.DAS.Apprenticeships.Stubs/Program.cs | 187 ++++++++++++++++++ .../SFA.DAS.Apprenticeships.Stubs.csproj | 20 ++ .../SFA.DAS.Apprenticeships.sln | 9 + .../SFA.DAS.Apprenticeships.slnLaunch | 16 ++ 5 files changed, 256 insertions(+), 9 deletions(-) create mode 100644 src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs create mode 100644 src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/SFA.DAS.Apprenticeships.Stubs.csproj create mode 100644 src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json b/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json index 5d63a6be01..5a680e7889 100644 --- a/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json @@ -1,13 +1,4 @@ { - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:22894", - "sslPort": 44333 - } - }, "profiles": { "SFA.DAS.Apprenticeships.Api": { "commandName": "Project", @@ -25,6 +16,30 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "With All Stubs": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "CoursesApiConfiguration__Url": "http://localhost:6011", + "ApprenticeshipsApiConfiguration__Url": "http://localhost:6012", + "CommitmentsV2ApiConfiguration__Url": "http://localhost:6013", + "AccountsInnerApi__Url": "http://localhost:6014", + "EmployerProfilesApiConfiguration__Url": "http://localhost:6015", + "CollectionCalendarApiConfiguration__Url": "http://localhost:6016" + }, + "applicationUrl": "https://localhost:7101;http://localhost:5101", + "dotnetRunMessages": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:22894", + "sslPort": 44333 } } } \ No newline at end of file diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs new file mode 100644 index 0000000000..ffeebeb435 --- /dev/null +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs @@ -0,0 +1,187 @@ +using System.Net; +using System.Text.Json; +using AutoFixture; +using SFA.DAS.Apprenticeships.InnerApi; +using SFA.DAS.Apprenticeships.Responses; +using SFA.DAS.SharedOuterApi.InnerApi.Responses; +using SFA.DAS.SharedOuterApi.InnerApi.Responses.Apprenticeships; +using SFA.DAS.SharedOuterApi.InnerApi.Responses.CollectionCalendar; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; +using WireMock.Server; +using WireMock.Settings; + +namespace SFA.DAS.Apprenticeships.Stubs +{ + public class Program + { + private static WireMockServer _fakeCoursesApi; + private static WireMockServer _fakeApprenticeshipsApi; + private static WireMockServer _fakeCommitmentsApi; + private static WireMockServer _fakeAccountsApi; + private static WireMockServer _fakeEmployerProfilesApi; + private static WireMockServer _fakeCollectionCalendarApi; + + static void Main(string[] args) + { + try + { + _fakeCoursesApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6011" }, + StartAdminInterface = true, + }); + + _fakeApprenticeshipsApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6012" }, + StartAdminInterface = true, + }); + SetUpApprenticeshipResponses(); + + _fakeCommitmentsApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6013" }, + StartAdminInterface = true, + }); + SetUpCommitmentsResponses(); + + _fakeAccountsApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6014" }, + StartAdminInterface = true, + }); + SetUpAccountsResponses(); + + _fakeEmployerProfilesApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6015" }, + StartAdminInterface = true, + }); + SetUpEmployerProfilesResponses(); + + _fakeCollectionCalendarApi = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://*:6016" }, + StartAdminInterface = true, + }); + SetupCollectionCalendarResponses(); + + Console.WriteLine(("Please RETURN to stop server")); + Console.ReadLine(); + } + finally + { + _fakeCoursesApi.Stop(); + _fakeCoursesApi.Dispose(); + _fakeApprenticeshipsApi.Stop(); + _fakeApprenticeshipsApi.Dispose(); + _fakeCommitmentsApi.Stop(); + _fakeCommitmentsApi.Dispose(); + _fakeAccountsApi.Stop(); + _fakeAccountsApi.Dispose(); + _fakeEmployerProfilesApi.Stop(); + _fakeEmployerProfilesApi.Dispose(); + _fakeCollectionCalendarApi.Stop(); + _fakeCollectionCalendarApi.Dispose(); + } + } + + private static void SetupCollectionCalendarResponses() + { + _fakeCollectionCalendarApi.Given( + Request.Create().WithPath($"/academicyears") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + } + + private static void SetUpCommitmentsResponses() + { + _fakeCommitmentsApi.Given( + Request.Create().WithPath($"/api/AccountLegalEntity/*") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeCommitmentsApi.Given( + Request.Create().WithPath($"/api/providers/*") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeCommitmentsApi.Given( + Request.Create().WithPath($"/api/trainingprogramme/*/versions") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + } + + private static void SetUpApprenticeshipResponses() + { + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/key") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/price") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDate") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + } + + private static void SetUpAccountsResponses() + { + _fakeAccountsApi.Given( + Request.Create().WithPath($"/api/user/*/accounts") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().CreateMany()))); + } + + private static void SetUpEmployerProfilesResponses() + { + _fakeEmployerProfilesApi.Given( + Request.Create().WithPath($"/api/users/*") + .UsingGet() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Build().With(x => x.Id, Guid.NewGuid().ToString).Create()))); + } + } +} \ No newline at end of file diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/SFA.DAS.Apprenticeships.Stubs.csproj b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/SFA.DAS.Apprenticeships.Stubs.csproj new file mode 100644 index 0000000000..02bcc5ce9b --- /dev/null +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/SFA.DAS.Apprenticeships.Stubs.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.sln b/src/Apprenticeships/SFA.DAS.Apprenticeships.sln index 02fedcb279..b7495be835 100644 --- a/src/Apprenticeships/SFA.DAS.Apprenticeships.sln +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.sln @@ -17,6 +17,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFA.DAS.SharedOuterApi", ". EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFA.DAS.SharedOuterApi.UnitTests", "..\Shared\SFA.DAS.SharedOuterApi.UnitTests\SFA.DAS.SharedOuterApi.UnitTests.csproj", "{C6ECCA19-D25A-4749-AEEF-9BF003C921F5}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stubs", "Stubs", "{5A06408D-D406-4285-958D-F2618BC987FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SFA.DAS.Apprenticeships.Stubs", "SFA.DAS.Apprenticeships.Stubs\SFA.DAS.Apprenticeships.Stubs.csproj", "{8D741612-C398-4164-95DE-3AAEB0CD39F6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +51,10 @@ Global {C6ECCA19-D25A-4749-AEEF-9BF003C921F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6ECCA19-D25A-4749-AEEF-9BF003C921F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6ECCA19-D25A-4749-AEEF-9BF003C921F5}.Release|Any CPU.Build.0 = Release|Any CPU + {8D741612-C398-4164-95DE-3AAEB0CD39F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D741612-C398-4164-95DE-3AAEB0CD39F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D741612-C398-4164-95DE-3AAEB0CD39F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D741612-C398-4164-95DE-3AAEB0CD39F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -54,6 +62,7 @@ Global GlobalSection(NestedProjects) = preSolution {322E17EC-CEA4-4C01-86B1-C13D09F10B86} = {3FE9AA84-D0A7-42FA-96A7-31136C2C236D} {C6ECCA19-D25A-4749-AEEF-9BF003C921F5} = {3FE9AA84-D0A7-42FA-96A7-31136C2C236D} + {8D741612-C398-4164-95DE-3AAEB0CD39F6} = {5A06408D-D406-4285-958D-F2618BC987FB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E20541EE-1A11-4048-9593-FA357F0ED2FC} diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch b/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch new file mode 100644 index 0000000000..36f52bc264 --- /dev/null +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch @@ -0,0 +1,16 @@ +[ + { + "Name": "With All Stubs", + "Projects": [ + { + "Path": "SFA.DAS.Apprenticeships.Api\\SFA.DAS.Apprenticeships.Api.csproj", + "Action": "Start", + "DebugTarget": "With All Stubs" + }, + { + "Path": "SFA.DAS.Apprenticeships.Stubs\\SFA.DAS.Apprenticeships.Stubs.csproj", + "Action": "Start" + } + ] + } +] \ No newline at end of file From d8bacb2ecadb4330f5b8a4282592b5c677786661 Mon Sep 17 00:00:00 2001 From: Michael Young Date: Wed, 27 Nov 2024 15:28:44 +0000 Subject: [PATCH 2/2] Add new profiles --- .../Properties/launchSettings.json | 15 +++ .../SFA.DAS.Apprenticeships.Stubs/Program.cs | 121 ++++++++++++++++++ .../SFA.DAS.Apprenticeships.slnLaunch | 14 ++ 3 files changed, 150 insertions(+) diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json b/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json index 5a680e7889..39157000af 100644 --- a/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.Api/Properties/launchSettings.json @@ -31,6 +31,21 @@ }, "applicationUrl": "https://localhost:7101;http://localhost:5101", "dotnetRunMessages": true + }, + "With Real Inner": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "CoursesApiConfiguration__Url": "http://localhost:6011", + "ApprenticeshipsApiConfiguration__Url": "http://localhost:6012", + "CommitmentsV2ApiConfiguration__Url": "http://localhost:6013", + "AccountsInnerApi__Url": "http://localhost:6014", + "EmployerProfilesApiConfiguration__Url": "http://localhost:6015", + "CollectionCalendarApiConfiguration__Url": "http://localhost:6016" + }, + "applicationUrl": "https://localhost:7101;http://localhost:5101", + "dotnetRunMessages": true } }, "$schema": "https://json.schemastore.org/launchsettings.json", diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs index ffeebeb435..4be779ac5b 100644 --- a/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs @@ -31,6 +31,7 @@ static void Main(string[] args) Urls = new[] { "http://*:6011" }, StartAdminInterface = true, }); + SetUpCoursesResponses(); _fakeApprenticeshipsApi = WireMockServer.Start(new WireMockServerSettings { @@ -87,6 +88,18 @@ static void Main(string[] args) } } + private static void SetUpCoursesResponses() + { + _fakeCoursesApi.Given( + Request.Create().WithPath($"/api/courses/standards/*") + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + } + private static void SetupCollectionCalendarResponses() { _fakeCollectionCalendarApi.Given( @@ -157,6 +170,114 @@ private static void SetUpApprenticeshipResponses() .WithStatusCode((int)HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/priceHistory").UsingPost() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDateChange").UsingPost() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/priceHistory/pending").UsingGet() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDateChange/pending").UsingGet() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody(JsonSerializer.Serialize(new Fixture().Create()))); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/priceHistory/pending").UsingDelete() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/priceHistory/pending/reject").UsingPatch() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/priceHistory/pending").UsingPatch() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDateChange/pending").UsingDelete() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDateChange/reject").UsingPatch() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/startDateChange/pending").UsingPatch() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/freeze").UsingPost() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); + + _fakeApprenticeshipsApi.Given( + Request.Create().WithPath($"/*/unfreeze").UsingPost() + ) + .RespondWith( + Response.Create() + .WithStatusCode((int)HttpStatusCode.OK) + .WithHeader("Content-Type", "application/json") + .WithBody("{}")); } private static void SetUpAccountsResponses() diff --git a/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch b/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch index 36f52bc264..70d43f2f4b 100644 --- a/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch +++ b/src/Apprenticeships/SFA.DAS.Apprenticeships.slnLaunch @@ -12,5 +12,19 @@ "Action": "Start" } ] + }, + { + "Name": "With Real Inner", + "Projects": [ + { + "Path": "SFA.DAS.Apprenticeships.Api\\SFA.DAS.Apprenticeships.Api.csproj", + "Action": "Start", + "DebugTarget": "With Real Inner" + }, + { + "Path": "SFA.DAS.Apprenticeships.Stubs\\SFA.DAS.Apprenticeships.Stubs.csproj", + "Action": "Start" + } + ] } ] \ No newline at end of file