Skip to content

Commit cd9c2e6

Browse files
committed
Store swagger documents in SwaggerDocuments directory as a part of test execution
1 parent ea30dc1 commit cd9c2e6

File tree

6 files changed

+1256
-18
lines changed

6 files changed

+1256
-18
lines changed

test/OpenApiClientTests/OpenApiClientTests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<OpenApiReference Include="..\OpenApiTests\LegacyOpenApiIntegration\swagger.json">
31+
<OpenApiReference Include="..\OpenApiTests\SwaggerDocuments\LegacyOpenApiIntegration.json">
3232
<Namespace>OpenApiClientTests.LegacyClient.GeneratedCode</Namespace>
3333
<ClassName>OpenApiClient</ClassName>
3434
<CodeGenerator>NSwagCSharp</CodeGenerator>
3535
<Options>/UseBaseUrl:false /GenerateClientInterfaces:true /ClientClassAccessModifier:internal</Options>
3636
</OpenApiReference>
3737
</ItemGroup>
3838

39-
<ItemGroup>
40-
<EmbeddedResource Include="..\OpenApiTests\LegacyOpenApiIntegration\swagger.json" />
41-
</ItemGroup>
42-
4339
<!-- Fixes IntelliSense errors on openapi.json in Visual Studio 2019, which uses the schema for OpenAPI 3.1 by default. -->
4440
<ProjectExtensions>
4541
<VisualStudio>

test/OpenApiTests/LegacyOpenApiIntegration/LegacyOpenApiIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public LegacyOpenApiIntegrationTests()
2424
public async Task Retrieved_document_matches_expected_document()
2525
{
2626
// Arrange
27-
string embeddedResourceName = $"{nameof(OpenApiTests)}.{nameof(LegacyOpenApiIntegration)}.swagger.json";
27+
string embeddedResourceName = $"{nameof(OpenApiTests)}.SwaggerDocuments.{nameof(LegacyOpenApiIntegration)}.json";
2828
string expectedDocument = await LoadEmbeddedResourceAsync(embeddedResourceName);
2929
const string requestUrl = "swagger/v1/swagger.json";
3030

test/OpenApiTests/NamingConvention/KebabCase/KebabCaseTests.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Net.Http;
34
using System.Text.Json;
45
using System.Threading;
@@ -22,8 +23,10 @@ public KebabCaseTests(IntegrationTestContext<KebabCaseNamingConventionStartup<Na
2223
_lazyOpenApiDocument ??= new Lazy<Task<JsonDocument>>(async () =>
2324
{
2425
testContext.UseController<SupermarketsController>();
25-
const string requestUrl = "swagger/v1/swagger.json";
26-
string content = await GetAsync(requestUrl);
26+
27+
string content = await GetAsync("swagger/v1/swagger.json");
28+
29+
await WriteToSwaggerDocumentsFolderAsync(content);
2730

2831
return JsonDocument.Parse(content);
2932
}, LazyThreadSafetyMode.ExecutionAndPublication);
@@ -39,6 +42,18 @@ private async Task<string> GetAsync(string requestUrl)
3942
return await responseMessage.Content.ReadAsStringAsync();
4043
}
4144

45+
private static async Task WriteToSwaggerDocumentsFolderAsync(string content)
46+
{
47+
string path = GetSwaggerDocumentPath(nameof(KebabCase));
48+
await File.WriteAllTextAsync(path, content);
49+
}
50+
51+
private static string GetSwaggerDocumentPath(string fileName)
52+
{
53+
string swaggerDocumentsDirectory = Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName;
54+
return Path.Join(swaggerDocumentsDirectory, "SwaggerDocuments", $"{fileName}.json");
55+
}
56+
4257
[Fact]
4358
public async Task Kebab_naming_policy_is_applied_to_get_collection_endpoint()
4459
{

test/OpenApiTests/OpenApiTests.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
</PropertyGroup>
55

66
<ItemGroup>
7-
<ProjectReference Include="..\..\src\JsonApiDotNetCore.OpenApi\JsonApiDotNetCore.OpenApi.csproj"/>
8-
<ProjectReference Include="..\TestBuildingBlocks\TestBuildingBlocks.csproj"/>
7+
<ProjectReference Include="..\..\src\JsonApiDotNetCore.OpenApi\JsonApiDotNetCore.OpenApi.csproj" />
8+
<ProjectReference Include="..\TestBuildingBlocks\TestBuildingBlocks.csproj" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All"/>
13-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)"/>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)"/>
15-
<PackageReference Include="BlushingPenguin.JsonPath" Version="$(BlushingPenguinVersion)"/>
16-
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3"/>
12+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCoreVersion)" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
15+
<PackageReference Include="BlushingPenguin.JsonPath" Version="$(BlushingPenguinVersion)" />
16+
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<EmbeddedResource Include="LegacyOpenApiIntegration\swagger.json"/>
20+
<EmbeddedResource Include="SwaggerDocuments\LegacyOpenApiIntegration.json" />
2121
</ItemGroup>
22-
22+
2323
<!-- Fixes IntelliSense errors on openapi.json in Visual Studio 2019, which uses the schema for OpenAPI 3.1 by default. -->
2424
<ProjectExtensions>
2525
<VisualStudio>
26-
<UserProperties swagger_1json__JsonSchema="https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json"/>
26+
<UserProperties swagger_1json__JsonSchema="https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json" />
2727
</VisualStudio>
2828
</ProjectExtensions>
2929
</Project>

0 commit comments

Comments
 (0)