Skip to content

Commit 9a31ca4

Browse files
Support only .NET 10 (#212)
* Not anymore needed * Remove .NET 8 and .NET 9 support * Remove stuff that doesn't exist anymore * Approved API * Remove dependency on the deprecated WebHostBuilder
1 parent 9e46d9e commit 9a31ca4

7 files changed

Lines changed: 42 additions & 94 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# mergetool output
1010
*.orig
1111

12+
# API Approvals
13+
*.received.txt
14+
1215
# Build dependencies and artifacts
1316
.dotnet/
1417
.build/

src/ServiceComposer.AspNetCore.Testing.Tests/PublicApiApprovalTests.Public_api_is_approved.verified.txt renamed to src/ServiceComposer.AspNetCore.Testing.Tests/ApiApprovals.Approve_API.verified.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/ServiceComposer/ServiceComposer.AspNetCore.Testing")]
2-
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName=".NET 10.0")]
3-
namespace ServiceComposer.AspNetCore.Testing
1+
namespace ServiceComposer.AspNetCore.Testing
42
{
53
public class SelfContainedWebApplicationFactoryWithHost<TEntryPoint> : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>
64
where TEntryPoint : class
@@ -17,14 +15,6 @@ namespace ServiceComposer.AspNetCore.Testing
1715
public SelfContainedWebApplicationFactoryWithWebHost(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.DependencyInjection.IServiceCollection> configureServices, System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.AspNetCore.Builder.IApplicationBuilder> configure) { }
1816
public System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> BuilderCustomization { get; set; }
1917
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
20-
protected override Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { }
21-
}
22-
public class WebApplicationFactoryWithWebHost<TStartup> : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TStartup>
23-
where TStartup : class
24-
{
25-
public WebApplicationFactoryWithWebHost() { }
26-
public System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> BuilderCustomization { get; set; }
27-
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
28-
protected override Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { }
18+
protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { }
2919
}
3020
}

src/ServiceComposer.AspNetCore.Testing.Tests/PublicApiApprovalTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
namespace ServiceComposer.AspNetCore.Testing.Tests;
55

6-
public class PublicApiApprovalTests
6+
public class ApiApprovals
77
{
88
[Fact]
9-
public Task Public_api_is_approved()
9+
public Task Approve_API()
1010
{
11-
var publicApi = ApiGenerator.GeneratePublicApi(typeof(WebApplicationFactoryWithWebHost<>).Assembly);
11+
var publicApi = typeof(SelfContainedWebApplicationFactoryWithHost<>).Assembly.GeneratePublicApi(new ApiGeneratorOptions
12+
{
13+
ExcludeAttributes = ["System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute"]
14+
})
15+
;
1216
return Verifier.Verify(publicApi);
1317
}
1418
}

src/ServiceComposer.AspNetCore.Testing.Tests/SelfContainedWebApplicationFactoryTests.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,6 @@ public async Task SelfContainedFactoryWithWebHost_invokes_builder_customization(
4646
Assert.True(builderCustomizationCalled);
4747
}
4848

49-
[Fact]
50-
public async Task WebApplicationFactoryWithWebHost_invokes_builder_customization()
51-
{
52-
var builderCustomizationCalled = false;
53-
await using var factory = new WebApplicationFactoryWithWebHost<Startup>
54-
{
55-
BuilderCustomization = _ => builderCustomizationCalled = true
56-
};
57-
58-
var client = factory.CreateClient();
59-
var response = await client.GetStringAsync("/");
60-
61-
Assert.Equal("startup", response);
62-
Assert.True(builderCustomizationCalled);
63-
}
64-
6549
class TestEntryPoint;
6650

6751
class Startup

src/ServiceComposer.AspNetCore.Testing/SelfContainedWebApplicationFactoryWithWebHost.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.AspNetCore.Mvc.Testing;
44
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
56
using System;
67

78
namespace ServiceComposer.AspNetCore.Testing
@@ -30,45 +31,45 @@ public SelfContainedWebApplicationFactoryWithWebHost(Action<IServiceCollection>
3031
_configureServices = configureServices;
3132
_configure = configure;
3233
}
33-
34+
3435
public SelfContainedWebApplicationFactoryWithWebHost(Action<WebHostBuilderContext, IServiceCollection> configureServices, Action<WebHostBuilderContext, IApplicationBuilder> configure)
3536
{
3637
_configureServicesWithWebHostBuilderContext = configureServices;
3738
_configureWithWebHostBuilderContext = configure;
3839
}
3940

40-
protected override IWebHostBuilder CreateWebHostBuilder()
41+
protected override IHostBuilder CreateHostBuilder()
4142
{
42-
var host = new WebHostBuilder().UseKestrel();
43-
44-
if (_configureServices != null)
45-
{
46-
host.ConfigureServices(_configureServices);
47-
}
43+
return Host.CreateDefaultBuilder(Array.Empty<string>())
44+
.ConfigureWebHostDefaults(webBuilder =>
45+
{
46+
if (_configureServices != null)
47+
{
48+
webBuilder.ConfigureServices(_configureServices);
49+
}
4850

49-
if (_configureServicesWithWebHostBuilderContext != null)
50-
{
51-
host.ConfigureServices(_configureServicesWithWebHostBuilderContext);
52-
}
51+
if (_configureServicesWithWebHostBuilderContext != null)
52+
{
53+
webBuilder.ConfigureServices(_configureServicesWithWebHostBuilderContext);
54+
}
5355

54-
if (_configure != null)
55-
{
56-
host.Configure(_configure);
57-
}
56+
if (_configure != null)
57+
{
58+
webBuilder.Configure(_configure);
59+
}
5860

59-
if (_configureWithWebHostBuilderContext != null)
60-
{
61-
host.Configure(_configureWithWebHostBuilderContext);
62-
}
63-
64-
return host;
61+
if (_configureWithWebHostBuilderContext != null)
62+
{
63+
webBuilder.Configure(_configureWithWebHostBuilderContext);
64+
}
65+
});
6566
}
6667

6768
protected override void ConfigureWebHost(IWebHostBuilder builder)
6869
{
6970
base.ConfigureWebHost(builder);
70-
71+
7172
BuilderCustomization?.Invoke(builder);
7273
}
7374
}
74-
}
75+
}

src/ServiceComposer.AspNetCore.Testing/ServiceComposer.AspNetCore.Testing.csproj

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
4+
<TargetFramework>net10.0</TargetFramework>
55
</PropertyGroup>
66

77
<PropertyGroup>
@@ -20,6 +20,10 @@
2020
<NoWarn>$(NoWarn);NU5105</NoWarn>
2121
</PropertyGroup>
2222

23+
<PropertyGroup>
24+
<MinVerMinimumMajorMinor>4.0</MinVerMinimumMajorMinor>
25+
</PropertyGroup>
26+
2327
<ItemGroup>
2428
<None Include="..\..\assets\ServiceComposer.png" Pack="true" PackagePath="\" />
2529
</ItemGroup>
@@ -28,15 +32,6 @@
2832
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2933
</ItemGroup>
3034

31-
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
32-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[8.0.0, 9.0.0)" />
33-
<PackageReference Include="System.Text.Json" Version="[8.0.5, 9.0.0)" Label="Dependencies not directly used but required to address security vulnerabilities" />
34-
</ItemGroup>
35-
36-
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
37-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[9.0.0, 10.0.0)" />
38-
</ItemGroup>
39-
4035
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
4136
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[10.0.0, 11.0.0)" />
4237
</ItemGroup>

src/ServiceComposer.AspNetCore.Testing/WebApplicationFactoryWithWebHost.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)