Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# mergetool output
*.orig

# API Approvals
*.received.txt

# Build dependencies and artifacts
.dotnet/
.build/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/ServiceComposer/ServiceComposer.AspNetCore.Testing")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName=".NET 10.0")]
namespace ServiceComposer.AspNetCore.Testing
namespace ServiceComposer.AspNetCore.Testing
{
public class SelfContainedWebApplicationFactoryWithHost<TEntryPoint> : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TEntryPoint>
where TEntryPoint : class
Expand All @@ -17,14 +15,6 @@ namespace ServiceComposer.AspNetCore.Testing
public SelfContainedWebApplicationFactoryWithWebHost(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.DependencyInjection.IServiceCollection> configureServices, System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.AspNetCore.Builder.IApplicationBuilder> configure) { }
public System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> BuilderCustomization { get; set; }
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
protected override Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { }
}
public class WebApplicationFactoryWithWebHost<TStartup> : Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory<TStartup>
where TStartup : class
{
public WebApplicationFactoryWithWebHost() { }
public System.Action<Microsoft.AspNetCore.Hosting.IWebHostBuilder> BuilderCustomization { get; set; }
protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { }
protected override Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateWebHostBuilder() { }
protected override Microsoft.Extensions.Hosting.IHostBuilder CreateHostBuilder() { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

namespace ServiceComposer.AspNetCore.Testing.Tests;

public class PublicApiApprovalTests
public class ApiApprovals
{
[Fact]
public Task Public_api_is_approved()
public Task Approve_API()
{
var publicApi = ApiGenerator.GeneratePublicApi(typeof(WebApplicationFactoryWithWebHost<>).Assembly);
var publicApi = typeof(SelfContainedWebApplicationFactoryWithHost<>).Assembly.GeneratePublicApi(new ApiGeneratorOptions
{
ExcludeAttributes = ["System.Runtime.Versioning.TargetFrameworkAttribute", "System.Reflection.AssemblyMetadataAttribute"]
})
;
return Verifier.Verify(publicApi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ public async Task SelfContainedFactoryWithWebHost_invokes_builder_customization(
Assert.True(builderCustomizationCalled);
}

[Fact]
public async Task WebApplicationFactoryWithWebHost_invokes_builder_customization()
{
var builderCustomizationCalled = false;
await using var factory = new WebApplicationFactoryWithWebHost<Startup>
{
BuilderCustomization = _ => builderCustomizationCalled = true
};

var client = factory.CreateClient();
var response = await client.GetStringAsync("/");

Assert.Equal("startup", response);
Assert.True(builderCustomizationCalled);
}

class TestEntryPoint;

class Startup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;

namespace ServiceComposer.AspNetCore.Testing
Expand Down Expand Up @@ -30,45 +31,45 @@ public SelfContainedWebApplicationFactoryWithWebHost(Action<IServiceCollection>
_configureServices = configureServices;
_configure = configure;
}

public SelfContainedWebApplicationFactoryWithWebHost(Action<WebHostBuilderContext, IServiceCollection> configureServices, Action<WebHostBuilderContext, IApplicationBuilder> configure)
{
_configureServicesWithWebHostBuilderContext = configureServices;
_configureWithWebHostBuilderContext = configure;
}

protected override IWebHostBuilder CreateWebHostBuilder()
protected override IHostBuilder CreateHostBuilder()
{
var host = new WebHostBuilder().UseKestrel();

if (_configureServices != null)
{
host.ConfigureServices(_configureServices);
}
return Host.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureWebHostDefaults(webBuilder =>
{
if (_configureServices != null)
{
webBuilder.ConfigureServices(_configureServices);
}

if (_configureServicesWithWebHostBuilderContext != null)
{
host.ConfigureServices(_configureServicesWithWebHostBuilderContext);
}
if (_configureServicesWithWebHostBuilderContext != null)
{
webBuilder.ConfigureServices(_configureServicesWithWebHostBuilderContext);
}

if (_configure != null)
{
host.Configure(_configure);
}
if (_configure != null)
{
webBuilder.Configure(_configure);
}

if (_configureWithWebHostBuilderContext != null)
{
host.Configure(_configureWithWebHostBuilderContext);
}

return host;
if (_configureWithWebHostBuilderContext != null)
{
webBuilder.Configure(_configureWithWebHostBuilderContext);
}
});
}

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);

BuilderCustomization?.Invoke(builder);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -20,6 +20,10 @@
<NoWarn>$(NoWarn);NU5105</NoWarn>
</PropertyGroup>

<PropertyGroup>
<MinVerMinimumMajorMinor>4.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\assets\ServiceComposer.png" Pack="true" PackagePath="\" />
</ItemGroup>
Expand All @@ -28,15 +32,6 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[8.0.0, 9.0.0)" />
<PackageReference Include="System.Text.Json" Version="[8.0.5, 9.0.0)" Label="Dependencies not directly used but required to address security vulnerabilities" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[9.0.0, 10.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[10.0.0, 11.0.0)" />
</ItemGroup>
Expand Down

This file was deleted.