Merge Config into main IntegrationTests project

This commit is contained in:
Joe DeCock 2025-09-03 18:27:07 -05:00
parent 5de380ca31
commit 5e8b61c1cd
16 changed files with 8 additions and 213 deletions

View file

@ -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)

View file

@ -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

1
.gitignore vendored
View file

@ -217,7 +217,6 @@ src/IdentityServer4/host/identityserver.db
tempkey.jwk
keys
*.key
test/Configuration.IntegrationTests/CoverageReports
nCrunchTemp_*
playwright-traces

View file

@ -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",

View file

@ -1,26 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Configuration\Duende.IdentityServer.Configuration.csproj" />
<ProjectReference
Include="..\..\src\Configuration.EntityFramework\Duende.IdentityServer.Configuration.EntityFramework.csproj" />
<ProjectReference Include="..\..\src\IdentityServer\Duende.IdentityServer.csproj" />
<ProjectReference
Include="..\..\src\EntityFramework.Storage\Duende.IdentityServer.EntityFramework.Storage.csproj" />
<ProjectReference Include="..\..\src\Storage\Duende.IdentityServer.Storage.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="AngleSharp" />
</ItemGroup>
</Project>

View file

@ -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<T>()
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<IServiceScopeFactory>().CreateScope().ServiceProvider.GetRequiredService<T>();
}
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<IServiceCollection> OnConfigureServices = services => { };
public event Action<WebApplication> 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);
}
}

View file

@ -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; }
}

View file

@ -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>(TState state)
#if NET7_0_OR_GREATER
where TState : notnull => this;
#endif
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
var msg = $"[{logLevel}] {_category} : {formatter(state, exception)}";
_parent.Log(msg);
}
}
public List<string> LogEntries = new List<string>();
private void Log(string msg) => LogEntries.Add(msg);
public ILogger CreateLogger(string categoryName) => new DebugLogger(this, categoryName);
public void Dispose()
{
}
}

View file

@ -4,7 +4,7 @@
using Duende.IdentityServer.Services;
namespace IntegrationTests.TestFramework;
namespace IdentityServer.IntegrationTests.Common;
public class MockCancellationTokenProvider : ICancellationTokenProvider
{

View file

@ -44,6 +44,8 @@
<ItemGroup>
<ProjectReference Include="..\..\..\shared\ShouldlyExtensions\ShouldlyExtensions.csproj" />
<ProjectReference Include="..\..\src\Configuration\Duende.IdentityServer.Configuration.csproj" />
<ProjectReference Include="..\..\src\Configuration.EntityFramework\Duende.IdentityServer.Configuration.EntityFramework.csproj" />
<ProjectReference Include="..\..\src\EntityFramework\Duende.IdentityServer.EntityFramework.csproj" />
<ProjectReference Include="..\..\src\IdentityServer\Duende.IdentityServer.csproj" />
</ItemGroup>

View file

@ -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;

View file

@ -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<Client> GetClientAsync(string clientId)
{
var store = _appServices?.GetRequiredService<ClientStore>()
?? throw new Exception("Failed to resolve ClientStore in test");
var store = Resolve<ClientStore>();
return await store.FindClientByIdAsync(clientId);
}
}

View file

@ -158,7 +158,6 @@
<Project Path="identity-server/templates/src/WebApp/TemplateWebApp.csproj" />
</Folder>
<Folder Name="/identity-server/test/">
<Project Path="identity-server/test/Configuration.IntegrationTests/Configuration.IntegrationTests.csproj" />
<Project Path="identity-server/test/EntityFramework.Storage.UnitTests/EntityFramework.Storage.UnitTests.csproj" />
<Project Path="identity-server/test/IdentityServer.IntegrationTests/IdentityServer.IntegrationTests.csproj" />
<Project Path="identity-server/test/IdentityServer.UnitTests/IdentityServer.UnitTests.csproj" />