Skip to content

Commit

Permalink
feat: Add support for net8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jul 31, 2023
1 parent e654d6d commit d3fb171
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: 🎨 Setup color
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: 🎨 Setup color
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: 🛠️ Update changelog
uses: thomaseizinger/keep-a-changelog-new-release@1.3.0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: 🎨 Setup color
if: matrix.os != 'windows-latest'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]


### Added

- `net8.0` support

## [1.22.19] - 2023-07-28

### Added
Expand Down
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<DotNet5Version>5.0.0</DotNet5Version>
<DotNet6Version>6.0.0</DotNet6Version>
<DotNet7Version>7.0.0</DotNet7Version>
<DotNet8Version>8.0.0-*</DotNet8Version>
</PropertyGroup>

<!-- Solution wide properties -->
Expand Down Expand Up @@ -38,7 +39,7 @@
<PropertyGroup Label="Analyzer settings">
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisLevel>7</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestMajor",
"allowPrerelease": false
"allowPrerelease": true
}
}
20 changes: 19 additions & 1 deletion src/bunit.core/Rendering/TestRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class TestRenderer : Renderer, ITestRenderer
{
private static readonly Type RendererType = typeof(Renderer);
private static readonly FieldInfo IsBatchInProgressField = RendererType.GetField("_isBatchInProgress", BindingFlags.Instance | BindingFlags.NonPublic)!;
#if !NET8_0_OR_GREATER
private static readonly MethodInfo GetRequiredComponentStateMethod = RendererType.GetMethod("GetRequiredComponentState", BindingFlags.Instance | BindingFlags.NonPublic)!;
#endif

private readonly object renderTreeUpdateLock = new();
private readonly Dictionary<int, IRenderedFragmentBase> renderedComponents = new();
Expand Down Expand Up @@ -188,6 +190,17 @@ public void DisposeComponents()
AssertNoUnhandledExceptions();
}
}

#if NET8_0_OR_GREATER
/// <inheritdoc/>
protected override IComponent ResolveComponentForRenderMode(Type componentType, int? parentComponentId,
IComponentActivator componentActivator, IComponentRenderMode renderMode)

{
ArgumentNullException.ThrowIfNull(componentActivator);
return componentActivator.CreateInstance(componentType);
}
#endif

/// <inheritdoc/>
internal void SetDirectParameters(IRenderedFragmentBase renderedComponent, ParameterView parameters)
Expand All @@ -207,9 +220,14 @@ internal void SetDirectParameters(IRenderedFragmentBase renderedComponent, Param
try
{
IsBatchInProgress = true;
#if NET8_0_OR_GREATER
var setDirectParametersMethod = typeof(ComponentState).GetMethod("SetDirectParameters", BindingFlags.NonPublic | BindingFlags.Instance)!;
var componentState = GetComponentState(renderedComponent.ComponentId);
#else
var componentState = GetRequiredComponentStateMethod.Invoke(this, new object[] { renderedComponent.ComponentId })!;
var setDirectParametersMethod = componentState.GetType().GetMethod("SetDirectParameters", BindingFlags.Public | BindingFlags.Instance)!;
#endif
setDirectParametersMethod.Invoke(componentState, new object[] { parameters });
}
catch (TargetInvocationException ex) when (ex.InnerException is not null)
Expand Down
8 changes: 7 additions & 1 deletion src/bunit.core/bunit.core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Core</AssemblyName>
</PropertyGroup>
Expand Down Expand Up @@ -38,4 +38,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components" Version="$(DotNet7Version)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="$(DotNet8Version)" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions src/bunit.web.testcomponents/bunit.web.testcomponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<PackageReference Include="System.Reflection.Metadata" Version="$(DotNet5Version)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Reflection.Metadata" Version="$(DotNet6Version)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\bunit.web\bunit.web.csproj" />
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/bunit.web/Extensions/TestServiceProviderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static IServiceCollection AddDefaultTestContextServices(this IServiceColl
services.AddSingleton<FakeWebAssemblyHostEnvironment>();
services.AddSingleton<IWebAssemblyHostEnvironment>(s => s.GetRequiredService<FakeWebAssemblyHostEnvironment>());

#if NET8_0_OR_GREATER
// bUnits fake ScrollToLocationHash
services.AddSingleton<IScrollToLocationHash, BunitScrollToLocationHash>();
#endif

// bUnit specific services
services.AddSingleton<TestContextBase>(testContext);
services.AddSingleton<WebTestRenderer>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#if NET8_0_OR_GREATER
using Microsoft.AspNetCore.Components.Routing;

namespace Bunit.TestDoubles;

internal sealed class BunitScrollToLocationHash : IScrollToLocationHash
{
public Task RefreshScrollPositionForHash(string locationAbsolute) => Task.CompletedTask;
}
#endif
15 changes: 12 additions & 3 deletions src/bunit.web/bunit.web.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Web</AssemblyName>
</PropertyGroup>
Expand Down Expand Up @@ -55,6 +55,15 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(DotNet7Version)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(DotNet8Version)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AngleSharpWrappers\AngleSharpWrappers.csproj" PrivateAssets="All" />
<ProjectReference Include="..\bunit.core\bunit.core.csproj" />
Expand All @@ -68,15 +77,15 @@
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')-&gt;WithMetadataValue('PrivateAssets', 'All'))" />
</ItemGroup>

<!-- Print batches for debug purposes -->
<Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" />

<ItemGroup>
<!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/>
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)" />
</ItemGroup>
</Target>

Expand Down
2 changes: 1 addition & 1 deletion src/bunit/bunit.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<NoBuild>true</NoBuild>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeSymbols>false</IncludeSymbols>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>AngleSharpWrappers</RootNamespace>
<AssemblyName>AngleSharpWrappers.Tests</AssemblyName>
</PropertyGroup>
Expand Down
21 changes: 21 additions & 0 deletions tests/bunit.core.tests/Rendering/TestRendererTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,16 @@ public void Test208()
cut.Instance.AfterRenderCount.ShouldBe(2);
cut.Instance.AfterRenderAsyncCount.ShouldBe(2);
}

#if NET8_0_OR_GREATER
[Fact(DisplayName = "Can render components that have a RenderMode attribute")]
public void Test209()
{
var cut = RenderComponent<RenderModeServerComponent>();

cut.Find("h3").TextContent.ShouldBe("Hello from Server");
}
#endif

internal sealed class LifeCycleMethodInvokeCounter : ComponentBase
{
Expand Down Expand Up @@ -622,4 +632,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
throw new InvalidOperationException();
}
}

#if NET8_0_OR_GREATER
[RenderModeServer]
private sealed class RenderModeServerComponent : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.AddMarkupContent(0, "<h3>Hello from Server</h3>");
}
}
#endif
}
2 changes: 1 addition & 1 deletion tests/bunit.core.tests/bunit.core.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Core.Tests</AssemblyName>
</PropertyGroup>
Expand Down
8 changes: 7 additions & 1 deletion tests/bunit.testassets/bunit.testassets.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>Bunit.TestAssets</RootNamespace>
<AssemblyName>Bunit.TestAssets</AssemblyName>
<OutputType>Library</OutputType>
Expand Down Expand Up @@ -42,5 +42,11 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(DotNet7Version)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(DotNet8Version)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(DotNet8Version)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion tests/bunit.web.tests/bunit.web.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Web.Tests</AssemblyName>
</PropertyGroup>
Expand Down

0 comments on commit d3fb171

Please sign in to comment.