From 5e8b61c1cd35d00d8d29e88c5cbca95db5d0fc4e Mon Sep 17 00:00:00 2001 From: Joe DeCock Date: Wed, 3 Sep 2025 18:27:07 -0500 Subject: [PATCH] Merge Config into main IntegrationTests project --- .github/workflow-gen/Program.cs | 2 +- .github/workflows/identity-server-ci.yml | 14 --- .gitignore | 1 - identity-server/identity-server.slnf | 1 - .../Configuration.IntegrationTests.csproj | 26 ----- .../TestFramework/GenericHost.cs | 103 ------------------ .../TestFramework/MockClock.cs | 12 -- .../TestFramework/TestLoggerProvider.cs | 49 --------- .../Common}/MockCancellationTokenProvider.cs | 2 +- .../DynamicClientRegistrationTests.cs | 0 ...ynamicClientRegistrationValidationTests.cs | 0 .../IdentityServer.IntegrationTests.csproj | 2 + .../TestHosts/ConfigurationHost.cs | 3 +- .../ConfigurationIntegrationTestBase.cs | 0 .../TestHosts/IdentityServerHost.cs | 5 +- products.slnx | 1 - 16 files changed, 8 insertions(+), 213 deletions(-) delete mode 100644 identity-server/test/Configuration.IntegrationTests/Configuration.IntegrationTests.csproj delete mode 100644 identity-server/test/Configuration.IntegrationTests/TestFramework/GenericHost.cs delete mode 100644 identity-server/test/Configuration.IntegrationTests/TestFramework/MockClock.cs delete mode 100644 identity-server/test/Configuration.IntegrationTests/TestFramework/TestLoggerProvider.cs rename identity-server/test/{Configuration.IntegrationTests/TestFramework => IdentityServer.IntegrationTests/Common}/MockCancellationTokenProvider.cs (85%) rename identity-server/test/{Configuration.IntegrationTests => IdentityServer.IntegrationTests/Configuration}/DynamicClientRegistrationTests.cs (100%) rename identity-server/test/{Configuration.IntegrationTests => IdentityServer.IntegrationTests/Configuration}/DynamicClientRegistrationValidationTests.cs (100%) rename identity-server/test/{Configuration.IntegrationTests => IdentityServer.IntegrationTests}/TestHosts/ConfigurationHost.cs (94%) rename identity-server/test/{Configuration.IntegrationTests => IdentityServer.IntegrationTests}/TestHosts/ConfigurationIntegrationTestBase.cs (100%) rename identity-server/test/{Configuration.IntegrationTests => IdentityServer.IntegrationTests}/TestHosts/IdentityServerHost.cs (92%) diff --git a/.github/workflow-gen/Program.cs b/.github/workflow-gen/Program.cs index 72b569af9..420fc29a0 100644 --- a/.github/workflow-gen/Program.cs +++ b/.github/workflow-gen/Program.cs @@ -20,7 +20,7 @@ var products = new Product[] new("identity-server", "identity-server.slnf", "is", - ["Configuration.IntegrationTests", "EntityFramework.Storage.UnitTests", "IdentityServer.IntegrationTests", "IdentityServer.UnitTests"], + ["EntityFramework.Storage.UnitTests", "IdentityServer.IntegrationTests", "IdentityServer.UnitTests"], []) }; foreach (var product in products) diff --git a/.github/workflows/identity-server-ci.yml b/.github/workflows/identity-server-ci.yml index 79fcb947f..c9960b389 100644 --- a/.github/workflows/identity-server-ci.yml +++ b/.github/workflows/identity-server-ci.yml @@ -90,20 +90,6 @@ jobs: run: dotnet build identity-server.slnf --no-restore -c Release - name: Dotnet devcerts run: dotnet dev-certs https --trust - - name: Test - test/Configuration.IntegrationTests - run: dotnet test test/Configuration.IntegrationTests -c Release --no-build --logger "console;verbosity=normal" --logger "trx;LogFileName=test/Configuration.IntegrationTests-tests.trx" --collect:"XPlat Code Coverage" - - id: test-report-test-Configuration-IntegrationTests - name: Test report - test/Configuration.IntegrationTests - if: github.event_name == 'push' && (success() || failure()) - uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 - with: - name: Test Report - test/Configuration.IntegrationTests - path: '**/test/Configuration.IntegrationTests-tests.trx' - reporter: dotnet-trx - fail-on-error: true - fail-on-empty: true - - name: Publish test report link - run: echo "[Test Results - test/Configuration.IntegrationTests](${{ steps.test-report-test-Configuration-IntegrationTests.outputs.url_html }})" >> $GITHUB_STEP_SUMMARY - name: Test - test/EntityFramework.Storage.UnitTests run: dotnet test test/EntityFramework.Storage.UnitTests -c Release --no-build --logger "console;verbosity=normal" --logger "trx;LogFileName=test/EntityFramework.Storage.UnitTests-tests.trx" --collect:"XPlat Code Coverage" - id: test-report-test-EntityFramework-Storage-UnitTests diff --git a/.gitignore b/.gitignore index d1d40e4b6..d9d12aaf8 100644 --- a/.gitignore +++ b/.gitignore @@ -217,7 +217,6 @@ src/IdentityServer4/host/identityserver.db tempkey.jwk keys *.key -test/Configuration.IntegrationTests/CoverageReports nCrunchTemp_* playwright-traces diff --git a/identity-server/identity-server.slnf b/identity-server/identity-server.slnf index 3743a4abd..506138ca5 100644 --- a/identity-server/identity-server.slnf +++ b/identity-server/identity-server.slnf @@ -65,7 +65,6 @@ "identity-server\\templates\\src\\IdentityServerInMem\\IdentityServerInMem.csproj", "identity-server\\templates\\src\\IdentityServer\\IdentityServerTemplate.csproj", "identity-server\\templates\\src\\WebApp\\TemplateWebApp.csproj", - "identity-server\\test\\Configuration.IntegrationTests\\Configuration.IntegrationTests.csproj", "identity-server\\test\\EntityFramework.Storage.UnitTests\\EntityFramework.Storage.UnitTests.csproj", "identity-server\\test\\IdentityServer.IntegrationTests\\IdentityServer.IntegrationTests.csproj", "identity-server\\test\\IdentityServer.UnitTests\\IdentityServer.UnitTests.csproj", diff --git a/identity-server/test/Configuration.IntegrationTests/Configuration.IntegrationTests.csproj b/identity-server/test/Configuration.IntegrationTests/Configuration.IntegrationTests.csproj deleted file mode 100644 index 826143222..000000000 --- a/identity-server/test/Configuration.IntegrationTests/Configuration.IntegrationTests.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - net8.0;net9.0 - enable - - - - - - - - - - - - - - - - - - - diff --git a/identity-server/test/Configuration.IntegrationTests/TestFramework/GenericHost.cs b/identity-server/test/Configuration.IntegrationTests/TestFramework/GenericHost.cs deleted file mode 100644 index 8950c5288..000000000 --- a/identity-server/test/Configuration.IntegrationTests/TestFramework/GenericHost.cs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// See LICENSE in the project root for license information. - - -using System.Reflection; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace IntegrationTests.TestFramework; - -public class GenericHost -{ - public GenericHost(string baseAddress = "https://server") - { - if (baseAddress.EndsWith('/')) - { - baseAddress = baseAddress.Substring(0, baseAddress.Length - 1); - } - - _baseAddress = baseAddress; - } - - private readonly string _baseAddress; - protected IServiceProvider? _appServices; - - public Assembly? HostAssembly { get; set; } - public bool IsDevelopment { get; set; } - - public TestServer? Server { get; private set; } - public HttpClient? HttpClient { get; set; } - - public TestLoggerProvider Logger { get; set; } = new TestLoggerProvider(); - - - public T Resolve() - where T : notnull - { - if (_appServices == null) - { - throw new Exception("Attempt to resolve services before service provider created. Call ConfigureApp first"); - } - // not calling dispose on scope on purpose - return _appServices.GetRequiredService().CreateScope().ServiceProvider.GetRequiredService(); - } - - public string Url(string path = "") - { - if (!path.StartsWith('/')) - { - path = '/' + path; - } - - return _baseAddress + path; - } - - public async Task InitializeAsync() - { - var builder = WebApplication.CreateBuilder(new WebApplicationOptions - { - EnvironmentName = IsDevelopment ? "Development" : "Production" - }); - builder.WebHost.UseTestServer(); - - if (HostAssembly is not null) - { - builder.Environment.ApplicationName = HostAssembly.GetName().Name ?? ""; - } - - ConfigureServices(builder.Services); - var app = builder.Build(); - ConfigureApp(app); - - // Build and start the IHost - await app.StartAsync(); - - Server = app.GetTestServer(); - // BrowserClient = new TestBrowserClient(Server.CreateHandler()); - HttpClient = Server.CreateClient(); - } - - public event Action OnConfigureServices = services => { }; - public event Action OnConfigure = app => { }; - - private void ConfigureServices(IServiceCollection services) - { - services.AddLogging(options => - { - options.SetMinimumLevel(LogLevel.Critical); - options.AddProvider(Logger); - }); - - OnConfigureServices(services); - } - - private void ConfigureApp(WebApplication app) - { - _appServices = app.Services; - - OnConfigure(app); - } -} diff --git a/identity-server/test/Configuration.IntegrationTests/TestFramework/MockClock.cs b/identity-server/test/Configuration.IntegrationTests/TestFramework/MockClock.cs deleted file mode 100644 index d403a0add..000000000 --- a/identity-server/test/Configuration.IntegrationTests/TestFramework/MockClock.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// See LICENSE in the project root for license information. - - -using Duende.IdentityServer; - -namespace IntegrationTests.TestFramework; - -public class MockClock : IClock -{ - public DateTimeOffset UtcNow { get; set; } -} diff --git a/identity-server/test/Configuration.IntegrationTests/TestFramework/TestLoggerProvider.cs b/identity-server/test/Configuration.IntegrationTests/TestFramework/TestLoggerProvider.cs deleted file mode 100644 index bb003c8d4..000000000 --- a/identity-server/test/Configuration.IntegrationTests/TestFramework/TestLoggerProvider.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// See LICENSE in the project root for license information. - - -using Microsoft.Extensions.Logging; - -namespace IntegrationTests.TestFramework; - -public class TestLoggerProvider : ILoggerProvider -{ - public class DebugLogger : ILogger, IDisposable - { - private readonly TestLoggerProvider _parent; - private readonly string _category; - - public DebugLogger(TestLoggerProvider parent, string category) - { - _parent = parent; - _category = category; - } - - public void Dispose() - { - } - - public IDisposable BeginScope(TState state) -#if NET7_0_OR_GREATER - where TState : notnull => this; -#endif - - public bool IsEnabled(LogLevel logLevel) => true; - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) - { - var msg = $"[{logLevel}] {_category} : {formatter(state, exception)}"; - _parent.Log(msg); - } - } - - public List LogEntries = new List(); - - private void Log(string msg) => LogEntries.Add(msg); - - public ILogger CreateLogger(string categoryName) => new DebugLogger(this, categoryName); - - public void Dispose() - { - } -} diff --git a/identity-server/test/Configuration.IntegrationTests/TestFramework/MockCancellationTokenProvider.cs b/identity-server/test/IdentityServer.IntegrationTests/Common/MockCancellationTokenProvider.cs similarity index 85% rename from identity-server/test/Configuration.IntegrationTests/TestFramework/MockCancellationTokenProvider.cs rename to identity-server/test/IdentityServer.IntegrationTests/Common/MockCancellationTokenProvider.cs index 9784ca05a..71c1ca90e 100644 --- a/identity-server/test/Configuration.IntegrationTests/TestFramework/MockCancellationTokenProvider.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/Common/MockCancellationTokenProvider.cs @@ -4,7 +4,7 @@ using Duende.IdentityServer.Services; -namespace IntegrationTests.TestFramework; +namespace IdentityServer.IntegrationTests.Common; public class MockCancellationTokenProvider : ICancellationTokenProvider { diff --git a/identity-server/test/Configuration.IntegrationTests/DynamicClientRegistrationTests.cs b/identity-server/test/IdentityServer.IntegrationTests/Configuration/DynamicClientRegistrationTests.cs similarity index 100% rename from identity-server/test/Configuration.IntegrationTests/DynamicClientRegistrationTests.cs rename to identity-server/test/IdentityServer.IntegrationTests/Configuration/DynamicClientRegistrationTests.cs diff --git a/identity-server/test/Configuration.IntegrationTests/DynamicClientRegistrationValidationTests.cs b/identity-server/test/IdentityServer.IntegrationTests/Configuration/DynamicClientRegistrationValidationTests.cs similarity index 100% rename from identity-server/test/Configuration.IntegrationTests/DynamicClientRegistrationValidationTests.cs rename to identity-server/test/IdentityServer.IntegrationTests/Configuration/DynamicClientRegistrationValidationTests.cs diff --git a/identity-server/test/IdentityServer.IntegrationTests/IdentityServer.IntegrationTests.csproj b/identity-server/test/IdentityServer.IntegrationTests/IdentityServer.IntegrationTests.csproj index 7ed56cbbe..d5c0aef1d 100644 --- a/identity-server/test/IdentityServer.IntegrationTests/IdentityServer.IntegrationTests.csproj +++ b/identity-server/test/IdentityServer.IntegrationTests/IdentityServer.IntegrationTests.csproj @@ -44,6 +44,8 @@ + + diff --git a/identity-server/test/Configuration.IntegrationTests/TestHosts/ConfigurationHost.cs b/identity-server/test/IdentityServer.IntegrationTests/TestHosts/ConfigurationHost.cs similarity index 94% rename from identity-server/test/Configuration.IntegrationTests/TestHosts/ConfigurationHost.cs rename to identity-server/test/IdentityServer.IntegrationTests/TestHosts/ConfigurationHost.cs index e4c187084..b587c85a0 100644 --- a/identity-server/test/Configuration.IntegrationTests/TestHosts/ConfigurationHost.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/TestHosts/ConfigurationHost.cs @@ -6,8 +6,9 @@ using Duende.IdentityServer.Configuration; using Duende.IdentityServer.Configuration.EntityFramework; using Duende.IdentityServer.EntityFramework.Options; using Duende.IdentityServer.EntityFramework.Storage; +using Duende.IdentityServer.IntegrationTests.TestFramework; using Duende.IdentityServer.Services; -using IntegrationTests.TestFramework; +using IdentityServer.IntegrationTests.Common; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; diff --git a/identity-server/test/Configuration.IntegrationTests/TestHosts/ConfigurationIntegrationTestBase.cs b/identity-server/test/IdentityServer.IntegrationTests/TestHosts/ConfigurationIntegrationTestBase.cs similarity index 100% rename from identity-server/test/Configuration.IntegrationTests/TestHosts/ConfigurationIntegrationTestBase.cs rename to identity-server/test/IdentityServer.IntegrationTests/TestHosts/ConfigurationIntegrationTestBase.cs diff --git a/identity-server/test/Configuration.IntegrationTests/TestHosts/IdentityServerHost.cs b/identity-server/test/IdentityServer.IntegrationTests/TestHosts/IdentityServerHost.cs similarity index 92% rename from identity-server/test/Configuration.IntegrationTests/TestHosts/IdentityServerHost.cs rename to identity-server/test/IdentityServer.IntegrationTests/TestHosts/IdentityServerHost.cs index 92343718b..e2b77e320 100644 --- a/identity-server/test/Configuration.IntegrationTests/TestHosts/IdentityServerHost.cs +++ b/identity-server/test/IdentityServer.IntegrationTests/TestHosts/IdentityServerHost.cs @@ -5,8 +5,8 @@ using Duende.IdentityServer.EntityFramework.DbContexts; using Duende.IdentityServer.EntityFramework.Storage; using Duende.IdentityServer.EntityFramework.Stores; +using Duende.IdentityServer.IntegrationTests.TestFramework; using Duende.IdentityServer.Models; -using IntegrationTests.TestFramework; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; @@ -62,8 +62,7 @@ public class IdentityServerHost : GenericHost public async Task GetClientAsync(string clientId) { - var store = _appServices?.GetRequiredService() - ?? throw new Exception("Failed to resolve ClientStore in test"); + var store = Resolve(); return await store.FindClientByIdAsync(clientId); } } diff --git a/products.slnx b/products.slnx index c52f40b9c..879a10c30 100644 --- a/products.slnx +++ b/products.slnx @@ -158,7 +158,6 @@ -