Skip to content

Commit

Permalink
Merge pull request #1811 from SkillsFundingAgency/FLP-1018_Apprentice…
Browse files Browse the repository at this point in the history
…shipsStubs

Flp 1018 apprenticeships stubs
  • Loading branch information
ShakilUmar authored Jan 7, 2025
2 parents a669d7b + d8bacb2 commit 181b28e
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -25,6 +16,45 @@
"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
},
"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",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22894",
"sslPort": 44333
}
}
}
308 changes: 308 additions & 0 deletions src/Apprenticeships/SFA.DAS.Apprenticeships.Stubs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
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,
});
SetUpCoursesResponses();

_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 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<GetStandardsListItem>())));
}

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<GetAcademicYearsResponse>())));
}

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<GetAccountLegalEntityResponse>())));

_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<GetProviderResponse>())));

_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<GetTrainingProgrammeVersionsResponse>())));
}

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<Guid>())));

_fakeApprenticeshipsApi.Given(
Request.Create().WithPath($"/*/price")
)
.RespondWith(
Response.Create()
.WithStatusCode((int)HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json")
.WithBody(JsonSerializer.Serialize(new Fixture().Create<GetApprenticeshipPriceResponse>())));

_fakeApprenticeshipsApi.Given(
Request.Create().WithPath($"/*/startDate")
)
.RespondWith(
Response.Create()
.WithStatusCode((int)HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json")
.WithBody(JsonSerializer.Serialize(new Fixture().Create<GetApprenticeshipStartDateResponse>())));

_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<PostCreateApprenticeshipPriceChangeApiResponse>())));

_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<GetPendingPriceChangeApiResponse>())));

_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<GetPendingStartDateChangeApiResponse>())));

_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()
{
_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<GetUserAccountsResponse>())));
}

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<EmployerProfileUsersApiResponse>().With(x => x.Id, Guid.NewGuid().ToString).Create())));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<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="..\..\Shared\SFA.DAS.SharedOuterApi\SFA.DAS.SharedOuterApi.csproj" />
<ProjectReference Include="..\SFA.DAS.Apprenticeships\SFA.DAS.Apprenticeships.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 181b28e

Please sign in to comment.