diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a52b66ad..cd53d67a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - v3 paths: - 'src/**' - 'tests/**' @@ -44,8 +45,6 @@ jobs: uses: actions/setup-dotnet@v6 with: dotnet-version: | - 8.0.x - 9.0.x 10.0.x 11.0.x @@ -126,8 +125,6 @@ jobs: uses: actions/setup-dotnet@v6 with: dotnet-version: | - 8.0.x - 9.0.x 10.0.x 11.0.x @@ -225,8 +222,6 @@ jobs: uses: actions/setup-dotnet@v6 with: dotnet-version: | - 8.0.x - 9.0.x 10.0.x 11.0.x @@ -256,7 +251,7 @@ jobs: - name: 🧪 Run sample unit tests working-directory: docs/samples - run: dotnet test samples.sln -p:VSTestUseMSBuildOutput=false -f net8.0 + run: dotnet test samples.sln -p:VSTestUseMSBuildOutput=false -f net10.0 - name: 📄 Build docs working-directory: ./docs/site diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 35f3bbdfe..7b9be3aa8 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -73,8 +73,6 @@ jobs: uses: actions/setup-dotnet@v6 with: dotnet-version: | - 8.0.x - 9.0.x 10.0.x 11.0.x diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6284e036..72d934d0a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -63,8 +63,6 @@ jobs: uses: actions/setup-dotnet@v6 with: dotnet-version: | - 8.0.x - 9.0.x 10.0.x 11.0.x diff --git a/Directory.Packages.props b/Directory.Packages.props index 93b2ce6d4..8de7acf21 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -26,36 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.md b/README.md index 4208f1d12..fda024d9f 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ To get started, head to the [getting started documentation](https://bunit.dev/do | bUnit version | .NET version | | ------------- | ------------------------------- | | 1.x | ≥ .netcore3.1 && ≤ .net 9 | -| 2.x | ≥ .net8 | +| 2.x | ≥ .net8 && ≤ .net 11 | +| 3.x | ≥ .net10 | For a migration guide, see [Upgrading bUnit](https://bunit.dev/docs/migrations/index.html). diff --git a/docs/samples/components/bunit.docs.samples.csproj b/docs/samples/components/bunit.docs.samples.csproj index 88949209f..9e1e852d7 100644 --- a/docs/samples/components/bunit.docs.samples.csproj +++ b/docs/samples/components/bunit.docs.samples.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit.Docs.Samples enable CA1014,NU5104 diff --git a/docs/samples/tests/Directory.Build.props b/docs/samples/tests/Directory.Build.props index 8071ce9d1..9a5722898 100644 --- a/docs/samples/tests/Directory.Build.props +++ b/docs/samples/tests/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 false true false diff --git a/docs/site/docs/extensions/bunit-generators.md b/docs/site/docs/extensions/bunit-generators.md index c9c072908..74d9b3f97 100644 --- a/docs/site/docs/extensions/bunit-generators.md +++ b/docs/site/docs/extensions/bunit-generators.md @@ -53,12 +53,12 @@ To use the generator, the **Interceptor** feature has to be used inside the cspr ```xml - net8.0 + net10.0 $(InterceptorsPreviewNamespaces);Bunit ``` -Due to the usage of **Interceptors** the generator is only available for .NET 8.0 and above. The generator does create a `partial` class, so it can be extended with custom logic if needed. +Due to the usage of **Interceptors** the generator requires .NET 10.0 and above, matching bUnit's minimum supported target framework. The generator does create a `partial` class, so it can be extended with custom logic if needed. ## Component stub generator via `ComponentStubAttribute` diff --git a/docs/site/docs/getting-started/create-test-project.md b/docs/site/docs/getting-started/create-test-project.md index a3b526ada..f1b9c558a 100644 --- a/docs/site/docs/getting-started/create-test-project.md +++ b/docs/site/docs/getting-started/create-test-project.md @@ -148,10 +148,10 @@ dotnet add package bunit --version #{NBGV_NuGetPackageVersion}# The test projects setting needs to be set to the following: - the project's SDK needs to be set to `Microsoft.NET.Sdk.Razor` (this does not work with **TUnit** - a more detailed explanation can be found below) -- set the `` to `net8.0` +- set the `` to `net10.0` > [!NOTE] -> bUnit works with `net8.0` and above as well. +> bUnit works with `net10.0` and above as well. To do so, change the first part of the test projects `.csproj` file to look like this.: @@ -159,7 +159,7 @@ To do so, change the first part of the test projects `.csproj` file to look like - net8.0 + net10.0 ... @@ -182,7 +182,7 @@ The result should be a test project with a `.csproj` that looks like this (non b - net8.0 + net10.0 enable false @@ -211,7 +211,7 @@ The result should be a test project with a `.csproj` that looks like this (non b - net8.0 + net10.0 enable false Exe @@ -241,7 +241,7 @@ The result should be a test project with a `.csproj` that looks like this (non b - net8.0 + net10.0 enable false @@ -267,7 +267,7 @@ The result should be a test project with a `.csproj` that looks like this (non b - net8.0 + net10.0 enable false @@ -293,7 +293,7 @@ The result should be a test project with a `.csproj` that looks like this (non b - net8.0 + net10.0 enable false false diff --git a/docs/site/docs/interaction/render-modes.md b/docs/site/docs/interaction/render-modes.md index d019abba6..45ca1d70f 100644 --- a/docs/site/docs/interaction/render-modes.md +++ b/docs/site/docs/interaction/render-modes.md @@ -75,7 +75,7 @@ public void StaticRendering() # [Razor test code](#tab/razor) ```razor -@inherits TestContext +@inherits BunitContext @code { [Fact] public void InteractiveServer() @@ -108,7 +108,7 @@ public void StaticRendering() *** ## Setting the `RendererInfo` during testing -To control the `ComponentBase.RendererInfo` property during testing, use the method on the `TestContext` class. The `SetRendererInfo` method takes an nullable `RendererInfo` object as a parameter. Passing `null` will set the `ComponentBase.RendererInfo` to `null`. +To control the `ComponentBase.RendererInfo` property during testing, use the method on the `BunitContext` class. The `SetRendererInfo` method takes an nullable `RendererInfo` object as a parameter. Passing `null` will set the `ComponentBase.RendererInfo` to `null`. A component (`AssistentComponent.razor`) might check if interactivity is given to enable a button: @@ -154,4 +154,4 @@ public void SimulatingInteractiveServerRendering() ``` > [!NOTE] -> If a component under test uses the `ComponentBase.RendererInfo` property and the `SetRendererInfo` on `TestContext` hasn't been passed in a `RendererInfo` object, the renderer will throw an exception. \ No newline at end of file +> If a component under test uses the `ComponentBase.RendererInfo` property and the `SetRendererInfo` on `BunitContext` hasn't been passed in a `RendererInfo` object, the renderer will throw an exception. \ No newline at end of file diff --git a/docs/site/docs/migrations/2to3.md b/docs/site/docs/migrations/2to3.md new file mode 100644 index 000000000..0ee106ebe --- /dev/null +++ b/docs/site/docs/migrations/2to3.md @@ -0,0 +1,51 @@ +--- +uid: migrating-from-2-to-3 +title: Migrating from 2.x to 3.x +--- + +# Migrating from bUnit 2.x to 3.x +This document describes the changes made in bUnit 3.x that may affect existing tests written for bUnit 2.x. + +## Dropped support for .NET 8 and .NET 9 + +bUnit 3.x drops support for `net8.0` and `net9.0`. The minimum supported target framework is now `net10.0`, and `net11.0` is also supported. + +To migrate, update your test project's `` (or ``) to `net10.0` or later: + +```diff +- net8.0 ++ net10.0 +``` + +## Removed obsolete and deprecated APIs + +bUnit 3.x removes APIs that were kept around for backwards compatibility with bUnit 1.x and were marked `[Obsolete]` or scheduled for removal: + +- `TestContext` class: use `BunitContext` instead. +- `RenderComponent()` and `RenderComponent(Action>?)`: use `Render()` instead. +- `BunitSignOutSessionStateManager`: this was a test double for the obsolete `SignOutSessionStateManager` from `Microsoft.AspNetCore.Components.WebAssembly.Authentication` and has been removed. `AddAuthorization()` no longer registers it in the service collection. + +## `BunitContext.DefaultWaitTimeout` is no longer static + +`BunitContext.DefaultWaitTimeout` used to be a `static` property, so setting it in one test affected the timeout used by every other test running in the same process, including tests running concurrently. It is now an instance property, so each `BunitContext` (and each test class deriving from it) has its own timeout, used by both `WaitForXXX` helpers and its own `JSInterop`. + +To migrate, set the timeout on the test's `BunitContext` instance instead of the static property. If every test in a class needs a longer timeout, the constructor is a good place to set it once: + +```diff + public class MyComponentTest : BunitContext + { ++ public MyComponentTest() ++ { ++ DefaultWaitTimeout = TimeSpan.FromSeconds(10); ++ } + + [Fact] + public void MyTest() + { +- BunitContext.DefaultWaitTimeout = TimeSpan.FromSeconds(10); + // ... + } + } +``` + +Setting it on a specific `BunitContext` instance (rather than a class deriving from it) works the same way: `context.DefaultWaitTimeout = TimeSpan.FromSeconds(10);`. \ No newline at end of file diff --git a/docs/site/docs/migrations/index.md b/docs/site/docs/migrations/index.md index 35f8abeae..4969e3e43 100644 --- a/docs/site/docs/migrations/index.md +++ b/docs/site/docs/migrations/index.md @@ -7,4 +7,5 @@ title: Migrations This section covers the migration across major versions of bUnit. The mirations themselves also list the link to the old version of the documentation (including the old API documentation). + - - \ No newline at end of file diff --git a/docs/site/docs/providing-input/seeding-assets.md b/docs/site/docs/providing-input/seeding-assets.md index af523698a..d821c04a8 100644 --- a/docs/site/docs/providing-input/seeding-assets.md +++ b/docs/site/docs/providing-input/seeding-assets.md @@ -5,7 +5,7 @@ title: Seeding static assets (Assets) # Seeding static assets (`Assets`) -This article explains how to seed the `Assets` property of components under test in bUnit. This is supported for .NET 9 and later. +This article explains how to seed the `Assets` property of components under test in bUnit. Since .NET 9, components can access static assets mapped by [`MapStaticAssets`](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/map-static-files?view=aspnetcore-9.0) through the [`ComponentBase.Assets`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.componentbase.assets?view=aspnetcore-9.0) property, e.g. to resolve fingerprinted URLs: diff --git a/docs/site/docs/toc.md b/docs/site/docs/toc.md index 53fe7e811..982f84898 100644 --- a/docs/site/docs/toc.md +++ b/docs/site/docs/toc.md @@ -37,6 +37,7 @@ ## [bunit.generators](xref:bunit-generators) # [Migrations](xref:migrations) +## [2.x to 3.x](xref:migrating-from-2-to-3) ## [1.x to 2.x](xref:migrating-from-1-to-2) # [Miscellaneous testing tips](xref:misc-test-tips) diff --git a/src/bunit.generators.internal/README.md b/src/bunit.generators.internal/README.md index 76af51e46..3031defd9 100644 --- a/src/bunit.generators.internal/README.md +++ b/src/bunit.generators.internal/README.md @@ -9,5 +9,5 @@ dotnet build-server shutdown A good way to quickly see if the generate is producing output: ``` -dotnet build-server shutdown && dotnet clean && dotnet test -p:TargetFramework=net8.0 +dotnet build-server shutdown && dotnet clean && dotnet test -p:TargetFramework=net10.0 ``` diff --git a/src/bunit.generators/README.md b/src/bunit.generators/README.md index 5211e1bfd..b852bfa0f 100644 --- a/src/bunit.generators/README.md +++ b/src/bunit.generators/README.md @@ -45,12 +45,12 @@ To use the generator, the **Interceptor** feature has to be used inside the cspr ```xml - net8.0 + net10.0 $(InterceptorsPreviewNamespaces);Bunit ``` -This limits the usage to .NET 8 and above. +This limits the usage to .NET 10 and above, matching bUnit's minimum supported target framework. ## `ComponentStubAttribute` This generator adds the ability to automatically generate stubs for a given type via an attribute. diff --git a/src/bunit.template/template/.template.config/dotnetcli.host.json b/src/bunit.template/template/.template.config/dotnetcli.host.json index ced81d900..d51839f87 100644 --- a/src/bunit.template/template/.template.config/dotnetcli.host.json +++ b/src/bunit.template/template/.template.config/dotnetcli.host.json @@ -14,9 +14,9 @@ } }, "usageExamples": [ - "--framework xunit --sdk net8.0", - "--framework xunitv3 --sdk net8.0", - "--framework nunit --sdk net8.0", - "--framework mstest --sdk net8.0" + "--framework xunit --sdk net10.0", + "--framework xunitv3 --sdk net10.0", + "--framework nunit --sdk net10.0", + "--framework mstest --sdk net10.0" ] } diff --git a/src/bunit.template/template/.template.config/template.json b/src/bunit.template/template/.template.config/template.json index 90eab74ea..27b894907 100644 --- a/src/bunit.template/template/.template.config/template.json +++ b/src/bunit.template/template/.template.config/template.json @@ -94,16 +94,6 @@ "defaultValue": "net10.0", "replaces": "targetSdk", "choices": [ - { - "choice": "net8.0", - "description": ".net 8.0", - "displayName": ".net 8.0" - }, - { - "choice": "net9.0", - "description": ".net 9.0", - "displayName": ".net 9.0" - }, { "choice": "net10.0", "description": ".net 10.0", diff --git a/src/bunit.template/template/CounterCSharpTest.cs b/src/bunit.template/template/CounterCSharpTest.cs index fd7c78040..a9c7b4835 100644 --- a/src/bunit.template/template/CounterCSharpTest.cs +++ b/src/bunit.template/template/CounterCSharpTest.cs @@ -7,7 +7,6 @@ namespace Company.BlazorTests1; #if (testFramework_xunit) public class CounterCSharpTest : BunitContext #elif (testFramework_xunitv3) -// The full qualified namespace for bUnit TestContext is used here as xunit v3 also offers a TestContext class public class CounterCSharpTest : BunitContext #elif (testFramework_nunit) public class CounterCSharpTest : BunitContext diff --git a/src/bunit.template/template/CounterRazorTests.razor b/src/bunit.template/template/CounterRazorTests.razor index 8b02e77ce..2126a27e2 100644 --- a/src/bunit.template/template/CounterRazorTests.razor +++ b/src/bunit.template/template/CounterRazorTests.razor @@ -1,7 +1,6 @@ @*#if (testFramework_xunit) *@ @inherits BunitContext @*#elif (testFramework_xunitv3)*@ -@* The full qualified namespace for bUnit TestContext is used here as xunit v3 also offers a TestContext class *@ @inherits BunitContext @*#elif (testFramework_nunit)*@ @inherits BunitContext diff --git a/src/bunit.web.query/bunit.web.query.csproj b/src/bunit.web.query/bunit.web.query.csproj index c0e9bc642..2a5d108a0 100644 --- a/src/bunit.web.query/bunit.web.query.csproj +++ b/src/bunit.web.query/bunit.web.query.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit Bunit.Web.Query diff --git a/src/bunit/BunitContext.Obsoletes.cs b/src/bunit/BunitContext.Obsoletes.cs deleted file mode 100644 index 121e95636..000000000 --- a/src/bunit/BunitContext.Obsoletes.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Bunit; - -public partial class BunitContext -{ - /// - /// Use instead. - /// - [Obsolete($"Use {nameof(Render)} instead.", true, UrlFormat = "https://bunit.dev/docs/migrations")] - public IRenderedComponent RenderComponent() - where TComponent : IComponent - { - throw new NotSupportedException($"Use {nameof(Render)}<{typeof(TComponent).Name}> instead."); - } - - /// - /// Use instead. - /// - [Obsolete($"Use {nameof(Render)} instead.", true, UrlFormat = "https://bunit.dev/docs/migrations")] - public IRenderedComponent RenderComponent(Action>? parameterBuilder) - where TComponent : IComponent - { - throw new NotSupportedException($"Use {nameof(Render)}<{typeof(TComponent).Name}> instead."); - } -} diff --git a/src/bunit/BunitContext.cs b/src/bunit/BunitContext.cs index 6783f63c8..5671287f1 100644 --- a/src/bunit/BunitContext.cs +++ b/src/bunit/BunitContext.cs @@ -1,6 +1,4 @@ -#if NET9_0_OR_GREATER using System.Runtime.CompilerServices; -#endif using Bunit.Extensions; using Bunit.Rendering; using Microsoft.Extensions.Logging; @@ -16,11 +14,10 @@ public partial class BunitContext : IDisposable, IAsyncDisposable private BunitRenderer? bunitRenderer; /// - /// Gets or sets the default wait timeout used by "WaitFor" operations, i.e. , - /// and JSInterop invocation handlers that have not been configured with results. + /// Gets or sets the default wait timeout used by "WaitFor" operations and JSInterop invocation + /// handlers that have not been configured with results. Default is 1 second. /// - /// The default is 1 second. - public static TimeSpan DefaultWaitTimeout { get; set; } = TimeSpan.FromSeconds(1); + public TimeSpan DefaultWaitTimeout { get; set; } = TimeSpan.FromSeconds(1); /// /// Gets the renderer used by the test context. @@ -65,6 +62,7 @@ public BunitContext() Services = new BunitServiceProvider(); Services.AddSingleton(_ => ComponentFactories); Services.AddDefaultBunitContextServices(this, JSInterop); + JSInterop.AttachToContext(this); } /// @@ -161,9 +159,7 @@ public virtual IRenderedComponent Render(ActionThe type of component to find in the render tree. /// The render fragment to render. /// The . -#if NET9_0_OR_GREATER [OverloadResolutionPriority(1)] -#endif public virtual IRenderedComponent Render(RenderFragment renderFragment) where TComponent : IComponent => RenderInsideRenderTree(renderFragment); @@ -176,7 +172,6 @@ public virtual IRenderedComponent Render(RenderFragment public virtual IRenderedComponent Render(RenderFragment renderFragment) => RenderInsideRenderTree(renderFragment); -#if NET9_0_OR_GREATER /// /// Sets the for the renderer. /// @@ -201,7 +196,6 @@ public void SetRendererInfo(RendererInfo? rendererInfo) [SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with ResourceAsset")] public void AddAsset(string url, string? label = null, params ResourceAssetProperty[] properties) => Renderer.AddAsset(url, label, properties); -#endif /// /// Dummy method required to allow Blazor's compiler to generate diff --git a/src/bunit/ComponentParameterCollection.cs b/src/bunit/ComponentParameterCollection.cs index bae0ece4e..43bb31f68 100644 --- a/src/bunit/ComponentParameterCollection.cs +++ b/src/bunit/ComponentParameterCollection.cs @@ -19,13 +19,11 @@ internal class ComponentParameterCollection : ICollection, I /// public bool IsReadOnly => false; -#if NET9_0_OR_GREATER /// /// Gets or sets the that will be specified in /// the render tree for component the parameters are being passed to. /// public IComponentRenderMode? RenderMode { get; set; } -#endif /// /// Adds a to the collection. @@ -108,9 +106,7 @@ void AddComponent(RenderTreeBuilder builder) { builder.OpenComponent(0); AddAttributes(builder); -#if NET9_0_OR_GREATER builder.AddComponentRenderMode(RenderMode); -#endif builder.CloseComponent(); } diff --git a/src/bunit/ComponentParameterCollectionBuilder.cs b/src/bunit/ComponentParameterCollectionBuilder.cs index 10ff1e4bc..e623aaa82 100644 --- a/src/bunit/ComponentParameterCollectionBuilder.cs +++ b/src/bunit/ComponentParameterCollectionBuilder.cs @@ -427,7 +427,6 @@ static string TrimEnd(string source, string value) : source; } -#if NET9_0_OR_GREATER /// /// Sets (or unsets) the for the component and child components. /// @@ -438,7 +437,6 @@ public ComponentParameterCollectionBuilder SetAssignedRenderMode(ICo parameters.RenderMode = renderMode; return this; } -#endif /// /// Try to add a for a parameter with the , if diff --git a/src/bunit/Extensions/WaitForHelpers/WaitForFailedException.cs b/src/bunit/Extensions/WaitForHelpers/WaitForFailedException.cs index ec18da2ff..9099ec25c 100644 --- a/src/bunit/Extensions/WaitForHelpers/WaitForFailedException.cs +++ b/src/bunit/Extensions/WaitForHelpers/WaitForFailedException.cs @@ -38,7 +38,7 @@ time to complete the necessary number of renders of the component under test. and see if they match what is expected. If they do not, consider increasing the timeout, either at the individual method call level, e.g. WaitForElement("div", TimeSpan.FromSeconds(15)), - or via the static TestContext.DefaultWaitTimeout property. + or via the BunitContext.DefaultWaitTimeout property. Check count: {checkCount}. Component render count: {componentRenderCount}. diff --git a/src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs b/src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs index d8e5111e1..f96d019e5 100644 --- a/src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs +++ b/src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Bunit.Rendering; using Microsoft.Extensions.Logging; @@ -15,6 +16,9 @@ internal abstract class WaitForHelper : IDisposable private readonly Func> completeChecker; private readonly IRenderedComponent renderedComponent; private readonly ILogger> logger; + + [SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "Owned by the test, not by this helper.")] + private readonly BunitContext bunitContext; private readonly BunitRenderer renderer; private readonly Timer? timer; private bool isDisposed; @@ -76,10 +80,8 @@ protected WaitForHelper( this.completeChecker = completeChecker ?? throw new ArgumentNullException(nameof(completeChecker)); logger = renderedComponent.Services.CreateLogger>(); - renderer = renderedComponent - .Services - .GetRequiredService() - .Renderer; + bunitContext = renderedComponent.Services.GetRequiredService(); + renderer = bunitContext.Renderer; checkPassedCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); // Create the wait task and run the initial check @@ -280,11 +282,11 @@ private void SubscribeToOnAfterRender() renderedComponent.OnAfterRender += OnAfterRender; } - private static TimeSpan GetRuntimeTimeout(TimeSpan? timeout) + private TimeSpan GetRuntimeTimeout(TimeSpan? timeout) { return Debugger.IsAttached ? Timeout.InfiniteTimeSpan - : timeout ?? BunitContext.DefaultWaitTimeout; + : timeout ?? bunitContext.DefaultWaitTimeout; } private static Func> WrapSynchronousChecker(Func<(bool CheckPassed, T Content)> completeChecker) diff --git a/src/bunit/JSInterop/BunitJSInterop.cs b/src/bunit/JSInterop/BunitJSInterop.cs index 2dbaa9787..3f466aa1c 100644 --- a/src/bunit/JSInterop/BunitJSInterop.cs +++ b/src/bunit/JSInterop/BunitJSInterop.cs @@ -10,6 +10,8 @@ public class BunitJSInterop { private readonly Dictionary> handlers = new(); private JSRuntimeMode mode; + private BunitContext? owningContext; + private TimeSpan standaloneDefaultWaitTimeout = TimeSpan.FromSeconds(1); /// /// Gets a dictionary of all this mock has observed. @@ -27,6 +29,27 @@ public class BunitJSInterop /// public IJSRuntime JSRuntime { get; } + /// + /// Gets or sets the timeout used by unconfigured invocation handlers. Defers to the owning + /// when attached. + /// + internal TimeSpan DefaultWaitTimeout + { + get => owningContext?.DefaultWaitTimeout ?? standaloneDefaultWaitTimeout; + set + { + if (owningContext is not null) + owningContext.DefaultWaitTimeout = value; + else + standaloneDefaultWaitTimeout = value; + } + } + + /// + /// Attaches this instance to its owning . + /// + internal void AttachToContext(BunitContext context) => owningContext = context; + /// /// Initializes a new instance of the class. /// @@ -51,6 +74,7 @@ public void AddInvocationHandler(JSRuntimeInvocationHandlerBase()); handlers[resultType].Add(handler); + handler.AttachTo(this); } internal ValueTask HandleInvocation(JSRuntimeInvocation invocation) diff --git a/src/bunit/JSInterop/Implementation/BunitJSObjectReference.cs b/src/bunit/JSInterop/Implementation/BunitJSObjectReference.cs index fdaaac958..7566f57fc 100644 --- a/src/bunit/JSInterop/Implementation/BunitJSObjectReference.cs +++ b/src/bunit/JSInterop/Implementation/BunitJSObjectReference.cs @@ -4,9 +4,6 @@ namespace Bunit; [SuppressMessage("Minor Code Smell", "S1939:Inheritance list should not be redundant", Justification = "By design. To make it obvious that both is implemented.")] internal sealed class BunitJSObjectReference : IJSObjectReference, IJSInProcessObjectReference -#if !NET9_0_OR_GREATER - , IJSUnmarshalledObjectReference -#endif { private BunitJSInterop JSInterop { get; } @@ -23,7 +20,6 @@ public ValueTask InvokeAsync(string identifier, object?[]? args) public ValueTask InvokeAsync(string identifier, CancellationToken cancellationToken, object?[]? args) => JSInterop.HandleInvokeAsync(identifier, cancellationToken, args); -#if NET10_0_OR_GREATER /// public ValueTask InvokeConstructorAsync(string identifier, object?[]? args) => JSInterop.HandleInvokeConstructorAsync(identifier, args); @@ -49,7 +45,6 @@ public ValueTask InvokeConstructorAsync(string identifier, C /// public void SetValue(string identifier, TValue value) => throw new NotImplementedException(); -#endif /// public TValue Invoke(string identifier, params object?[]? args) diff --git a/src/bunit/JSInterop/Implementation/BunitJSRuntime.net10.cs b/src/bunit/JSInterop/Implementation/BunitJSRuntime.net10.cs index 5fd991935..3a3e1c3d9 100644 --- a/src/bunit/JSInterop/Implementation/BunitJSRuntime.net10.cs +++ b/src/bunit/JSInterop/Implementation/BunitJSRuntime.net10.cs @@ -1,4 +1,3 @@ -#if NET10_0_OR_GREATER using Bunit.JSInterop.Implementation; namespace Bunit.JSInterop; @@ -16,4 +15,3 @@ ValueTask IJSRuntime.InvokeConstructorAsync(string identifie ValueTask IJSRuntime.InvokeConstructorAsync(string identifier, CancellationToken cancellationToken, object?[]? args) => JSInterop.HandleInvokeConstructorAsync(identifier, cancellationToken, args); } -#endif diff --git a/src/bunit/JSInterop/Implementation/BunitJSRuntime.net8.cs b/src/bunit/JSInterop/Implementation/BunitJSRuntime.net8.cs deleted file mode 100644 index 1a3a8d649..000000000 --- a/src/bunit/JSInterop/Implementation/BunitJSRuntime.net8.cs +++ /dev/null @@ -1,27 +0,0 @@ -#if !NET9_0_OR_GREATER -using Bunit.JSInterop.Implementation; - -namespace Bunit.JSInterop; - -/// -/// bUnit's implementation of . -/// -internal sealed partial class BunitJSRuntime : IJSUnmarshalledRuntime -{ - /// - public TResult InvokeUnmarshalled(string identifier) - => JSInterop.HandleInvokeUnmarshalled(identifier); - - /// - public TResult InvokeUnmarshalled(string identifier, T0 arg0) - => JSInterop.HandleInvokeUnmarshalled(identifier, arg0); - - /// - public TResult InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1) - => JSInterop.HandleInvokeUnmarshalled(identifier, arg0, arg1); - - /// - public TResult InvokeUnmarshalled(string identifier, T0 arg0, T1 arg1, T2 arg2) - => JSInterop.HandleInvokeUnmarshalled(identifier, arg0, arg1, arg2); -} -#endif diff --git a/src/bunit/JSInterop/Implementation/JSRuntimeExtensions.cs b/src/bunit/JSInterop/Implementation/JSRuntimeExtensions.cs index e5d9f5159..075043e2f 100644 --- a/src/bunit/JSInterop/Implementation/JSRuntimeExtensions.cs +++ b/src/bunit/JSInterop/Implementation/JSRuntimeExtensions.cs @@ -85,7 +85,6 @@ internal static TResult HandleInvokeUnmarshalled(this Bunit .GetResult(); } -#if NET10_0_OR_GREATER internal static ValueTask HandleInvokeConstructorAsync(this BunitJSInterop jSInterop, string identifier, object?[]? args) { var invocation = new JSRuntimeInvocation(identifier, null, args, typeof(IJSObjectReference), "InvokeConstructorAsync"); @@ -98,7 +97,6 @@ internal static ValueTask HandleInvokeConstructorAsync(this var invocation = new JSRuntimeInvocation(identifier, cancellationToken, args, typeof(IJSObjectReference), "InvokeConstructorAsync"); return jSInterop.HandleInvocation(invocation); } -#endif private static string GetInvokeAsyncMethodName() => typeof(TValue) == typeof(Microsoft.JSInterop.Infrastructure.IJSVoidResult) diff --git a/src/bunit/JSInterop/InvocationHandlers/JSRuntimeInvocationHandlerBase{TResult}.cs b/src/bunit/JSInterop/InvocationHandlers/JSRuntimeInvocationHandlerBase{TResult}.cs index 53026ff4d..949d4022d 100644 --- a/src/bunit/JSInterop/InvocationHandlers/JSRuntimeInvocationHandlerBase{TResult}.cs +++ b/src/bunit/JSInterop/InvocationHandlers/JSRuntimeInvocationHandlerBase{TResult}.cs @@ -16,6 +16,7 @@ public abstract class JSRuntimeInvocationHandlerBase : IDisposable private long nextInvocationId; private Task? outcome; private bool disposed; + private BunitJSInterop? owner; /// /// Gets a value indicating whether this handler is set up to handle calls to InvokeVoidAsync(string, object[]). @@ -79,7 +80,7 @@ protected internal virtual Task HandleAsync(JSRuntimeInvocation invocat if (Volatile.Read(ref outcome) is { } configured) return configured; - var timeout = BunitContext.DefaultWaitTimeout; + var timeout = DefaultWaitTimeout; if (timeout <= TimeSpan.Zero) { throw new JSRuntimeInvocationNotSetException(invocation); @@ -108,6 +109,11 @@ protected internal virtual Task HandleAsync(JSRuntimeInvocation invocat /// True if the handler can handle the invocation, false otherwise. internal bool CanHandle(JSRuntimeInvocation invocation) => invocationMatcher(invocation); + /// + /// Attaches this handler to its owning . + /// + internal void AttachTo(BunitJSInterop jsInterop) => owner = jsInterop; + /// public void Dispose() { @@ -144,6 +150,8 @@ private void CompleteAll(Task next) } } + private TimeSpan DefaultWaitTimeout => owner?.DefaultWaitTimeout ?? TimeSpan.FromSeconds(1); + private void OnTimeoutElapsed(object? state) { if (state is not PendingInvocation pending || !pendingInvocations.TryRemove(pending.Id, out _)) diff --git a/src/bunit/RemovedInFutureVersionAttribute.cs b/src/bunit/RemovedInFutureVersionAttribute.cs deleted file mode 100644 index 3330d9252..000000000 --- a/src/bunit/RemovedInFutureVersionAttribute.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Bunit; - -[AttributeUsage(AttributeTargets.All, Inherited = false)] -internal sealed class RemovedInFutureVersionAttribute(string todo) : Attribute -{ - public string Todo { get; } = todo; -} diff --git a/src/bunit/Rendering/BunitHtmlParser.cs b/src/bunit/Rendering/BunitHtmlParser.cs index 47fcf0095..7973adeb1 100644 --- a/src/bunit/Rendering/BunitHtmlParser.cs +++ b/src/bunit/Rendering/BunitHtmlParser.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Diagnostics; +using System.Threading; using AngleSharp; using AngleSharp.Css; using AngleSharp.Dom; @@ -23,7 +24,7 @@ internal sealed class BunitHtmlParser : IDisposable private readonly IBrowsingContext context; private readonly HtmlParser htmlParser; private readonly List documents = new(); - private readonly object parserLock = new(); + private readonly Lock parserLock = new(); private bool disposed; /// diff --git a/src/bunit/Rendering/BunitRenderer.cs b/src/bunit/Rendering/BunitRenderer.cs index 88740fcbc..12d9bb375 100644 --- a/src/bunit/Rendering/BunitRenderer.cs +++ b/src/bunit/Rendering/BunitRenderer.cs @@ -4,6 +4,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; +using System.Threading; namespace Bunit.Rendering; @@ -23,7 +24,7 @@ public sealed class BunitRenderer : Renderer [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "SetDirectParameters")] private static extern void CallSetDirectParameters(ComponentState componentState, ParameterView parameters); - private readonly object renderTreeUpdateLock = new(); + private readonly Lock renderTreeUpdateLock = new(); private readonly HashSet returnedRenderedComponentIds = new(); private readonly List rootComponents = new(); @@ -60,7 +61,6 @@ private bool IsBatchInProgress /// internal int RenderCount { get; } -#if NET9_0_OR_GREATER private RendererInfo? rendererInfo; /// @@ -125,7 +125,6 @@ public void AddAsset(string url, string? label = null, params ResourceAssetPrope resourceAssets.Add(new ResourceAsset(url, props.Count > 0 ? props : null)); resourceAssetCollection = null; } -#endif /// /// Initializes a new instance of the class. @@ -344,7 +343,6 @@ protected override IComponent ResolveComponentForRenderMode(Type componentType, return componentActivator.CreateInstance(componentType); } -#if NET9_0_OR_GREATER /// protected override IComponentRenderMode? GetComponentRenderMode(IComponent component) { @@ -417,7 +415,6 @@ childRenderMode is not null return null; } } -#endif /// protected override void AddPendingTask(ComponentState? componentState, Task task) diff --git a/src/bunit/Rendering/Internal/Htmlizer.cs b/src/bunit/Rendering/Internal/Htmlizer.cs index 9f31c4bd0..92b391c44 100644 --- a/src/bunit/Rendering/Internal/Htmlizer.cs +++ b/src/bunit/Rendering/Internal/Htmlizer.cs @@ -113,10 +113,8 @@ int position case RenderTreeFrameType.ElementReferenceCapture: case RenderTreeFrameType.ComponentReferenceCapture: return position + 1; -#if NET8_0_OR_GREATER case RenderTreeFrameType.NamedEvent: return position + 1; -#endif default: throw new InvalidOperationException( $"Invalid element frame type '{frame.FrameType}'." diff --git a/src/bunit/Rendering/MissingRendererInfoException.cs b/src/bunit/Rendering/MissingRendererInfoException.cs index a763a0d98..7eaf3c785 100644 --- a/src/bunit/Rendering/MissingRendererInfoException.cs +++ b/src/bunit/Rendering/MissingRendererInfoException.cs @@ -1,4 +1,3 @@ -#if NET9_0_OR_GREATER namespace Bunit.Rendering; /// @@ -11,11 +10,11 @@ public sealed class MissingRendererInfoException : Exception /// public MissingRendererInfoException() : base(""" - A component under test is trying to access the 'RendererInfo' property, which has not been specified. Set it via TestContext.Renderer.SetRendererInfo. + A component under test is trying to access the 'RendererInfo' property, which has not been specified. Set it via BunitContext.Renderer.SetRendererInfo. For example: - public class SomeTestClass : TestContext + public class SomeTestClass : BunitContext { [Fact] public void SomeTestCase() @@ -33,4 +32,3 @@ public void SomeTestCase() HelpLink = "https://bunit.dev/docs/interaction/render-modes"; } } -#endif diff --git a/src/bunit/Rendering/RenderModeMisMatchException.cs b/src/bunit/Rendering/RenderModeMisMatchException.cs index 8187988e3..447c4e5d7 100644 --- a/src/bunit/Rendering/RenderModeMisMatchException.cs +++ b/src/bunit/Rendering/RenderModeMisMatchException.cs @@ -1,4 +1,3 @@ -#if NET9_0_OR_GREATER namespace Bunit.Rendering; /// @@ -19,4 +18,3 @@ Ensure that the render mode of the parent component matches the render mode of t HelpLink = "https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#render-mode-propagation"; } } -#endif diff --git a/src/bunit/TestContext.cs b/src/bunit/TestContext.cs deleted file mode 100644 index 2f3ad5022..000000000 --- a/src/bunit/TestContext.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Bunit; - -/// -[Obsolete($"Use {nameof(BunitContext)} instead. TestContext will be removed in a future release.", false, UrlFormat = "https://bunit.dev/docs/migrations")] -public class TestContext : BunitContext -{ -} diff --git a/src/bunit/TestDoubles/Authorization/BunitAuthorizationExtensions.cs b/src/bunit/TestDoubles/Authorization/BunitAuthorizationExtensions.cs index 8fad2d81d..c3dc37223 100644 --- a/src/bunit/TestDoubles/Authorization/BunitAuthorizationExtensions.cs +++ b/src/bunit/TestDoubles/Authorization/BunitAuthorizationExtensions.cs @@ -1,6 +1,5 @@ using Bunit.TestDoubles; using Microsoft.AspNetCore.Components.Authorization; -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; namespace Bunit; @@ -11,16 +10,9 @@ public partial class BunitContext /// an authenticated user, as well as adding the component to the /// test contexts render tree. /// - [RemovedInFutureVersion("SignOutSessionStateManager should be removed from the container.")] public BunitAuthorizationContext AddAuthorization() { Services.AddCascadingAuthenticationState(); -#if !NET11_0_OR_GREATER - Services.AddSingleton(); -#pragma warning disable CS0618 - Services.AddSingleton(s => s.GetRequiredService()); -#pragma warning restore CS0618 -#endif var authCtx = new BunitAuthorizationContext(Services); return authCtx; } diff --git a/src/bunit/TestDoubles/NavigationManager/BunitSignOutSessionStateManager.cs b/src/bunit/TestDoubles/NavigationManager/BunitSignOutSessionStateManager.cs deleted file mode 100644 index af6d78ecf..000000000 --- a/src/bunit/TestDoubles/NavigationManager/BunitSignOutSessionStateManager.cs +++ /dev/null @@ -1,42 +0,0 @@ -#if !NET11_0_OR_GREATER -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; - -namespace Bunit.TestDoubles; - -/// -/// Represents bUnit's own that captures calls to -/// that will help later to assert if the user was logged out -/// -#pragma warning disable CS0618 -[RemovedInFutureVersion("SignOutSessionStateManager is obsolete")] -public class BunitSignOutSessionStateManager : SignOutSessionStateManager -#pragma warning restore CS0618 -{ - /// - /// Returns true when was called, otherwise false - /// - public bool IsSignedOut { get; set; } - - /// - /// Initializes a new instance of - /// - public BunitSignOutSessionStateManager(IJSRuntime jsRuntime) : base(jsRuntime) - { - } - - /// - public override ValueTask SetSignOutState() - { - IsSignedOut = true; - return new ValueTask(); - } - - /// - public override Task ValidateSignOutState() - { - var wasSignedOut = IsSignedOut; - IsSignedOut = false; - return Task.FromResult(wasSignedOut); - } -} -#endif diff --git a/src/bunit/bunit.csproj b/src/bunit/bunit.csproj index 8712df6b9..14e3353c7 100644 --- a/src/bunit/bunit.csproj +++ b/src/bunit/bunit.csproj @@ -1,6 +1,6 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index 28d889510..eb2e9fbcc 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit Bunit.Generator.Tests true diff --git a/tests/bunit.testassets/Assets/AssetsIndexerComponent.razor b/tests/bunit.testassets/Assets/AssetsIndexerComponent.razor index 3b3a7cb3d..47e2c8b28 100644 --- a/tests/bunit.testassets/Assets/AssetsIndexerComponent.razor +++ b/tests/bunit.testassets/Assets/AssetsIndexerComponent.razor @@ -1,7 +1 @@ -@{ -#if NET9_0_OR_GREATER -} -@{ -#endif -} diff --git a/tests/bunit.testassets/Assets/AssetsIterationComponent.razor b/tests/bunit.testassets/Assets/AssetsIterationComponent.razor index f6dfbe340..430c4a2b7 100644 --- a/tests/bunit.testassets/Assets/AssetsIterationComponent.razor +++ b/tests/bunit.testassets/Assets/AssetsIterationComponent.razor @@ -1,15 +1,8 @@ -@{ -#if NET9_0_OR_GREATER -} @foreach (var name in SubresourceNames) { @name } -@{ -#endif -} @code { -#if NET9_0_OR_GREATER private IReadOnlyList SubresourceNames { get; set; } = Array.Empty(); protected override void OnInitialized() @@ -17,5 +10,4 @@ .Select(asset => asset.Properties?.SingleOrDefault(property => property.Name == "label")?.Value) .OfType() .ToList(); -#endif } diff --git a/tests/bunit.testassets/Assets/AssetsPropertiesComponent.razor b/tests/bunit.testassets/Assets/AssetsPropertiesComponent.razor index bb4d4ffab..453e1e472 100644 --- a/tests/bunit.testassets/Assets/AssetsPropertiesComponent.razor +++ b/tests/bunit.testassets/Assets/AssetsPropertiesComponent.razor @@ -1,6 +1,3 @@ -@{ -#if NET9_0_OR_GREATER -} @foreach (var asset in Assets) {
    @@ -10,6 +7,3 @@ }
} -@{ -#endif -} diff --git a/tests/bunit.testassets/DumpCapture.cs b/tests/bunit.testassets/DumpCapture.cs index 822fddf28..ca635e590 100644 --- a/tests/bunit.testassets/DumpCapture.cs +++ b/tests/bunit.testassets/DumpCapture.cs @@ -49,11 +49,7 @@ public static async Task OnFailureAsync( private static async Task CaptureDump(string testName, string testFilePath, ITestOutputHelper outputHelper) { -#if NETSTANDARD2_1 - var processId = Process.GetCurrentProcess().Id; -#else var processId = Environment.ProcessId; -#endif var dumpFilePath = Path.Combine(Directory.GetCurrentDirectory(), $"{Path.GetFileNameWithoutExtension(testFilePath)}-{testName}-wait-failed-{Guid.NewGuid()}.dmp"); // Attempt to start the dotnet-dump process var startInfo = new ProcessStartInfo @@ -72,11 +68,7 @@ private static async Task CaptureDump(string testName, string testFilePath, ITes return; } -#if NETSTANDARD2_1 - process.WaitForExit(); -#else await process.WaitForExitAsync(); -#endif var output = await process.StandardOutput.ReadToEndAsync(); var error = await process.StandardError.ReadToEndAsync(); outputHelper.WriteLine($"Dump status: {{process.ExitCode}}. Dump file: {dumpFilePath}"); diff --git a/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor index effe0ff2c..98e281912 100644 --- a/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor +++ b/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor @@ -1,9 +1 @@ -@{ -#if NET9_0_OR_GREATER -} -

Assigned Render Mode: @AssignedRenderMode?.GetType().Name

- -@{ -#endif -} diff --git a/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor index dd008df6c..6e1a0fe20 100644 --- a/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor +++ b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor @@ -1,7 +1,3 @@ -@{ -#if NET9_0_OR_GREATER -} - @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
@ChildContent @@ -9,7 +5,3 @@ @code { [Parameter] public RenderFragment? ChildContent { get; set; } } - -@{ -#endif -} diff --git a/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor index af0888317..b0acd4364 100644 --- a/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor +++ b/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor @@ -1,15 +1,7 @@ -@{ -#if NET9_0_OR_GREATER -} - @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveWebAssembly
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
@ChildContent @code { [Parameter] public RenderFragment? ChildContent { get; set; } -} - -@{ -#endif } \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor index 6d5f7f9b7..b47217109 100644 --- a/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor +++ b/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor @@ -1,14 +1,6 @@ -@{ -#if NET9_0_OR_GREATER -} -
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
@ChildContent @code { [Parameter] public RenderFragment? ChildContent { get; set; } -} - -@{ -#endif } \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs b/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs index 9393ab3eb..02947c591 100644 --- a/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs +++ b/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs @@ -1,5 +1,3 @@ -#if NET9_0_OR_GREATER - namespace Bunit.TestAssets.RenderModes; public class RendererInfoComponent : ComponentBase @@ -17,4 +15,3 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseElement(); } } -#endif \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs b/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs index 70dd7d9a1..cc3237ebb 100644 --- a/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs +++ b/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs @@ -1,22 +1,16 @@ using Microsoft.AspNetCore.Components.Web; - -#if NET8_0_OR_GREATER using Microsoft.AspNetCore.Components.Sections; -#endif namespace Bunit.TestAssets.RenderModes; public class SectionOutletComponent : ComponentBase { -#if NET8_0_OR_GREATER private static readonly Guid SectionId = Guid.NewGuid(); -#endif [Parameter] public RenderFragment ChildContent { get; set; } protected override void BuildRenderTree(RenderTreeBuilder builder) { -#if NET8_0_OR_GREATER builder.OpenComponent(0); builder.AddComponentParameter(1, nameof(SectionOutlet.SectionId), SectionId); builder.AddComponentRenderMode(RenderMode.InteractiveWebAssembly); @@ -25,6 +19,5 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddComponentParameter(11, nameof(SectionContent.SectionId), SectionId); builder.AddAttribute(12, nameof(SectionContent.ChildContent), ChildContent); builder.CloseComponent(); -#endif } } diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index b8d28daec..d26f5977a 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -1,7 +1,7 @@  - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit.TestAssets Bunit.TestAssets Library diff --git a/tests/bunit.tests/BlazorE2E/ComponentRenderingTest.cs b/tests/bunit.tests/BlazorE2E/ComponentRenderingTest.cs index 9c3fb672b..132feff6a 100644 --- a/tests/bunit.tests/BlazorE2E/ComponentRenderingTest.cs +++ b/tests/bunit.tests/BlazorE2E/ComponentRenderingTest.cs @@ -20,7 +20,7 @@ public class ComponentRenderingTest : BunitContext { public ComponentRenderingTest(ITestOutputHelper outputHelper) { - BunitContext.DefaultWaitTimeout = TimeSpan.FromSeconds(10); + DefaultWaitTimeout = TimeSpan.FromSeconds(10); Services.AddXunitLogger(outputHelper); JSInterop.Mode = JSRuntimeMode.Loose; } diff --git a/tests/bunit.tests/EventDispatchExtensions/GeneralEventDispatchExtensionsTest.cs b/tests/bunit.tests/EventDispatchExtensions/GeneralEventDispatchExtensionsTest.cs index 7bf444d62..caf4083a0 100644 --- a/tests/bunit.tests/EventDispatchExtensions/GeneralEventDispatchExtensionsTest.cs +++ b/tests/bunit.tests/EventDispatchExtensions/GeneralEventDispatchExtensionsTest.cs @@ -14,7 +14,7 @@ public class GeneralEventDispatchExtensionsTest : EventDispatchExtensionsTest(() => ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar")); - exception.Invocation.Identifier.ShouldBe(identifier); - exception.Invocation.Arguments.ShouldBe(args); - } - - [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with two arguments")] - public void Test048() - { - var sut = CreateSut(JSRuntimeMode.Strict); - var identifier = "func"; - var args = new[] { "bar", "baz" }; - - var exception = Should.Throw(() => ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar", "baz")); - exception.Invocation.Identifier.ShouldBe(identifier); - exception.Invocation.Arguments.ShouldBe(args); - } - - [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with three arguments")] - public void Test049() - { - var sut = CreateSut(JSRuntimeMode.Strict); - var identifier = "func"; - var args = new[] { "bar", "baz", "bau" }; - - var exception = Should.Throw(() => ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar", "baz", "bau")); - exception.Invocation.Identifier.ShouldBe(identifier); - exception.Invocation.Arguments.ShouldBe(args); - } - - [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with zero arguments")] - public void Test050() - { - var sut = CreateSut(JSRuntimeMode.Strict); - var identifier = "func"; - - var exception = Should.Throw(() => ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier)); - exception.Invocation.Identifier.ShouldBe(identifier); - exception.Invocation.Arguments.ShouldBeEmpty(); - } - - [Fact(DisplayName = "An IJSUnmarshalledRuntime invocation should return the correct result when passed one arguments.")] - public void Test055() - { - var identifier = "fooFunc"; - var args = new[] { "bar" }; - var sut = CreateSut(JSRuntimeMode.Strict); - - var expectedResult = Guid.NewGuid(); - var planned = sut.Setup("fooFunc", args); - planned.SetResult(expectedResult); - - var actual = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar"); - actual.ShouldBe(expectedResult); - } - - [Fact(DisplayName = "An IJSUnmarshalledRuntime invocation should return the correct result when passed two arguments.")] - public void Test056() - { - var identifier = "fooFunc"; - var args = new[] { "bar", "baz" }; - var sut = CreateSut(JSRuntimeMode.Strict); - - var expectedResult = Guid.NewGuid(); - var planned = sut.Setup("fooFunc", args); - planned.SetResult(expectedResult); - - var actual = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar", "baz"); - actual.ShouldBe(expectedResult); - } - - [Fact(DisplayName = "An IJSUnmarshalledRuntime invocation should return the correct result when passed three arguments.")] - public void Test057() - { - var identifier = "fooFunc"; - var args = new[] { "bar", "baz", "bao" }; - var sut = CreateSut(JSRuntimeMode.Strict); - - var expectedResult = Guid.NewGuid(); - var planned = sut.Setup("fooFunc", args); - planned.SetResult(expectedResult); - - var actual = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier, "bar", "baz", "bao"); - actual.ShouldBe(expectedResult); - } - - [Fact(DisplayName = "An IJSUnmarshalledRuntime invocation should return the correct result when passed zero arguments.")] - public void Test058() - { - var identifier = "fooFunc"; - var sut = CreateSut(JSRuntimeMode.Strict); - - var expectedResult = Guid.NewGuid(); - var planned = sut.Setup("fooFunc"); - planned.SetResult(expectedResult); - - var actual = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled(identifier); - actual.ShouldBe(expectedResult); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier), then the invocation should be visible from the Invocations list"), AutoData] - public void Test310(string identifier) - { - var sut = CreateSut(JSRuntimeMode.Loose); - var jsUnmarshalledRuntime = (IJSUnmarshalledRuntime)sut.JSRuntime; - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier); - - sut.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - Array.Empty(), - typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0), then the invocation should be visible from the Invocations list"), AutoData] - public void Test306(string identifier, string arg0) - { - var sut = CreateSut(JSRuntimeMode.Loose); - var jsUnmarshalledRuntime = (IJSUnmarshalledRuntime)sut.JSRuntime; - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier, arg0); - - sut.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0, arg1), then the invocation should be visible from the Invocations list"), AutoData] - public void Test307(string identifier, string arg0, string arg1) - { - var sut = CreateSut(JSRuntimeMode.Loose); - var jsUnmarshalledRuntime = (IJSUnmarshalledRuntime)sut.JSRuntime; - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier, arg0, arg1); - - sut.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0, arg1 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0, arg1, arg2), then the invocation should be visible from the Invocations list"), AutoData] - public void Test308(string identifier, string arg0, string arg1, string arg2) - { - var sut = CreateSut(JSRuntimeMode.Loose); - var jsUnmarshalledRuntime = (IJSUnmarshalledRuntime)sut.JSRuntime; - - jsUnmarshalledRuntime.InvokeUnmarshalled( - identifier, arg0, arg1, arg2); - - sut.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0, arg1, arg2 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } -#endif -#if NET10_0_OR_GREATER [Fact(DisplayName = "InvokeConstructorAsync returns IJSObjectReference in loose mode without setup")] public async Task Test400() { @@ -774,5 +591,4 @@ public async Task Test406() sut.Invocations["JsClass"].ShouldHaveSingleItem() .InvocationMethodName.ShouldBe("InvokeConstructorAsync"); } -#endif } diff --git a/tests/bunit.tests/JSInterop/BunitJSInteropTimeoutTest.cs b/tests/bunit.tests/JSInterop/BunitJSInteropTimeoutTest.cs index eb5cc4a28..e268cc2ec 100644 --- a/tests/bunit.tests/JSInterop/BunitJSInteropTimeoutTest.cs +++ b/tests/bunit.tests/JSInterop/BunitJSInteropTimeoutTest.cs @@ -2,12 +2,6 @@ namespace Bunit.JSInterop; -[CollectionDefinition(nameof(DefaultWaitTimeoutTestGroup), DisableParallelization = true)] -public sealed class DefaultWaitTimeoutTestGroup -{ -} - -[Collection(nameof(DefaultWaitTimeoutTestGroup))] public class BunitJSInteropTimeoutTest { [Fact(DisplayName = "JSRuntime invocation times out when handler is not configured")] @@ -15,34 +9,28 @@ public async Task Test309() { const string identifier = "testFunction"; - await WithDefaultWaitTimeout(TimeSpan.FromMilliseconds(100), async () => - { - var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict }; - sut.Setup(identifier); + var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict, DefaultWaitTimeout = TimeSpan.FromMilliseconds(100) }; + sut.Setup(identifier); - var invocationTask = sut.JSRuntime.InvokeAsync(identifier); + var invocationTask = sut.JSRuntime.InvokeAsync(identifier); - var exception = await Should.ThrowAsync(invocationTask.AsTask()); - exception.Invocation.Identifier.ShouldBe(identifier); - }); + var exception = await Should.ThrowAsync(invocationTask.AsTask()); + exception.Invocation.Identifier.ShouldBe(identifier); } [Fact(DisplayName = "Each pending invocation times out with its own invocation")] public async Task Test310() { - await WithDefaultWaitTimeout(TimeSpan.FromMilliseconds(100), async () => - { - var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict }; - sut.Setup(_ => true); + var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict, DefaultWaitTimeout = TimeSpan.FromMilliseconds(100) }; + sut.Setup(_ => true); - var first = sut.JSRuntime.InvokeAsync("first").AsTask(); - var second = sut.JSRuntime.InvokeAsync("second").AsTask(); + var first = sut.JSRuntime.InvokeAsync("first").AsTask(); + var second = sut.JSRuntime.InvokeAsync("second").AsTask(); - (await Should.ThrowAsync(first)) - .Invocation.Identifier.ShouldBe("first"); - (await Should.ThrowAsync(second)) - .Invocation.Identifier.ShouldBe("second"); - }); + (await Should.ThrowAsync(first)) + .Invocation.Identifier.ShouldBe("first"); + (await Should.ThrowAsync(second)) + .Invocation.Identifier.ShouldBe("second"); } [Fact(DisplayName = "A timed out invocation does not affect later invocations")] @@ -50,18 +38,15 @@ public async Task Test311() { const string identifier = "testFunction"; - await WithDefaultWaitTimeout(TimeSpan.FromMilliseconds(100), async () => - { - var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict }; - var handler = sut.Setup(identifier); + var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict, DefaultWaitTimeout = TimeSpan.FromMilliseconds(100) }; + var handler = sut.Setup(identifier); - await Should.ThrowAsync( - sut.JSRuntime.InvokeAsync(identifier).AsTask()); + await Should.ThrowAsync( + sut.JSRuntime.InvokeAsync(identifier).AsTask()); - handler.SetResult(42); + handler.SetResult(42); - (await sut.JSRuntime.InvokeAsync(identifier)).ShouldBe(42); - }); + (await sut.JSRuntime.InvokeAsync(identifier)).ShouldBe(42); } [Fact(DisplayName = "Setting a result while the timeout elapses does not crash the test host")] @@ -70,21 +55,18 @@ public async Task Test312() const string identifier = "testFunction"; var timeout = TimeSpan.FromMilliseconds(2); - await WithDefaultWaitTimeout(timeout, async () => - { - var workers = Enumerable - .Range(0, Math.Max(4, Environment.ProcessorCount)) - .Select(_ => Task.Run(() => RaceResultAgainstTimeout(identifier, timeout, iterations: 250))); + var workers = Enumerable + .Range(0, Math.Max(4, Environment.ProcessorCount)) + .Select(_ => Task.Run(() => RaceResultAgainstTimeout(identifier, timeout, iterations: 250))); - await Task.WhenAll(workers); - }); + await Task.WhenAll(workers); } private static async Task RaceResultAgainstTimeout(string identifier, TimeSpan timeout, int iterations) { for (var i = 0; i < iterations; i++) { - var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict }; + var sut = new BunitJSInterop { Mode = JSRuntimeMode.Strict, DefaultWaitTimeout = timeout }; var handler = sut.Setup(identifier); var invocationTask = sut.JSRuntime.InvokeAsync(identifier).AsTask(); @@ -105,18 +87,4 @@ private static async Task RaceResultAgainstTimeout(string identifier, TimeSpan t exception.InnerException.ShouldBeOfType(); } } - - private static async Task WithDefaultWaitTimeout(TimeSpan timeout, Func test) - { - var originalTimeout = BunitContext.DefaultWaitTimeout; - BunitContext.DefaultWaitTimeout = timeout; - try - { - await test(); - } - finally - { - BunitContext.DefaultWaitTimeout = originalTimeout; - } - } } diff --git a/tests/bunit.tests/JSInterop/BunitJsObjectReferenceTest.cs b/tests/bunit.tests/JSInterop/BunitJsObjectReferenceTest.cs index d99bd9dd3..6342f3569 100644 --- a/tests/bunit.tests/JSInterop/BunitJsObjectReferenceTest.cs +++ b/tests/bunit.tests/JSInterop/BunitJsObjectReferenceTest.cs @@ -246,18 +246,6 @@ public void Test070() jsRuntime.ShouldBeAssignableTo(); } -#if !NET9_0_OR_GREATER - [Fact(DisplayName = "IJSObjectReference can be cast to IJSUnmarshalledObjectReference")] - public void Test071() - { - JSInterop.Mode = JSRuntimeMode.Loose; - - var jsRuntime = GetBunitJSObjectReference(); - - jsRuntime.ShouldBeAssignableTo(); - } -#endif - [Fact(DisplayName = "IJSInProcessObjectReference-invocations is handled by handlers from BunitJSInterop")] public async Task Test080() { @@ -279,114 +267,6 @@ public async Task Test080() JSInterop.VerifyInvoke("bar6").Arguments.ShouldBe(["baz"]); } -#if !NET9_0_OR_GREATER - [Fact(DisplayName = "IJSUnmarshalledObjectReference-invocations is handled by handlers from BunitJSInterop")] - [Obsolete("Because we are calling obsolete methods in test.")] - public async Task Test081() - { - JSInterop.Mode = JSRuntimeMode.Loose; - var jsUnmarshalled = (IJSUnmarshalledObjectReference)GetBunitJSObjectReference(); - - await jsUnmarshalled.InvokeAsync("bar1"); - await jsUnmarshalled.InvokeAsync("bar2", "baz"); - await jsUnmarshalled.InvokeVoidAsync("bar3"); - await jsUnmarshalled.InvokeVoidAsync("bar4", "baz"); - jsUnmarshalled.Invoke("bar5"); - jsUnmarshalled.Invoke("bar6", "baz"); - jsUnmarshalled.InvokeUnmarshalled("bar7"); - jsUnmarshalled.InvokeUnmarshalled("bar8", "baz"); - jsUnmarshalled.InvokeUnmarshalled("bar9", "baz", "boo"); - jsUnmarshalled.InvokeUnmarshalled("bar10", "baz", "boo", "bah"); - - JSInterop.VerifyInvoke("bar1"); - JSInterop.VerifyInvoke("bar2").Arguments.ShouldBe(["baz"]); - JSInterop.VerifyInvoke("bar3"); - JSInterop.VerifyInvoke("bar4").Arguments.ShouldBe(["baz"]); - JSInterop.VerifyInvoke("bar5"); - JSInterop.VerifyInvoke("bar6").Arguments.ShouldBe(["baz"]); - JSInterop.VerifyInvoke("bar7"); - JSInterop.VerifyInvoke("bar8").Arguments.ShouldBe(["baz"]); - JSInterop.VerifyInvoke("bar9").Arguments.ShouldBe(["baz", "boo"]); - JSInterop.VerifyInvoke("bar10").Arguments.ShouldBe(["baz", "boo", "bah"]); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier), then the invocation should be visible from the Invocations list"), AutoData] - [Obsolete("Because we are calling obsolete methods in test.")] - public void Test310(string identifier) - { - JSInterop.Mode = JSRuntimeMode.Loose; - var jsUnmarshalledRuntime = (IJSUnmarshalledObjectReference)GetBunitJSObjectReference(); - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier); - - JSInterop.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: Array.Empty(), - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0), then the invocation should be visible from the Invocations list"), AutoData] - [Obsolete("Because we are calling obsolete methods in test.")] - public void Test306(string identifier, string arg0) - { - JSInterop.Mode = JSRuntimeMode.Loose; - var jsUnmarshalledRuntime = (IJSUnmarshalledObjectReference)GetBunitJSObjectReference(); - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier, arg0); - - JSInterop.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0, arg1), then the invocation should be visible from the Invocations list"), AutoData] - [Obsolete("Because we are calling obsolete methods in test.")] - public void Test307(string identifier, string arg0, string arg1) - { - JSInterop.Mode = JSRuntimeMode.Loose; - var jsUnmarshalledRuntime = (IJSUnmarshalledObjectReference)GetBunitJSObjectReference(); - - jsUnmarshalledRuntime.InvokeUnmarshalled(identifier, arg0, arg1); - - JSInterop.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0, arg1 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } - - [Theory(DisplayName = "When calling InvokeUnmarshalled(identifier, arg0, arg1, arg2), then the invocation should be visible from the Invocations list"), AutoData] - [Obsolete("Because we are calling obsolete methods in test.")] - public void Test308(string identifier, string arg0, string arg1, string arg2) - { - JSInterop.Mode = JSRuntimeMode.Loose; - var jsUnmarshalledRuntime = (IJSUnmarshalledObjectReference)GetBunitJSObjectReference(); - - jsUnmarshalledRuntime.InvokeUnmarshalled( - identifier, arg0, arg1, arg2); - - JSInterop.Invocations[identifier] - .ShouldHaveSingleItem() - .ShouldBe(new JSRuntimeInvocation( - identifier, - cancellationToken: null, - args: new[] { arg0, arg1, arg2 }, - resultType: typeof(string), - invocationMethodName: "InvokeUnmarshalled")); - } -#endif [Theory(DisplayName = "When calling InvokeVoidAsync, then the invocation should be visible from the Invocations list"), AutoData] public void Test302(string identifier, string[] args, CancellationToken cancellationToken) diff --git a/tests/bunit.tests/JSInterop/InvocationHandlers/VirtualizeJsRuntimeInvocationHandlerTest.cs b/tests/bunit.tests/JSInterop/InvocationHandlers/VirtualizeJsRuntimeInvocationHandlerTest.cs index 42a7a5607..784ba7e62 100644 --- a/tests/bunit.tests/JSInterop/InvocationHandlers/VirtualizeJsRuntimeInvocationHandlerTest.cs +++ b/tests/bunit.tests/JSInterop/InvocationHandlers/VirtualizeJsRuntimeInvocationHandlerTest.cs @@ -15,9 +15,7 @@ public void Test001(int itemsInDataSource) { var cut = Render>(ps => ps .Add(p => p.Items, CreateItems(itemsInDataSource)) -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.ChildContent, item => $"

{item}

")); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -29,9 +27,7 @@ public void Test002(int itemsInDataSource) { var cut = Render>(ps => ps .Add(p => p.Items, CreateItems(itemsInDataSource)) -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.ItemContent, item => $"

{item}

")); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -43,9 +39,7 @@ public void Test010(int itemsInDataSource) { var cut = Render>(ps => ps .Add(p => p.ItemsProvider, CreateItemsProvider(itemsInDataSource)) -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.ChildContent, item => $"

{item}

")); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -57,9 +51,7 @@ public void Test011(int itemsInDataSource) { var cut = Render>(ps => ps .Add(p => p.ItemsProvider, CreateItemsProvider(itemsInDataSource)) -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.ItemContent, item => $"

{item}

")); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -119,9 +111,7 @@ public void Test030(int itemsInDataSource, float itemSize, int overscanCount) .Add(p => p.ItemsProvider, CreateItemsProvider(itemsInDataSource)) .Add(p => p.ItemContent, item => $"

{item}

") .Add(p => p.ItemSize, itemSize) -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.OverscanCount, overscanCount)); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -134,9 +124,7 @@ public void Test040(int itemsInDataSource) var cut = Render>(ps => ps .Add(p => p.ItemsProvider, _ => ValueTask.FromResult(new ItemsProviderResult(Array.Empty(), itemsInDataSource))) .Add(p => p.ItemContent, item => @$"

{item}

") -#if NET9_0_OR_GREATER .Add(p => p.MaxItemCount, itemsInDataSource) -#endif .Add(p => p.Placeholder, _ => @"

")); cut.FindAll(".placeholder").Count.ShouldBe(itemsInDataSource); diff --git a/tests/bunit.tests/Rendering/AssetsTest.razor b/tests/bunit.tests/Rendering/AssetsTest.razor index 3f2dd16aa..84c757c52 100644 --- a/tests/bunit.tests/Rendering/AssetsTest.razor +++ b/tests/bunit.tests/Rendering/AssetsTest.razor @@ -1,6 +1,3 @@ -@code{ - #if NET9_0_OR_GREATER -} @using Bunit.TestAssets.Assets; @inherits BunitContext @code { @@ -101,6 +98,3 @@ ex.ParamName.ShouldBe("properties"); } } -@code{ - #endif -} diff --git a/tests/bunit.tests/Rendering/RenderModeTest.razor b/tests/bunit.tests/Rendering/RenderModeTest.razor index afc865b9e..ecc32b481 100644 --- a/tests/bunit.tests/Rendering/RenderModeTest.razor +++ b/tests/bunit.tests/Rendering/RenderModeTest.razor @@ -1,6 +1,3 @@ -@code{ - #if NET9_0_OR_GREATER -} @using Bunit.TestAssets.RenderModes; @inherits BunitContext @code { @@ -171,6 +168,3 @@ act.ShouldThrow(); } } -@code{ - #endif -} diff --git a/tests/bunit.tests/TestDoubles/Authorization/AuthorizationTest.cs b/tests/bunit.tests/TestDoubles/Authorization/AuthorizationTest.cs index 40c2d9730..ccc00e5c1 100644 --- a/tests/bunit.tests/TestDoubles/Authorization/AuthorizationTest.cs +++ b/tests/bunit.tests/TestDoubles/Authorization/AuthorizationTest.cs @@ -6,7 +6,7 @@ public class AuthorizationTest : BunitContext { public AuthorizationTest(ITestOutputHelper outputHelper) { - BunitContext.DefaultWaitTimeout = TimeSpan.FromSeconds(10); + DefaultWaitTimeout = TimeSpan.FromSeconds(10); Services.AddXunitLogger(outputHelper); } diff --git a/tests/bunit.tests/TestDoubles/BunitSignOutSessionStateManagerTest.cs b/tests/bunit.tests/TestDoubles/BunitSignOutSessionStateManagerTest.cs deleted file mode 100644 index 03a40bf7a..000000000 --- a/tests/bunit.tests/TestDoubles/BunitSignOutSessionStateManagerTest.cs +++ /dev/null @@ -1,31 +0,0 @@ -#if !NET11_0_OR_GREATER -namespace Bunit.TestDoubles; - -public class BunitSignOutSessionStateManagerTest : BunitContext -{ - [Theory, AutoData] - public void ShouldSignOut(string randomUserName) - { - AddAuthorization().SetAuthorized(randomUserName); - var cut = Render(); - - cut.Find("button").Click(); - - Services.GetService()! - .IsSignedOut - .ShouldBeTrue(); - } - - [Fact] - public async Task ShouldReturnSignOutStateOnValidateSignOutState() - { - var cut = new BunitSignOutSessionStateManager(Substitute.For()); - await cut.SetSignOutState(); - - var wasValidate = await cut.ValidateSignOutState(); - - wasValidate.ShouldBeTrue(); - cut.IsSignedOut.ShouldBeFalse(); - } -} -#endif \ No newline at end of file diff --git a/tests/bunit.tests/bunit.tests.csproj b/tests/bunit.tests/bunit.tests.csproj index 93b44ce54..a7c0e5ee0 100644 --- a/tests/bunit.tests/bunit.tests.csproj +++ b/tests/bunit.tests/bunit.tests.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit Bunit.Tests diff --git a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj index dc2b89628..7ada40bcd 100644 --- a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj +++ b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj @@ -1,7 +1,7 @@ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 Bunit Bunit.Web.Query.Tests diff --git a/version.json b/version.json index b6ff506b5..a372a9054 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "2.12-preview", + "version": "3.0-alpha", "assemblyVersion": { "precision": "revision" },