Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Xunit.DependencyInjection/Xunit.DependencyInjection.csproj
#	test/TestPackages.targets
  • Loading branch information
pengweiqhca committed Jan 20, 2025
2 parents e0c48e8 + 35dd964 commit 161d2fe
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions Xunit.DependencyInjection.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{25119119-1FAE-46DF-9722-9E1AA38586D7}"
ProjectSection(SolutionItems) = preProject
test\TestPackages.targets = test\TestPackages.targets
test\Directory.Build.props = test\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xunit.DependencyInjection.AspNetCoreTesting", "src\Xunit.DependencyInjection.AspNetCoreTesting\Xunit.DependencyInjection.AspNetCoreTesting.csproj", "{8E57DE30-9A8B-4501-9EB7-9DAC3A267FF2}"
Expand Down
8 changes: 4 additions & 4 deletions src/Xunit.DependencyInjection/HostManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ internal sealed class HostManager(Assembly assembly, IMessageSink diagnosticMess
private Type? _defaultStartupType;
private DependencyInjectionContext? _defaultHost;

public DependencyInjectionContext? BuildDefaultHost()
public DependencyInjectionContext BuildDefaultHost()
{
_defaultStartupType = StartupLoader.GetStartupType(assembly);

if (_defaultStartupType == null) return _defaultHost;

var value = StartupLoader.CreateHost(_defaultStartupType, assembly, diagnosticMessageSink);
var value = _defaultStartupType == null
? StartupLoader.CreateEmptyStartup(assembly.GetName(), diagnosticMessageSink)
: StartupLoader.CreateHost(_defaultStartupType, assembly, diagnosticMessageSink);

_hosts.Add(value.Host);

Expand Down
9 changes: 9 additions & 0 deletions src/Xunit.DependencyInjection/StartupLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ private static DependencyInjectionContext CreateHostWithHostApplicationBuilder(T
return new(host, startupType.GetCustomAttributesData().Any(a => a.AttributeType == typeof(DisableParallelizationAttribute)));
}

public static DependencyInjectionContext CreateEmptyStartup(AssemblyName assemblyName, IMessageSink diagnosticMessageSink)
{
var hostApplicationBuilder = Host.CreateEmptyApplicationBuilder(new() { ApplicationName = assemblyName.Name });

new DefaultServices(diagnosticMessageSink).ConfigureServices(hostApplicationBuilder.Services);

return new(hostApplicationBuilder.Build(), false);
}

private sealed class DefaultServices(IMessageSink diagnosticMessageSink)
{
public void ConfigureServices(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

Release notes:

10.1: Allow the default startup to be missing anywhere.
10.0: Upgrade xunit to v3.</Description>
<PackageTags>xunit ioc di DependencyInjection test</PackageTags>
<Version>10.0.1-preview.1</Version>
<Version>10.1.0</Version>
<PackageReleaseNotes>$(Description)</PackageReleaseNotes>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.RequiresLocationAttribute;System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute</PolySharpExcludeGeneratedTypes>
</PropertyGroup>
Expand Down
11 changes: 11 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>

<Import Project="..\Directory.Build.props" />

<PropertyGroup>
<IsPackable>false</IsPackable>
<RollForward>Major</RollForward>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

</Project>
6 changes: 0 additions & 6 deletions test/TestPackages.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project>

<PropertyGroup>
<IsPackable>false</IsPackable>
<RollForward>Major</RollForward>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="xunit.v3" Version="1.*" />
Expand Down
3 changes: 0 additions & 3 deletions test/Xunit.DependencyInjection.Analyzer.Test/Startup.cs

This file was deleted.

This file was deleted.

0 comments on commit 161d2fe

Please sign in to comment.