From 69db0e37bd27998c395a6200b830e42333d03171 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 26 Nov 2024 11:18:52 +0100 Subject: [PATCH] Add more integration tests (#3151) Extend the integration test coverage to include more of the test projects. --- Directory.Packages.props | 4 +- .../SwaggerIntegrationTests.cs | 70 +++++++++++----- ...nsValidSwaggerJson_ForAutofaq.verified.txt | 54 ++++++++++++ ....Program_swaggerRequestUri=v1.verified.txt | 74 +++++++++++++++++ ...Program_swaggerRequestUri=v1.verified.txt} | 0 ...oc.Program_swaggerRequestUri=.verified.txt | 9 ++ ....Program_swaggerRequestUri=v1.verified.txt | 82 +++++++++++++++++++ ...Program_swaggerRequestUri=v1.verified.txt} | 0 .../SwaggerVerifyIntegrationTest.cs | 53 +++++++----- ...hbuckle.AspNetCore.IntegrationTests.csproj | 3 + .../TestSiteAutofaq.cs | 42 ++++++++++ test/WebSites/MinimalApp/Program.cs | 12 ++- .../MinimalAppWithHostedServices/Program.cs | 1 + test/WebSites/MvcWithNullable/Program.cs | 4 +- .../ApiTestsSetup.cs | 4 +- test/WebSites/WebApi.Aot/Program.cs | 10 +++ test/WebSites/WebApi/Program.cs | 3 +- 17 files changed, 376 insertions(+), 49 deletions(-) create mode 100644 test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq.verified.txt create mode 100644 test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MinimalApp.Program_swaggerRequestUri=v1.verified.txt rename test/Swashbuckle.AspNetCore.IntegrationTests/{SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_Mvc_swaggerRequestUri=v1.verified.txt => SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MvcWithNullable.Program_swaggerRequestUri=v1.verified.txt} (100%) create mode 100644 test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=TopLevelSwaggerDoc.Program_swaggerRequestUri=.verified.txt create mode 100644 test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Aot.Program_swaggerRequestUri=v1.verified.txt rename test/Swashbuckle.AspNetCore.IntegrationTests/{SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt => SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.verified.txt} (100%) create mode 100644 test/Swashbuckle.AspNetCore.IntegrationTests/TestSiteAutofaq.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index a123627a6a..cf36e381e9 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,6 +1,6 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs index de11ee3413..35ee4af447 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using System.Net.Http; +using System.Reflection; #if NET8_0_OR_GREATER using System.Net.Http.Json; #endif @@ -41,6 +42,15 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson( await AssertValidSwaggerJson(client, swaggerRequestUri); } + [Fact] + public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq() + { + var testSite = new TestSiteAutofaq(typeof(CliExampleWithFactory.Startup)); + using var client = testSite.BuildClient(); + + await AssertValidSwaggerJson(client, "/swagger/v1/swagger_net8.0.json"); + } + [Fact] public async Task SwaggerEndpoint_ReturnsNotFound_IfUnknownSwaggerDocument() { @@ -113,23 +123,22 @@ public async Task SwaggerMiddleware_CanBeConfiguredMultipleTimes( Assert.Equal(expectedVersionValue, json.GetProperty(expectedVersionProperty).GetString()); } -#if NET8_0_OR_GREATER [Theory] - [InlineData("/swagger/v1/swagger.json")] - public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi( - string swaggerRequestUri) - { - await SwaggerEndpointReturnsValidSwaggerJson(swaggerRequestUri); - } - - [Theory] - [InlineData("/swagger/v1/swagger.json")] - public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_For_Mvc( + [InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")] +#if NET8_0_OR_GREATER + [InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")] +#endif + public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup( + Type entryPointType, string swaggerRequestUri) { - await SwaggerEndpointReturnsValidSwaggerJson(swaggerRequestUri); + await SwaggerEndpointReturnsValidSwaggerJson(entryPointType, swaggerRequestUri); } +#if NET8_0_OR_GREATER [Fact] public async Task TypesAreRenderedCorrectly() { @@ -161,22 +170,45 @@ public async Task TypesAreRenderedCorrectly() () => Assert.True(properties.GetProperty("temperatureF").GetProperty("readOnly").GetBoolean()), ]); } +#endif - private static async Task SwaggerEndpointReturnsValidSwaggerJson(string swaggerRequestUri) - where TEntryPoint : class + private static async Task SwaggerEndpointReturnsValidSwaggerJson(Type entryPointType, string swaggerRequestUri) { - using var application = new TestApplication(); - using var client = application.CreateDefaultClient(); - + using var client = GetHttpClientForTestApplication(entryPointType); await AssertValidSwaggerJson(client, swaggerRequestUri); } -#endif + + internal static HttpClient GetHttpClientForTestApplication(Type entryPointType) + { + var applicationType = typeof(TestApplication<>).MakeGenericType(entryPointType); + var application = (IDisposable)Activator.CreateInstance(applicationType); + Assert.NotNull(application); + + var createClientMethod = applicationType + .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) + .FirstOrDefault(m => m.Name == "CreateDefaultClient" && m.GetParameters().Length == 1); + if (createClientMethod == null) + { + throw new InvalidOperationException($"The method CreateDefaultClient was not found on TestApplication<{entryPointType.FullName}>."); + } + + // Pass null for DelegatingHandler[] + var parameters = new object[] { null }; + + var clientObject = (IDisposable)createClientMethod.Invoke(application, parameters); + if (clientObject is not HttpClient client) + { + throw new InvalidOperationException($"The method CreateDefaultClient on TestApplication<{entryPointType.FullName}> did not return an HttpClient."); + } + + return client; + } private static async Task AssertValidSwaggerJson(HttpClient client, string swaggerRequestUri) { using var swaggerResponse = await client.GetAsync(swaggerRequestUri); - Assert.True(swaggerResponse.IsSuccessStatusCode, await swaggerResponse.Content.ReadAsStringAsync()); + Assert.True(swaggerResponse.IsSuccessStatusCode, $"IsSuccessStatusCode is false. Response: '{await swaggerResponse.Content.ReadAsStringAsync()}'"); using var contentStream = await swaggerResponse.Content.ReadAsStreamAsync(); new OpenApiStreamReader().Read(contentStream, out OpenApiDiagnostic diagnostic); Assert.Empty(diagnostic.Errors); diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq.verified.txt new file mode 100644 index 0000000000..a53ff05609 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq.verified.txt @@ -0,0 +1,54 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "CliExampleWithFactory", + "version": "1.0" + }, + "servers": [ + { + "url": "http://localhost:57556/" + } + ], + "paths": { + "/products": { + "get": { + "tags": [ + "Products" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Product" + } + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Product": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int32" + }, + "description": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + } + } +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MinimalApp.Program_swaggerRequestUri=v1.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MinimalApp.Program_swaggerRequestUri=v1.verified.txt new file mode 100644 index 0000000000..2d32d11ab8 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MinimalApp.Program_swaggerRequestUri=v1.verified.txt @@ -0,0 +1,74 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "MinimalApp", + "version": "v1" + }, + "paths": { + "/WeatherForecast": { + "get": { + "tags": [ + "WeatherForecast" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "text/plain": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/WeatherForecast" + } + } + }, + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/WeatherForecast" + } + } + }, + "text/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/WeatherForecast" + } + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "WeatherForecast": { + "type": "object", + "properties": { + "date": { + "type": "string", + "format": "date-time" + }, + "temperatureC": { + "type": "integer", + "format": "int32" + }, + "temperatureF": { + "type": "integer", + "format": "int32", + "readOnly": true + }, + "summary": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": false + } + } + } +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_Mvc_swaggerRequestUri=v1.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MvcWithNullable.Program_swaggerRequestUri=v1.verified.txt similarity index 100% rename from test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_Mvc_swaggerRequestUri=v1.verified.txt rename to test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=MvcWithNullable.Program_swaggerRequestUri=v1.verified.txt diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=TopLevelSwaggerDoc.Program_swaggerRequestUri=.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=TopLevelSwaggerDoc.Program_swaggerRequestUri=.verified.txt new file mode 100644 index 0000000000..a8341b1285 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=TopLevelSwaggerDoc.Program_swaggerRequestUri=.verified.txt @@ -0,0 +1,9 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "Test API", + "version": "1" + }, + "paths": { }, + "components": { } +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Aot.Program_swaggerRequestUri=v1.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Aot.Program_swaggerRequestUri=v1.verified.txt new file mode 100644 index 0000000000..6d8fa87df9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Aot.Program_swaggerRequestUri=v1.verified.txt @@ -0,0 +1,82 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "Native AoT API V1", + "description": "A sample API for testing Swashbuckle with native AoT", + "termsOfService": "http://tempuri.org/terms", + "version": "v1" + }, + "paths": { + "/todos": { + "get": { + "tags": [ + "WebApi.Aot" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Todo" + } + } + } + } + } + } + } + }, + "/todos/{id}": { + "get": { + "tags": [ + "WebApi.Aot" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + } + }, + "components": { + "schemas": { + "Todo": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int32" + }, + "title": { + "type": "string", + "nullable": true + }, + "dueBy": { + "type": "string", + "format": "date", + "nullable": true + }, + "isComplete": { + "type": "boolean" + } + }, + "additionalProperties": false + } + } + } +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.verified.txt similarity index 100% rename from test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi_swaggerRequestUri=v1.verified.txt rename to test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup_entryPointType=WebApi.Program_swaggerRequestUri=v1.verified.txt diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.cs index 32d4e0f99b..9de4795469 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerVerifyIntegrationTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -39,6 +39,20 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson( await Verifier.Verify(swagger).UseParameters(startupType, GetVersion(swaggerRequestUri)); } + [Fact] + public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_ForAutofaq() + { + var startupType = typeof(CliExampleWithFactory.Startup); + const string swaggerRequestUri = "/swagger/v1/swagger_net8.0.json"; + + var testSite = new TestSiteAutofaq(startupType); + using var client = testSite.BuildClient(); + + using var swaggerResponse = await client.GetAsync(swaggerRequestUri); + var swagger = await swaggerResponse.Content.ReadAsStringAsync(); + await Verifier.Verify(swagger).UseParameters(startupType, GetVersion(swaggerRequestUri)); + } + #if NET6_0 [Theory] [InlineData(typeof(Basic.Startup), "/swagger/v1/swagger.json")] @@ -56,25 +70,23 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_DotNet6( } #endif -#if NET8_0_OR_GREATER [Theory] - [InlineData("/swagger/v1/swagger.json")] - public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi( - string swaggerRequestUri) - { - var swaggerResponse = await SwaggerEndpointReturnsValidSwaggerJson(swaggerRequestUri); - await Verifier.Verify(swaggerResponse).UseParameters(GetVersion(swaggerRequestUri)); - } - - [Theory] - [InlineData("/swagger/v1/swagger.json")] - public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_For_Mvc( + [InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")] +#if NET8_0_OR_GREATER + [InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")] +#endif + public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_Without_Startup( + Type entryPointType, string swaggerRequestUri) { - var swaggerResponse = await SwaggerEndpointReturnsValidSwaggerJson(swaggerRequestUri); - await Verifier.Verify(swaggerResponse).UseParameters(GetVersion(swaggerRequestUri)); + var swaggerResponse = await SwaggerEndpointReturnsValidSwaggerJson(entryPointType, swaggerRequestUri); + await Verifier.Verify(swaggerResponse).UseParameters(entryPointType, GetVersion(swaggerRequestUri)); } +#if NET8_0_OR_GREATER [Fact] public async Task TypesAreRenderedCorrectly() { @@ -84,22 +96,21 @@ public async Task TypesAreRenderedCorrectly() var swaggerResponse = await SwaggerResponse(client, "/swagger/v1/swagger.json"); await Verifier.Verify(swaggerResponse); } +#endif - private static async Task SwaggerEndpointReturnsValidSwaggerJson(string swaggerRequestUri) - where TEntryPoint : class + private static async Task SwaggerEndpointReturnsValidSwaggerJson(Type entryPointType, string swaggerRequestUri) { - using var application = new TestApplication(); - using var client = application.CreateDefaultClient(); - + using var client = SwaggerIntegrationTests.GetHttpClientForTestApplication(entryPointType); return await SwaggerResponse(client, swaggerRequestUri); } + private static async Task SwaggerResponse(HttpClient client, string swaggerRequestUri) { using var swaggerResponse = await client.GetAsync(swaggerRequestUri); var contentStream = await swaggerResponse.Content.ReadAsStringAsync(); return contentStream; } -#endif + private static string GetVersion(string swaggerUi) => #if NET6_0 Regex.Match(swaggerUi, "/\\w+/([\\w+\\d+.-]+)/").Groups[1].Value; diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj b/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj index a54b8e518a..2a6013a317 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj @@ -9,12 +9,14 @@ + + @@ -26,6 +28,7 @@ + diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TestSiteAutofaq.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TestSiteAutofaq.cs new file mode 100644 index 0000000000..5d32e75aaa --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TestSiteAutofaq.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Reflection; +using Autofac.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; + +namespace Swashbuckle.AspNetCore.IntegrationTests +{ + public class TestSiteAutofaq + { + private readonly Type _startupType; + + public TestSiteAutofaq(Type startupType) + { + _startupType = startupType; + } + + public TestServer BuildServer() + { + var startupAssembly = _startupType.GetTypeInfo().Assembly; + var applicationName = startupAssembly.GetName().Name; + + var hostBuilder = new WebHostBuilder() + .UseEnvironment("Development") + .ConfigureServices(services => services.AddAutofac()) + .UseSolutionRelativeContentRoot(Path.Combine("test", "WebSites", applicationName)) + .UseStartup(_startupType); + + return new TestServer(hostBuilder); + } + + public HttpClient BuildClient() + { + var server = BuildServer(); + var client = server.CreateClient(); + + return client; + } + } +} diff --git a/test/WebSites/MinimalApp/Program.cs b/test/WebSites/MinimalApp/Program.cs index b7ce745583..eba538df03 100644 --- a/test/WebSites/MinimalApp/Program.cs +++ b/test/WebSites/MinimalApp/Program.cs @@ -1,5 +1,3 @@ -using Microsoft.OpenApi.Models; - var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -25,3 +23,13 @@ app.MapControllers(); app.Run(); + +namespace MinimalApp +{ + /// + /// Expose the Program class for use with WebApplicationFactory + /// + public partial class Program + { + } +} diff --git a/test/WebSites/MinimalAppWithHostedServices/Program.cs b/test/WebSites/MinimalAppWithHostedServices/Program.cs index 60eade8971..ff05efd797 100644 --- a/test/WebSites/MinimalAppWithHostedServices/Program.cs +++ b/test/WebSites/MinimalAppWithHostedServices/Program.cs @@ -24,6 +24,7 @@ class HostedService : IHostedService { public Task StartAsync(CancellationToken cancellationToken) { + // This is intentional. See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/3151#discussion_r1856678972 throw new Exception("Crash!"); } diff --git a/test/WebSites/MvcWithNullable/Program.cs b/test/WebSites/MvcWithNullable/Program.cs index c3d808e394..eaf33739b4 100644 --- a/test/WebSites/MvcWithNullable/Program.cs +++ b/test/WebSites/MvcWithNullable/Program.cs @@ -33,8 +33,10 @@ public class EnumController : ControllerBase namespace MvcWithNullable { + /// + /// Expose the Program class for use with WebApplicationFactory + /// public partial class Program { - // Expose the Program class for use with WebApplicationFactory } } diff --git a/test/WebSites/TestFirst.IntegrationTests/ApiTestsSetup.cs b/test/WebSites/TestFirst.IntegrationTests/ApiTestsSetup.cs index ac9442e9bc..1ed3865e07 100644 --- a/test/WebSites/TestFirst.IntegrationTests/ApiTestsSetup.cs +++ b/test/WebSites/TestFirst.IntegrationTests/ApiTestsSetup.cs @@ -14,10 +14,10 @@ public ApiTestRunner() Configure(c => { var apiDocsRoot = Path.Combine(GetSolutionRelativeContentRoot(Path.Combine("test", "WebSites", "TestFirst")), "wwwroot", "swagger"); - + // This app demonstrates the two different workflows that can be used with this library ... - // 1) Import OpenAPI file(s) from elsewhere (e.g. created via http://editor.swagger.io) + // 1) Import OpenAPI file(s) from elsewhere (e.g. created via http://editor.swagger.io) c.AddOpenApiFile("v1-imported", $"{apiDocsRoot}/v1-imported/openapi.json"); // 2) Configure OpenApi document(s), add Operation descriptions with tests, and generate files after test run diff --git a/test/WebSites/WebApi.Aot/Program.cs b/test/WebSites/WebApi.Aot/Program.cs index c1e543567e..31f22d2cab 100644 --- a/test/WebSites/WebApi.Aot/Program.cs +++ b/test/WebSites/WebApi.Aot/Program.cs @@ -55,3 +55,13 @@ internal record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsCompl [JsonSerializable(typeof(Todo[]))] internal partial class AppJsonSerializerContext : JsonSerializerContext; + +namespace WebApi.Aot +{ + /// + /// Expose the Program class for use with WebApplicationFactory + /// + public partial class Program + { + } +} diff --git a/test/WebSites/WebApi/Program.cs b/test/WebSites/WebApi/Program.cs index ee4f51266a..57a0514d72 100644 --- a/test/WebSites/WebApi/Program.cs +++ b/test/WebSites/WebApi/Program.cs @@ -37,10 +37,9 @@ namespace WebApi { /// - /// Main class + /// Expose the Program class for use with WebApplicationFactory /// public partial class Program { - // Expose the Program class for use with WebApplicationFactory } }