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
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
5 changes: 3 additions & 2 deletions 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 All @@ -21,7 +22,7 @@
<LangVersion>11.0</LangVersion>
<AccelerateBuildsInVisualStudio>false</AccelerateBuildsInVisualStudio>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>CA1014,NU5104,NETSDK1138</NoWarn>
<NoWarn>CA1014,NU5104,NETSDK1138,SYSLIB0051</NoWarn>
<CheckEolTargetFramework>false</CheckEolTargetFramework>

<!-- Used by code coverage -->
Expand All @@ -38,7 +39,7 @@
<PropertyGroup Label="Analyzer settings">
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisLevel>7</AnalysisLevel>
Comment thread
egil marked this conversation as resolved.
<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
}
}
24 changes: 23 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 @@ -96,7 +98,11 @@ public IRenderedComponentBase<TComponent> RenderComponent<TComponent>(ComponentP
EventArgs eventArgs) => DispatchEventAsync(eventHandlerId, fieldInfo, eventArgs, ignoreUnknownEventHandlers: false);

/// <inheritdoc/>
#if !NET8_0_OR_GREATER
public Task DispatchEventAsync(
#else
public new Task DispatchEventAsync(
#endif
ulong eventHandlerId,
EventFieldInfo fieldInfo,
EventArgs eventArgs,
Expand Down Expand Up @@ -188,6 +194,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 +224,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
3 changes: 3 additions & 0 deletions src/bunit.web/Asserting/JSInvokeCountExpectedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ private JSInvokeCountExpectedException(SerializationInfo serializationInfo, Stre
}

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info is null)
Expand Down
3 changes: 3 additions & 0 deletions src/bunit.web/Extensions/ElementNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ protected ElementNotFoundException(SerializationInfo serializationInfo, Streamin
}

/// <inheritdoc/>
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info is null)
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
7 changes: 4 additions & 3 deletions src/bunit.web/JSInterop/JSRuntimeInvocationDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ internal void RegisterInvocation(JSRuntimeInvocation invocation)
{
Count++;

if (!invocations.ContainsKey(invocation.Identifier))
if (!invocations.TryGetValue(invocation.Identifier, out var value))
{
invocations.Add(invocation.Identifier, new List<JSRuntimeInvocation>());
value = new List<JSRuntimeInvocation>();
invocations.Add(invocation.Identifier, value);
}

invocations[invocation.Identifier].Add(invocation);
value.Add(invocation);
}
}
2 changes: 1 addition & 1 deletion src/bunit.web/Rendering/RenderedComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void SetComponentAndID(RenderEvent renderEvent)
}
}

private bool TryFindComponent(RenderTreeFrameDictionary framesCollection, int parentComponentId, out int componentId, out TComponent component)
private static bool TryFindComponent(RenderTreeFrameDictionary framesCollection, int parentComponentId, out int componentId, out TComponent component)
{
componentId = -1;
component = default!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ IEnumerator IEnumerable.GetEnumerator()
/// <returns>An instance of <see cref="CapturedParameterView{TComponent}"/>.</returns>
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Following factory pattern used in .net")]
public static CapturedParameterView<TComponent> From(ParameterView parameters)
=> new(parameters.ToDictionary());
=> new(parameters.ToDictionary()!);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ private MissingMockStringLocalizationException(SerializationInfo serializationIn
Arguments = serializationInfo.GetValue(nameof(Arguments), Array.Empty<object?>().GetType()) as object?[] ?? Array.Empty<object?>();
}

/// <inheritdoc/>
/// <inheritdoc/>¨
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info is null)
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