fix/testing #6

Merged
notazof merged 3 commits from fix/testing into main 2026-07-12 06:03:40 +01:00
5 changed files with 33 additions and 9 deletions
Showing only changes of commit 4aacaf5e51 - Show all commits

tests: configure static fixture ports and update org test config

Paul Schneider 2026-07-12 05:48:47 +01:00

View file

@ -48,6 +48,8 @@ namespace Yavsc.Blogs.Tests;
/// </summary> /// </summary>
public sealed class BlogsWebServerFixture : WebHostFixture public sealed class BlogsWebServerFixture : WebHostFixture
{ {
protected override int HttpsPort => 5103;
private InMemoryDatabaseRoot? _inMemoryRoot; private InMemoryDatabaseRoot? _inMemoryRoot;
protected override WebApplication BuildApp(WebApplicationBuilder builder) protected override WebApplication BuildApp(WebApplicationBuilder builder)

View file

@ -23,7 +23,6 @@ namespace Yavsc.Org.Tests
throw new InvalidOperationException("No HTTPS server address found"); throw new InvalidOperationException("No HTTPS server address found");
HttpClient client = NewHttpClient(); HttpClient client = NewHttpClient();
var disco = await client.GetDiscoveryDocumentAsync(serverUrl); var disco = await client.GetDiscoveryDocumentAsync(serverUrl);
if (disco.IsError) throw new Exception(disco.Error); if (disco.IsError) throw new Exception(disco.Error);

View file

@ -39,6 +39,8 @@ namespace Yavsc.Org.Tests;
[CollectionDefinition("Yavsc Server")] [CollectionDefinition("Yavsc Server")]
public sealed class WebServerFixture : WebHostFixture public sealed class WebServerFixture : WebHostFixture
{ {
protected override int HttpsPort => 5101;
private static IConfiguration? _sharedConfiguration; private static IConfiguration? _sharedConfiguration;
private static SiteSettings? _sharedSiteSettings; private static SiteSettings? _sharedSiteSettings;
private static ILogger? _sharedLogger; private static ILogger? _sharedLogger;
@ -81,6 +83,11 @@ public sealed class WebServerFixture : WebHostFixture
["Smtp:Port"] = "465", ["Smtp:Port"] = "465",
["Smtp:UserName"] = "test-user", ["Smtp:UserName"] = "test-user",
["Smtp:Password"] = "test-pass", ["Smtp:Password"] = "test-pass",
// Kestrel test config: override the default port from
// WebApplication.CreateBuilder() so that the test host
// binds to the same port as the production host would.
["Kestrel:Endpoints:Http:Url"] = "http://localhost:5100",
["Kestrel:Endpoints:Https:Url"] = builder.Configuration["Site:Authority"] ?? "https://localhost:5101"
}); });
Configuration = builder.Configuration; Configuration = builder.Configuration;

View file

@ -1,6 +1,6 @@
{ {
"Site": { "Site": {
"Authority": "https://localhost:5001", "Authority": "https://localhost:5101",
"Title": "Yavsc dev", "Title": "Yavsc dev",
"Slogan": "Yavsc : WIP.", "Slogan": "Yavsc : WIP.",
"Banner": "/images/yavsc.png", "Banner": "/images/yavsc.png",
@ -62,6 +62,16 @@
"UserName": "fakeuser", "UserName": "fakeuser",
"Password": "f/\\kePassw0rd" "Password": "f/\\kePassw0rd"
} }
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5100"
},
"Https": {
"Url": "https://localhost:5101"
}
}
} }
} }

View file

@ -16,8 +16,8 @@ namespace Yavsc.Tests.Shared;
/// ///
/// <list type="bullet"> /// <list type="bullet">
/// <item><description>Kestrel with a self-signed HTTPS certificate /// <item><description>Kestrel with a self-signed HTTPS certificate
/// on a dynamically-allocated port (no port collisions between /// on a fixture-defined fixed port for deterministic integration
/// parallel xUnit test classes).</description></item> /// test endpoints.</description></item>
/// <item><description>A per-process single-instance host initialised /// <item><description>A per-process single-instance host initialised
/// on first construction and torn down when the last fixture is /// on first construction and torn down when the last fixture is
/// disposed — same lazy + lock + count pattern as the original Org /// disposed — same lazy + lock + count pattern as the original Org
@ -86,11 +86,12 @@ public abstract class WebHostFixture : IDisposable
protected virtual void CopySpecialisedSharedState() { } protected virtual void CopySpecialisedSharedState() { }
/// <summary>Specialisations register their services and middleware /// <summary>Specialisations register their services and middleware
/// here. The base class has already configured Kestrel HTTPS on a /// here. The base class has already configured Kestrel HTTPS on
/// dynamic port — do not bind additional listeners.</summary> /// the fixture-defined test port — do not bind additional
/// listeners.</summary>
/// <param name="builder">The <see cref="WebApplicationBuilder"/> /// <param name="builder">The <see cref="WebApplicationBuilder"/>
/// configured with Kestrel HTTPS on a dynamic port and the shared /// configured with Kestrel HTTPS on the fixture-defined test port
/// self-signed certificate.</param> /// and the shared self-signed certificate.</param>
/// <returns>The fully built <see cref="WebApplication"/>, ready /// <returns>The fully built <see cref="WebApplication"/>, ready
/// for <c>ConfigurePipeline</c> + <c>StartAsync</c>.</returns> /// for <c>ConfigurePipeline</c> + <c>StartAsync</c>.</returns>
protected abstract WebApplication BuildApp(WebApplicationBuilder builder); protected abstract WebApplication BuildApp(WebApplicationBuilder builder);
@ -104,13 +105,18 @@ public abstract class WebHostFixture : IDisposable
return app; return app;
} }
/// <summary>HTTPS port used by this fixture's Kestrel host.
/// Override in derived fixtures when they must not share the same
/// listen port.</summary>
protected virtual int HttpsPort => 5101;
private async Task InitializeAsync() private async Task InitializeAsync()
{ {
var builder = WebApplication.CreateBuilder(); var builder = WebApplication.CreateBuilder();
builder.WebHost.ConfigureKestrel(options => builder.WebHost.ConfigureKestrel(options =>
{ {
options.Listen(IPAddress.Loopback, 0, listenOptions => options.Listen(IPAddress.Loopback, HttpsPort, listenOptions =>
{ {
listenOptions.UseHttps(_selfSignedCertificate.Value); listenOptions.UseHttps(_selfSignedCertificate.Value);
}); });