diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9ec00c266..41f46fb35 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,7 @@ "features": { "ghcr.io/devcontainers/features/dotnet:2": { "version": "latest", - "additionalVersions": "8.0,7.0,6.0,5.0,3.1" + "additionalVersions": "8.0" } }, diff --git a/.editorconfig b/.editorconfig index 678b64563..bc2d6e84a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -454,6 +454,7 @@ dotnet_diagnostic.S1075.severity = suggestion # S1075: URIs should not be hardco dotnet_diagnostic.S1186.severity = suggestion # S1186: Methods should not be empty dotnet_diagnostic.S2292.severity = suggestion # S2292: Trivial properties should be auto-implemented dotnet_diagnostic.S3267.severity = suggestion # S3267: Convert foreach loop to LINQ query +dotnet_diagnostic.S2743.severity = suggestion # S2743: A static field in a generic type is not shared among instances dotnet_diagnostic.S4158.severity = none # BUGGY with C#9 code - doesnt understand local methods # Razor specific rules @@ -491,6 +492,7 @@ dotnet_diagnostic.CA1062.severity = none # CA1062: Validate arguments of public dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores dotnet_diagnostic.CA1812.severity = none # CA1812: Avoid uninstantiated internal classes - components under test are never instantiated directly. dotnet_diagnostic.CA1822.severity = suggestion # CA1822: Mark members as static +dotnet_diagnostic.CA1859.severity = none # CA1859: Change return type of method dotnet_diagnostic.CA2007.severity = none # CA2007: Consider calling ConfigureAwait on the awaited task # Microsoft - FxCop diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b5c93a45..4565da072 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ on: paths: - 'src/**' - 'tests/**' + - 'docs/**' pull_request: types: @@ -18,7 +19,7 @@ on: workflow_dispatch: concurrency: - group: verification-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }} + group: ci-${{ github.workflow }}-${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/v2') && github.run_id || github.event.pull_request.number || github.ref }} cancel-in-progress: true env: @@ -46,6 +47,7 @@ jobs: dotnet-version: | 8.0.x 9.0.x + 10.0.x - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 @@ -71,10 +73,9 @@ jobs: # Create the NuGet package in the folder from the environment variable NuGetDirectory - run: | dotnet pack src/bunit/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true - dotnet pack src/bunit.core/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true - dotnet pack src/bunit.web/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true dotnet pack src/bunit.template/ -c Release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true dotnet pack src/bunit.web.query/ -c release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true + dotnet pack src/bunit.generators/ -c release --output ${{ env.NUGET_DIRECTORY }} -p:ContinuousIntegrationBuild=true -p:publicrelease=true # Publish the NuGet package as an artifact, so they can be used in the following jobs - uses: actions/upload-artifact@v4 @@ -112,8 +113,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-13, windows-latest] - framework: [net8.0, net9.0] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -128,6 +128,7 @@ jobs: dotnet-version: | 8.0.x 9.0.x + 10.0.x - name: ⚙️ Restore packages and tools run: | @@ -135,7 +136,7 @@ jobs: dotnet tool restore - name: 🧪 Run unit tests - run: dotnet test -c release --no-restore -f ${{ matrix.framework }} + run: dotnet test -c release --no-restore - name: 📛 Upload hang- and crash-dumps on test failure if: success() || failure() @@ -219,12 +220,9 @@ jobs: uses: actions/setup-dotnet@v4 with: dotnet-version: | - 3.1.x - 5.0.x - 6.0.x - 7.0.x 8.0.x 9.0.x + 10.0.x - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 1bf98486a..a1b9954ca 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -75,6 +75,7 @@ jobs: dotnet-version: | 8.0.x 9.0.x + 10.0.x - name: 🎨 Setup color run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c4b9027e6..09a1ac5c9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,6 +60,7 @@ jobs: dotnet-version: | 8.0.x 9.0.x + 10.0.x - name: 🛠️ Update changelog uses: thomaseizinger/keep-a-changelog-new-release@3.1.0 @@ -96,9 +97,9 @@ jobs: - name: 🛠️ Packing library in release mode run: | dotnet pack src/bunit/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - dotnet pack src/bunit.core/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - dotnet pack src/bunit.web/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true + dotnet pack src/bunit.template/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true dotnet pack src/bunit.web.query/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true + dotnet pack src/bunit.generators/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - name: 🛠️ Upload library to NuGet.org repository run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5271c47..3ac8e4790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +This major release focuses on platform updates and API simplifications. + +For a migration guide, see [Upgrading bUnit](https://bunit.dev/docs/migrations/index.html). + +### Changed + +- Target framework support updated: added support for .NET 10 (`net10.0`) and dropped all versions prior to .NET 8 (`net8.0`). +- Cleanup of the API with simplifications of many API calls and methods. This also includes renaming of some objects to better reflect their purpose. + +### Added + +- Improved renderer logic that catches more edge cases. +- Improved developer experience in relation to JSInterop. + ## [1.40.0] - 2025-06-14 ### Fixed @@ -85,6 +99,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad - CI build changes to force running verification on x64 based AMD CPUs. +### Added + +- New overloads for `ComponentParameterCollectionBuilder.Add` that allow passing arguments for asynchronous callback parameters. Reported by [springy76](https://github.com/springy76). By [@Qwertyluk](https://github.com/Qwertyluk). + ## [1.28.9] - 2024-04-19 ### Fixed @@ -743,7 +761,7 @@ List of new features. - Added `Render(RenderFragment)` and `Render(RenderFragment)` methods to `TestContext`, as well as various overloads to the `MarkupMatches` methods, that also takes a `RenderFragment` as the expected value. - The difference between the generic `Render` method and the non-generic one is that the generic returns an `IRenderedComponent`, whereas the non-generic one returns a `IRenderedFragment`. + The difference between the generic `Render` method and the non-generic one is that the generic returns an `IRenderedComponent`, whereas the non-generic one returns a `RenderedFragment`. Calling `Render(RenderFragent)` is equivalent to calling `Render(RenderFragment).FindComponent()`, e.g. it returns the first component in the render tree of type `TComponent`. This is different from the `RenderComponent()` method, where `TComponent` _is_ the root component of the render tree. diff --git a/Directory.Build.props b/Directory.Build.props index b2194a03c..432358349 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -25,23 +25,19 @@ ../../key.snk - - 3.0 - - AllEnabledByDefault true - 7 + 8 true - + true - + diff --git a/Directory.Packages.props b/Directory.Packages.props index 63b989f88..da87d3770 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,9 +6,9 @@ - - - + + + @@ -18,99 +18,65 @@ - - + + - - - - - - - - - - - - + + + + - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - + + + + + + - - - - - - - + - - - - - - - - - - - + + + + + + + + + + + + + - - - - + + + + @@ -118,28 +84,23 @@ - - + + - + - - - - - - - - + + + + - - - - - - + + + + + diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 000000000..02f944288 --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,84 @@ +# Migration Guide `v1` to `v2` +This document describes the changes that need to be made to migrate from bUnit 1.x to 2.x. + +## Removal of `GetChangesSinceFirstRender` and `GetChangesSinceLastRender` methods +The `GetChangesSinceFirstRender` and `GetChangesSinceLastRender` methods have been removed from `RenderedComponent`. There is no one-to-one replacement for these methods, but the general idea is to select the HTML in question via `Find` and assert against that. + +Alternatively, the `RenderedFragment` still offers the `OnMarkupUpdated` event, which can be used to assert against the markup after a render. + +## Removal of `IsNullOrEmpty` extension method on `IEnumerable` and `CreateLogger` on `IServiceProvider` +The `IsNullOrEmpty` extension method on `IEnumerable` has been removed, as well as the `CreateLogger` extension method on `IServiceProvider`. These extension methods are pretty common and conflict with other libraries. These methods can be recreated like this: + +```csharp +public static class Extensions +{ + public static bool IsNullOrEmpty(this IEnumerable enumerable) + => enumerable == null || !enumerable.Any(); + + public static ILogger CreateLogger(this IServiceProvider serviceProvider) + { + var loggerFactory = serviceProvider.GetRequiredService() ?? NullLoggerFactory.Instance; + return loggerFactory.CreateLogger(); + } +} +``` + +## Merge of `bunit.core` and `bunit.web` +The `bunit.core` and `bunit.web` packages have been merged into a single `bunit` package. If you used either of these packages, you should remove them and install the `bunit` package instead. + +## Removal of unneeded abstraction + +### `IRenderedComponentBase` and `RenderedFragmentBase` +`IRenderedComponentBase`, `IRenderedComponent`, `RenderedFragmentBase`, `RenderedFragment` and `RenderedFragmentBase` have been removed. +If you used either of these types, you should replace them with `RenderedComponent` or `RenderedFragment` respectively. + +### `WebTestRender` merged into `BunitTestRender` +The `WebTestRender` class has been merged into the `TestRender` class. If you used `WebTestRender`, you should replace it with `BunitTestRender`. + +## Renamed `Fake` to `Bunit` in many test doubles +The `Fake` prefix has been replaced with `Bunit` in many test doubles. For example, `FakeNavigationManager` is now `BunitNavigationManager`. If you reference any of these types explicitly, you need to update your code. + +### Renamed `AddTestAuthorization` to `AddAuthorization` +The `AddTestAuthorization` method on `BunitContext` has been renamed to `AddAuthorization`. If you used `AddTestAuthorization`, you should replace it with `AddAuthorization`. + +## Merged `BunitContext` and `BunitContextBase` +The `BunitContext` and `BunitContextBase` classes have been merged into a single `BunitContext` class. All references to `BunitContextBase` should replace them with `BunitContext` to migrate. + +## Renamed all `RenderComponent` and `SetParametersAndRender` to `Render` +To make the API more consistent, `RenderComponent` and `SetParametersAndRender` methods have been renamed to `Render`. + +## Removal of `ComponentParameter` and method using them +Using `ComponentParameter` and factory methods to create them is not recommend in V1 and have now been removed in V2. Instead, use the strongly typed builder pattern that enables you to pass parameters to components you render. + +## `BunitContext` implements `IDisposable` and `IAsyncDisposable` +The `BunitContext` now implements `IDisposable` and `IAsyncDisposable`. In version 1.x, `BunitContext` only implemented `IDisposable` and cleaned up asynchronous objects in the synchronous `Dispose` method. This is no longer the case, and asynchronous objects are now cleaned up in the `DisposeAsync` method. +If you register services into the container that implement `IAsyncDisposable` make sure that the test framework calls the right method. + +## `TestContext` was renamed to `BunitContext` +The `TestContext` class has been renamed to `BunitContext`. If you used `TestContext`, you should replace it with `BunitContext`. + +## `TestContextWrapper` was removed +The `TestContextWrapper` class has been removed. Either use lifecycle events of the testing framework (like `LifeCycle.InstancePerTestCase` in NUnit). +```csharp +[FixtureLifeCycle(LifeCycle.InstancePerTestCase)] +public class HelloWorldInstancePerTestCase : Bunit.TestContext +{ + [Test] + public void HelloWorldComponentRendersCorrectly() + { + // Act + var cut = RenderComponent(); + + // Assert + cut.MarkupMatches("

Hello world from Blazor

"); + } +} +``` + +Or use the `BunitContext` directly and manage the lifecycle yourself. + +## `TestServiceProvider` renamed to `BunitTestServiceProvider` +The `TestServiceProvider` class has been renamed to `BunitTestServiceProvider`. If you used `TestServiceProvider`, you should replace it with `BunitTestServiceProvider`. + +## `DisposeComponents` is now asynchronous and called `DisposeComponentsAsync` +`DisposeComponentsAsync` allows to await `DisposeAsync` of components under test. If you used `DisposeComponents`, you should replace it with `DisposeComponentsAsync`. diff --git a/README.md b/README.md index 2d9170d9f..a98b1ee86 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![GitHub tag](https://img.shields.io/github/v/tag/bUnit-dev/bUnit?include_prereleases&logo=github&style=flat-square)](https://github.com/bUnit-dev/bUnit/releases) -[![Nuget](https://img.shields.io/nuget/dt/bunit.core?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) +[![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) [![Issues Open](https://img.shields.io/github/issues/bUnit-dev/bUnit.svg?style=flat-square&logo=github)](https://github.com/bUnit-dev/bUnit/issues) # bUnit - a testing library for Blazor components @@ -12,7 +12,7 @@ - Pass parameters, cascading values and inject services into components under test - Mock `IJSRuntime`, Blazor authentication and authorization, and others -bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, and MSTest, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run. +bUnit builds on top of existing unit testing frameworks such as xUnit, NUnit, MSTest and TUnit, which run the Blazor component tests in just the same way as any normal unit test. bUnit runs a test in milliseconds, compared to browser-based UI tests which usually take seconds to run. **Go to [bUnit.dev](https://bunit.dev) to learn more.** @@ -22,15 +22,21 @@ bUnit is available on NuGet in various incarnations. Most should just pick the [ | Name | Description | NuGet Download Link | | ----- | ----- | ---- | -| [bUnit](https://www.nuget.org/packages/bunit/) | Includes the bUnit.core and bUnit.web packages. | [![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) | -| [bUnit.core](https://www.nuget.org/packages/bunit.core/) | Core library that enables rendering a Blazor component in a test context. | [![Nuget](https://img.shields.io/nuget/dt/bunit.core?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.core/) | -| [bUnit.web](https://www.nuget.org/packages/bunit.web/) | Adds support for testing Blazor components for the web. This includes bUnit.core. | [![Nuget](https://img.shields.io/nuget/dt/bunit.web?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web/) | +| [bUnit](https://www.nuget.org/packages/bunit/) | Adds support for testing Blazor components. | [![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) | | [bUnit.template](https://www.nuget.org/packages/bunit.template/) | Template, which currently creates xUnit-based bUnit test projects only. | [![Nuget](https://img.shields.io/nuget/dt/bunit.template?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.template/) | | [bUnit.generators](https://www.nuget.org/packages/bunit.generators/)|Source code generators to minimize code setup in various situations.|[![Nuget](https://img.shields.io/nuget/dt/bunit.generators?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.generators/)| | [bUnit.web.query](https://www.nuget.org/packages/bunit.web.query/)|bUnit implementation of testing-library.com's query APIs.|[![Nuget](https://img.shields.io/nuget/dt/bunit.web.query?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web.query/)| To get started, head to the [getting started documentation](https://bunit.dev/docs/getting-started) to learn more. +## bUnit and .NET version compatibility matrix +| bUnit version | .NET version | +| ------------- | ------------------------------- | +| 1.x | ≥ .netcore3.1 && ≤ .net 9 | +| 2.x | ≥ .net8 | + +For a migration guide, see [Upgrading bUnit](https://bunit.dev/docs/migrations/index.html). + ## Sponsors A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). The higher tier sponsors are: diff --git a/benchmark/Directory.Build.props b/benchmark/Directory.Build.props deleted file mode 100644 index 27b0bf9c3..000000000 --- a/benchmark/Directory.Build.props +++ /dev/null @@ -1,11 +0,0 @@ - - - - CA1014,NU5104 - false - - - full - true - - diff --git a/benchmark/bunit.benchmarks.assets/Counter.razor b/benchmark/bunit.benchmarks.assets/Counter.razor deleted file mode 100644 index 381411d2a..000000000 --- a/benchmark/bunit.benchmarks.assets/Counter.razor +++ /dev/null @@ -1,21 +0,0 @@ -@page "/counter" - -

Counter - Example

- -

This is not the real counter example but a bit adopted to have more stuff in it.

-
- Look mum I am centered -
- -

Current count: @currentCount

- - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} \ No newline at end of file diff --git a/benchmark/bunit.benchmarks.assets/bunit.benchmarks.assets.csproj b/benchmark/bunit.benchmarks.assets/bunit.benchmarks.assets.csproj deleted file mode 100644 index 2362cb400..000000000 --- a/benchmark/bunit.benchmarks.assets/bunit.benchmarks.assets.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - diff --git a/benchmark/bunit.benchmarks/Benchmark.cs b/benchmark/bunit.benchmarks/Benchmark.cs deleted file mode 100644 index 343f305fa..000000000 --- a/benchmark/bunit.benchmarks/Benchmark.cs +++ /dev/null @@ -1,14 +0,0 @@ -using BenchmarkDotNet.Attributes; -using bunit.benchmarks.assets; - -namespace Bunit; - -[MemoryDiagnoser] -public class Benchmark : BenchmarkBase -{ - [Benchmark] - public IRenderedComponentBase RenderCounter() - { - return RenderComponent(); - } -} \ No newline at end of file diff --git a/benchmark/bunit.benchmarks/BenchmarkBase.cs b/benchmark/bunit.benchmarks/BenchmarkBase.cs deleted file mode 100644 index f45d26972..000000000 --- a/benchmark/bunit.benchmarks/BenchmarkBase.cs +++ /dev/null @@ -1,47 +0,0 @@ -using BenchmarkDotNet.Attributes; -using Bunit.Rendering; -using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging.Abstractions; - -namespace Bunit; - -public abstract class BenchmarkBase -{ - private static readonly ComponentParameterCollection EmptyParameter = new(); - private readonly ServiceCollection services = new(); - - protected TestRenderer Renderer { get; private set; } = default!; - - [GlobalSetup] - public void Setup() - { - RegisterServices(services); - - var serviceProvider = services.BuildServiceProvider(); - Renderer = new TestRenderer( - new RenderedComponentActivator(serviceProvider), - new TestServiceProvider(services), - new NullLoggerFactory()); - } - - [GlobalCleanup] - public void Cleanup() - { - InternalCleanup(); - Renderer.Dispose(); - } - - protected IRenderedComponentBase RenderComponent() - where TComponent : IComponent => - Renderer.RenderComponent(EmptyParameter); - - protected virtual void InternalCleanup() - { - } - - protected virtual void RegisterServices(IServiceCollection serviceCollection) - { - services.AddSingleton(); - } -} \ No newline at end of file diff --git a/benchmark/bunit.benchmarks/Program.cs b/benchmark/bunit.benchmarks/Program.cs deleted file mode 100644 index 18d11e89b..000000000 --- a/benchmark/bunit.benchmarks/Program.cs +++ /dev/null @@ -1,6 +0,0 @@ -// See https://aka.ms/new-console-template for more information - -using BenchmarkDotNet.Running; -using Bunit; - -BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).RunAll(); diff --git a/benchmark/bunit.benchmarks/bunit.benchmarks.csproj b/benchmark/bunit.benchmarks/bunit.benchmarks.csproj deleted file mode 100644 index 15a876547..000000000 --- a/benchmark/bunit.benchmarks/bunit.benchmarks.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net6.0 - enable - false - - - - - - - - - - - - - diff --git a/bunit.sln b/bunit.sln index 2a6f50753..e5b5294d4 100644 --- a/bunit.sln +++ b/bunit.sln @@ -33,20 +33,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".text", ".text", "{392FCD4E ProjectSection(SolutionItems) = preProject CHANGELOG.md = CHANGELOG.md README.md = README.md + MIGRATION.md = MIGRATION.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.core.tests", "tests\bunit.core.tests\bunit.core.tests.csproj", "{3A1486BF-1029-4E5B-A79B-2D36C8152240}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit", "src\bunit\bunit.csproj", "{1DA6EFDE-81A1-4324-A56C-40BEE14A75BA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.core", "src\bunit.core\bunit.core.csproj", "{0C51D12D-A562-4229-B653-78B14960345C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web", "src\bunit.web\bunit.web.csproj", "{C91AE830-FFB5-49A9-A604-3F68B44EBCDC}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.template", "src\bunit.template\bunit.template.csproj", "{6127D121-9387-451B-B15D-8350A32D3001}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.tests", "tests\bunit.web.tests\bunit.web.tests.csproj", "{FC122F63-8B22-4BAE-B96A-7AF3194CD204}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.testassets", "tests\bunit.testassets\bunit.testassets.csproj", "{7972A80F-30DC-4EF4-9294-7D4DD2965882}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".workflows", ".workflows", "{3B2F3419-5336-4147-A212-E19091195203}" @@ -54,7 +47,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".workflows", ".workflows", .github\workflows\ci.yml = .github\workflows\ci.yml .github\workflows\docs-deploy.yml = .github\workflows\docs-deploy.yml .github\workflows\prepare-release.yml = .github\workflows\prepare-release.yml - .github\workflows\release-preview.yml = .github\workflows\release-preview.yml .github\workflows\release.yml = .github\workflows\release.yml EndProjectSection EndProject @@ -64,32 +56,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.query.tests", "te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.generators.internal", "src\bunit.generators.internal\bunit.generators.internal.csproj", "{AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.generators", "src\bunit.generators\bunit.generators.csproj", "{A7C6A2AA-FF8F-4ED1-8590-5324FC566059}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bunit.tests", "tests\bunit.tests\bunit.tests.csproj", "{56889DE7-5E66-4E9C-815B-CBCFC9961612}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bunit.generators.tests", "tests\bunit.generators.tests\bunit.generators.tests.csproj", "{D08F7F1D-74B1-4A76-86A2-94918863740C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3A1486BF-1029-4E5B-A79B-2D36C8152240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A1486BF-1029-4E5B-A79B-2D36C8152240}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3A1486BF-1029-4E5B-A79B-2D36C8152240}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A1486BF-1029-4E5B-A79B-2D36C8152240}.Release|Any CPU.Build.0 = Release|Any CPU {1DA6EFDE-81A1-4324-A56C-40BEE14A75BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1DA6EFDE-81A1-4324-A56C-40BEE14A75BA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0C51D12D-A562-4229-B653-78B14960345C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0C51D12D-A562-4229-B653-78B14960345C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0C51D12D-A562-4229-B653-78B14960345C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0C51D12D-A562-4229-B653-78B14960345C}.Release|Any CPU.Build.0 = Release|Any CPU - {C91AE830-FFB5-49A9-A604-3F68B44EBCDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C91AE830-FFB5-49A9-A604-3F68B44EBCDC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C91AE830-FFB5-49A9-A604-3F68B44EBCDC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C91AE830-FFB5-49A9-A604-3F68B44EBCDC}.Release|Any CPU.Build.0 = Release|Any CPU + {1DA6EFDE-81A1-4324-A56C-40BEE14A75BA}.Release|Any CPU.Build.0 = Release|Any CPU + {1DA6EFDE-81A1-4324-A56C-40BEE14A75BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {6127D121-9387-451B-B15D-8350A32D3001}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6127D121-9387-451B-B15D-8350A32D3001}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC122F63-8B22-4BAE-B96A-7AF3194CD204}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC122F63-8B22-4BAE-B96A-7AF3194CD204}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC122F63-8B22-4BAE-B96A-7AF3194CD204}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC122F63-8B22-4BAE-B96A-7AF3194CD204}.Release|Any CPU.Build.0 = Release|Any CPU {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Debug|Any CPU.Build.0 = Debug|Any CPU {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -106,21 +90,32 @@ Global {AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F}.Release|Any CPU.Build.0 = Release|Any CPU + {A7C6A2AA-FF8F-4ED1-8590-5324FC566059}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7C6A2AA-FF8F-4ED1-8590-5324FC566059}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7C6A2AA-FF8F-4ED1-8590-5324FC566059}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7C6A2AA-FF8F-4ED1-8590-5324FC566059}.Release|Any CPU.Build.0 = Release|Any CPU + {56889DE7-5E66-4E9C-815B-CBCFC9961612}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56889DE7-5E66-4E9C-815B-CBCFC9961612}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56889DE7-5E66-4E9C-815B-CBCFC9961612}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56889DE7-5E66-4E9C-815B-CBCFC9961612}.Release|Any CPU.Build.0 = Release|Any CPU + {D08F7F1D-74B1-4A76-86A2-94918863740C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D08F7F1D-74B1-4A76-86A2-94918863740C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D08F7F1D-74B1-4A76-86A2-94918863740C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D08F7F1D-74B1-4A76-86A2-94918863740C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {3A1486BF-1029-4E5B-A79B-2D36C8152240} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {1DA6EFDE-81A1-4324-A56C-40BEE14A75BA} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} - {0C51D12D-A562-4229-B653-78B14960345C} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} - {C91AE830-FFB5-49A9-A604-3F68B44EBCDC} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} {6127D121-9387-451B-B15D-8350A32D3001} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} - {FC122F63-8B22-4BAE-B96A-7AF3194CD204} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {7972A80F-30DC-4EF4-9294-7D4DD2965882} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {0FF92169-7D8F-46A2-8327-A2F028CB426F} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} {DE975A0C-0672-4248-913E-D267C1001801} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} + {A7C6A2AA-FF8F-4ED1-8590-5324FC566059} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} + {56889DE7-5E66-4E9C-815B-CBCFC9961612} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} + {D08F7F1D-74B1-4A76-86A2-94918863740C} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {24106918-1C86-4769-BDA6-9C80E64CD260} diff --git a/docs/samples/components/AsyncComponentLoader.razor b/docs/samples/components/AsyncComponentLoader.razor new file mode 100644 index 000000000..ba25e59f0 --- /dev/null +++ b/docs/samples/components/AsyncComponentLoader.razor @@ -0,0 +1,24 @@ +@if (isLoading) +{ +

Loading...

+} +else +{ + @foreach (var item in Items) + { + + } +} + +@code { + [Parameter] public List Items { get; set; } = new(); + + private bool isLoading = true; + + protected override async Task OnInitializedAsync() + { + // Simulate async loading + await Task.Delay(100); + isLoading = false; + } +} diff --git a/docs/samples/components/AsyncDisposableComponent.razor b/docs/samples/components/AsyncDisposableComponent.razor new file mode 100644 index 000000000..0d3851b3e --- /dev/null +++ b/docs/samples/components/AsyncDisposableComponent.razor @@ -0,0 +1,10 @@ +@using Microsoft.JSInterop +@implements IAsyncDisposable +@inject IJSRuntime JSRuntime +@code { + + public async ValueTask DisposeAsync() + { + await JSRuntime.InvokeVoidAsync("dispose"); + } +} diff --git a/docs/samples/components/ListItem.razor b/docs/samples/components/ListItem.razor new file mode 100644 index 000000000..76dfd5d42 --- /dev/null +++ b/docs/samples/components/ListItem.razor @@ -0,0 +1,5 @@ +
@Value
+ +@code { + [Parameter] public string Value { get; set; } = string.Empty; +} diff --git a/docs/samples/components/bunit.docs.samples.csproj b/docs/samples/components/bunit.docs.samples.csproj index 5bc4c1ae9..8d0c766a6 100644 --- a/docs/samples/components/bunit.docs.samples.csproj +++ b/docs/samples/components/bunit.docs.samples.csproj @@ -1,8 +1,7 @@ - net8.0 - latest + net8.0;net9.0;net10.0 Bunit.Docs.Samples enable CA1014,NU5104 diff --git a/docs/samples/myfile.json b/docs/samples/myfile.json deleted file mode 100644 index 72ec0a029..000000000 --- a/docs/samples/myfile.json +++ /dev/null @@ -1,20 +0,0 @@ -'packages' was not matched. Did you mean one of the following? -package - -Description: - List references or packages of a .NET project. - -Usage: - dotnet list [] [command] [options] - -Arguments: - The project or solution file to operate on. If a file is not specified, the command will search the current - directory for one. [default: /Users/stevengiesel/repos/bUnit/docs/samples/] - -Options: - -?, -h, --help Show command line help. - -Commands: - package List all package references of the project or solution. - reference List all project-to-project references of the project. - diff --git a/docs/samples/tests/Directory.Build.props b/docs/samples/tests/Directory.Build.props index b79778dbc..487c917d1 100644 --- a/docs/samples/tests/Directory.Build.props +++ b/docs/samples/tests/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net8.0;net9.0;net10.0 false true false diff --git a/docs/samples/tests/mstest/BunitTestContext.cs b/docs/samples/tests/mstest/BunitTestContext.cs deleted file mode 100644 index 2dad801cf..000000000 --- a/docs/samples/tests/mstest/BunitTestContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Bunit.Docs.Samples; - -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Bunit; - -public abstract class BunitTestContext : TestContextWrapper -{ - [TestInitialize] - public void Setup() => TestContext = new Bunit.TestContext(); - - [TestCleanup] - public void TearDown() => TestContext?.Dispose(); -} \ No newline at end of file diff --git a/docs/samples/tests/mstest/HelloWorldExplicitContextTest.cs b/docs/samples/tests/mstest/HelloWorldExplicitContextTest.cs index 32734e2fe..e7f2aebab 100644 --- a/docs/samples/tests/mstest/HelloWorldExplicitContextTest.cs +++ b/docs/samples/tests/mstest/HelloWorldExplicitContextTest.cs @@ -10,10 +10,10 @@ public class HelloWorldExplicitContext public void HelloWorldComponentRendersCorrectly() { // Arrange - using var ctx = new Bunit.TestContext(); + using var ctx = new Bunit.BunitContext(); // Act - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); // Assert cut.MarkupMatches("

Hello world from Blazor

"); diff --git a/docs/samples/tests/mstest/HelloWorldRazorTest.razor b/docs/samples/tests/mstest/HelloWorldRazorTest.razor index f821bd1ab..12b56f0ff 100644 --- a/docs/samples/tests/mstest/HelloWorldRazorTest.razor +++ b/docs/samples/tests/mstest/HelloWorldRazorTest.razor @@ -1,5 +1,5 @@ @attribute [TestClass] -@inherits BunitTestContext +@inherits BunitContext @code { [TestMethod] diff --git a/docs/samples/tests/mstest/HelloWorldTest.cs b/docs/samples/tests/mstest/HelloWorldTest.cs index 13c8f69c7..f2f08e7d4 100644 --- a/docs/samples/tests/mstest/HelloWorldTest.cs +++ b/docs/samples/tests/mstest/HelloWorldTest.cs @@ -4,13 +4,13 @@ namespace Bunit.Docs.Samples; using Bunit; [TestClass] -public class HelloWorldTest : BunitTestContext +public class HelloWorldTest : BunitContext { [TestMethod] public void HelloWorldComponentRendersCorrectly() { // Act - var cut = RenderComponent(); + var cut = Render(); // Assert cut.MarkupMatches("

Hello world from Blazor

"); diff --git a/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj b/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj index 3dc4399a2..a9289f90c 100644 --- a/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj +++ b/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj @@ -17,7 +17,7 @@
- + diff --git a/docs/samples/tests/nunit/BunitTestContext.cs b/docs/samples/tests/nunit/BunitTestContext.cs deleted file mode 100644 index 00dd5f7d0..000000000 --- a/docs/samples/tests/nunit/BunitTestContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Bunit.Docs.Samples; - -using Bunit; -using NUnit.Framework; - -public abstract class BunitTestContext : TestContextWrapper -{ - [SetUp] - public void Setup() => TestContext = new Bunit.TestContext(); - - [TearDown] - public void TearDown() => TestContext?.Dispose(); -} \ No newline at end of file diff --git a/docs/samples/tests/nunit/HelloWorldExplicitContextTest.cs b/docs/samples/tests/nunit/HelloWorldExplicitContextTest.cs index a35a15f7d..fede764e6 100644 --- a/docs/samples/tests/nunit/HelloWorldExplicitContextTest.cs +++ b/docs/samples/tests/nunit/HelloWorldExplicitContextTest.cs @@ -9,10 +9,10 @@ public class HelloWorldExplicitContext public void HelloWorldComponentRendersCorrectly() { // Arrange - using var ctx = new Bunit.TestContext(); + using var ctx = new Bunit.BunitContext(); // Act - var cut = ctx.RenderComponent(); + var cut = ctx.Render(); // Assert cut.MarkupMatches("

Hello world from Blazor

"); diff --git a/docs/samples/tests/nunit/HelloWorldInstancePerTestCase.cs b/docs/samples/tests/nunit/HelloWorldInstancePerTestCase.cs index 95f6edd23..562823627 100644 --- a/docs/samples/tests/nunit/HelloWorldInstancePerTestCase.cs +++ b/docs/samples/tests/nunit/HelloWorldInstancePerTestCase.cs @@ -3,13 +3,13 @@ namespace Bunit.Docs.Samples; [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] -public class HelloWorldInstancePerTestCase : Bunit.TestContext +public class HelloWorldInstancePerTestCase : Bunit.BunitContext { [Test] public void HelloWorldComponentRendersCorrectly() { // Act - var cut = RenderComponent(); + var cut = Render(); // Assert cut.MarkupMatches("

Hello world from Blazor

"); diff --git a/docs/samples/tests/nunit/HelloWorldRazorInstancePerTestCase.razor b/docs/samples/tests/nunit/HelloWorldRazorInstancePerTestCase.razor index 4685d907d..fec14a60d 100644 --- a/docs/samples/tests/nunit/HelloWorldRazorInstancePerTestCase.razor +++ b/docs/samples/tests/nunit/HelloWorldRazorInstancePerTestCase.razor @@ -1,5 +1,5 @@ @attribute [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] -@inherits Bunit.TestContext +@inherits Bunit.BunitContext @code { [Test] diff --git a/docs/samples/tests/nunit/HelloWorldRazorTest.razor b/docs/samples/tests/nunit/HelloWorldRazorTest.razor index 6de4ac4f4..ac54446f1 100644 --- a/docs/samples/tests/nunit/HelloWorldRazorTest.razor +++ b/docs/samples/tests/nunit/HelloWorldRazorTest.razor @@ -1,4 +1,4 @@ -@inherits BunitTestContext +@inherits BunitContext @code { [Test] diff --git a/docs/samples/tests/nunit/HelloWorldTest.cs b/docs/samples/tests/nunit/HelloWorldTest.cs index d8ad7011d..74ce9aa4c 100644 --- a/docs/samples/tests/nunit/HelloWorldTest.cs +++ b/docs/samples/tests/nunit/HelloWorldTest.cs @@ -3,13 +3,13 @@ namespace Bunit.Docs.Samples; using Bunit; using NUnit.Framework; -public class HelloWorldTest : BunitTestContext +public class HelloWorldTest : BunitContext { [Test] public void HelloWorldComponentRendersCorrectly() { // Act - var cut = RenderComponent(); + var cut = Render(); // Assert cut.MarkupMatches("

Hello world from Blazor

"); diff --git a/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj b/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj index f0b0211a4..9ec0d08a7 100644 --- a/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj +++ b/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj @@ -13,7 +13,7 @@
- + diff --git a/docs/samples/tests/razor/CascadingParams1Test.razor b/docs/samples/tests/razor/CascadingParams1Test.razor index db67f0142..d3db4114d 100644 --- a/docs/samples/tests/razor/CascadingParams1Test.razor +++ b/docs/samples/tests/razor/CascadingParams1Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/CascadingParams2Test.razor b/docs/samples/tests/razor/CascadingParams2Test.razor index 3dc8d73d0..b4251f8b7 100644 --- a/docs/samples/tests/razor/CascadingParams2Test.razor +++ b/docs/samples/tests/razor/CascadingParams2Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/CascadingParams3Test.razor b/docs/samples/tests/razor/CascadingParams3Test.razor index fa0f03812..c66a95bd7 100644 --- a/docs/samples/tests/razor/CascadingParams3Test.razor +++ b/docs/samples/tests/razor/CascadingParams3Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/ChildContentParams1Test.razor b/docs/samples/tests/razor/ChildContentParams1Test.razor index 18ee564e4..069c24e84 100644 --- a/docs/samples/tests/razor/ChildContentParams1Test.razor +++ b/docs/samples/tests/razor/ChildContentParams1Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/ChildContentParams2Test.razor b/docs/samples/tests/razor/ChildContentParams2Test.razor index 7ff765e5c..b1f2184f2 100644 --- a/docs/samples/tests/razor/ChildContentParams2Test.razor +++ b/docs/samples/tests/razor/ChildContentParams2Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/ChildContentParams3Test.razor b/docs/samples/tests/razor/ChildContentParams3Test.razor index 9e1041bc8..c802e92ee 100644 --- a/docs/samples/tests/razor/ChildContentParams3Test.razor +++ b/docs/samples/tests/razor/ChildContentParams3Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/ChildContentParams4Test.razor b/docs/samples/tests/razor/ChildContentParams4Test.razor index fb9751d92..dc2ce5beb 100644 --- a/docs/samples/tests/razor/ChildContentParams4Test.razor +++ b/docs/samples/tests/razor/ChildContentParams4Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/ClickMeTest.razor b/docs/samples/tests/razor/ClickMeTest.razor index 940aa5595..0534006e6 100644 --- a/docs/samples/tests/razor/ClickMeTest.razor +++ b/docs/samples/tests/razor/ClickMeTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/CounterTest.razor b/docs/samples/tests/razor/CounterTest.razor index 3f2e471a0..2ccc845be 100644 --- a/docs/samples/tests/razor/CounterTest.razor +++ b/docs/samples/tests/razor/CounterTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { [Fact] public void CounterShouldIncrementWhenClicked() diff --git a/docs/samples/tests/razor/EventCallbackParamsTest.razor b/docs/samples/tests/razor/EventCallbackParamsTest.razor index 02482b6ef..872d7a603 100644 --- a/docs/samples/tests/razor/EventCallbackParamsTest.razor +++ b/docs/samples/tests/razor/EventCallbackParamsTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/NestedComponentTest.razor b/docs/samples/tests/razor/NestedComponentTest.razor index 470a1b06c..007d17d8a 100644 --- a/docs/samples/tests/razor/NestedComponentTest.razor +++ b/docs/samples/tests/razor/NestedComponentTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/NonBlazorTypesParamsTest.razor b/docs/samples/tests/razor/NonBlazorTypesParamsTest.razor index af4f64dd6..3f87d42e8 100644 --- a/docs/samples/tests/razor/NonBlazorTypesParamsTest.razor +++ b/docs/samples/tests/razor/NonBlazorTypesParamsTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/RenderFragmentParams1Test.razor b/docs/samples/tests/razor/RenderFragmentParams1Test.razor index 0ffb568ca..efb31ff44 100644 --- a/docs/samples/tests/razor/RenderFragmentParams1Test.razor +++ b/docs/samples/tests/razor/RenderFragmentParams1Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/RenderFragmentParams2Test.razor b/docs/samples/tests/razor/RenderFragmentParams2Test.razor index ceb160a91..9df4c598d 100644 --- a/docs/samples/tests/razor/RenderFragmentParams2Test.razor +++ b/docs/samples/tests/razor/RenderFragmentParams2Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/RenderFragmentParams3Test.razor b/docs/samples/tests/razor/RenderFragmentParams3Test.razor index 36adadd33..a6e77cd08 100644 --- a/docs/samples/tests/razor/RenderFragmentParams3Test.razor +++ b/docs/samples/tests/razor/RenderFragmentParams3Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/RenderFragmentParams4Test.razor b/docs/samples/tests/razor/RenderFragmentParams4Test.razor index 0fa477306..6976927bc 100644 --- a/docs/samples/tests/razor/RenderFragmentParams4Test.razor +++ b/docs/samples/tests/razor/RenderFragmentParams4Test.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/TemplateParams1Test.razor b/docs/samples/tests/razor/TemplateParams1Test.razor index 612a27abb..857f34e99 100644 --- a/docs/samples/tests/razor/TemplateParams1Test.razor +++ b/docs/samples/tests/razor/TemplateParams1Test.razor @@ -1,16 +1,14 @@ -@inherits TestContext +@inherits BunitContext @code { -#if NET6_0 [Fact] public void Test() { var cut = Render(@ - - ); + + ); } -#endif } \ No newline at end of file diff --git a/docs/samples/tests/razor/TemplateParams2Test.razor b/docs/samples/tests/razor/TemplateParams2Test.razor index 3afcffd59..3b4754476 100644 --- a/docs/samples/tests/razor/TemplateParams2Test.razor +++ b/docs/samples/tests/razor/TemplateParams2Test.razor @@ -1,16 +1,14 @@ -@inherits TestContext +@inherits BunitContext @code { -#if NET6_0 [Fact] public void Test() { var cut = Render(@ - - ); + + ); } -#endif } \ No newline at end of file diff --git a/docs/samples/tests/razor/TwoWayBindingTest.razor b/docs/samples/tests/razor/TwoWayBindingTest.razor index 5edd20db1..c8be81db4 100644 --- a/docs/samples/tests/razor/TwoWayBindingTest.razor +++ b/docs/samples/tests/razor/TwoWayBindingTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { [Fact] diff --git a/docs/samples/tests/razor/UnmatchedParamsTest.razor b/docs/samples/tests/razor/UnmatchedParamsTest.razor index f52af243f..bb1568595 100644 --- a/docs/samples/tests/razor/UnmatchedParamsTest.razor +++ b/docs/samples/tests/razor/UnmatchedParamsTest.razor @@ -1,4 +1,4 @@ -@inherits TestContext +@inherits BunitContext @code { diff --git a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj index 50e257101..6dfff1e62 100644 --- a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj +++ b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj @@ -18,7 +18,7 @@
- + diff --git a/docs/samples/tests/xunit/AllKindsOfParamsTest.cs b/docs/samples/tests/xunit/AllKindsOfParamsTest.cs deleted file mode 100644 index 13179ddc5..000000000 --- a/docs/samples/tests/xunit/AllKindsOfParamsTest.cs +++ /dev/null @@ -1,342 +0,0 @@ -using Xunit; -using Bunit; -using System.Collections.Generic; -using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; -using Bunit.Rendering; -using static Bunit.ComponentParameterFactory; - -namespace Bunit.Docs.Samples; - -public class AllKindsOfParamsTest : TestContext -{ - [Fact] - public void NonBlazorParamTypes() - { - // Using C# tuple with hardcoded name - var cut1 = RenderComponent( - ("Numbers", 42), - ("Lines", new List { "Hello", "World" }) - ); - - // Using C# tuple with refactor safe name - var cut2 = RenderComponent( - (nameof(NonBlazorTypesParams.Numbers), 42), - (nameof(NonBlazorTypesParams.Lines), new List { "Hello", "World" }) - ); - - // Using factory method - var cut3 = RenderComponent( - Parameter("Numbers", 42), - Parameter("Lines", new List { "Hello", "World" }) - ); - - // Using parameter builder - var cut4 = RenderComponent(parameters => parameters - .Add(p => p.Numbers, 42) - .Add(p => p.Lines, new List { "Hello", "World" }) - ); - } - - [Fact] - public void EventCallbackTypes() - { - - // Using factory method with hardcoded name - var cut1 = RenderComponent( - EventCallback("OnClick", (MouseEventArgs args) => - { - /* handle callback */ - }), - EventCallback("OnSomething", () => - { - /* handle callback */ - }) - ); - - // Using factory method refactor safe name - var cut2 = RenderComponent( - EventCallback(nameof(EventCallbackParams.OnClick), (MouseEventArgs args) => - { - /* handle callback */ - }), - EventCallback(nameof(EventCallbackParams.OnSomething), () => - { - /* handle callback */ - }) - ); - - // Using parameter builder - var cut3 = RenderComponent(parameters => parameters - .Add(p => p.OnClick, args => - { - /* handle callback */ - }) - .Add(p => p.OnSomething, () => - { - /* handle callback */ - }) - ); - } - - [Fact] - public void HtmlAsChildContent() - { - // Using factory method - var cut1 = RenderComponent( - ChildContent("

Hello World

") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddChildContent("

Hello World

") - ); - } - - [Fact] - public void ComponentAsChildContent() - { - // Using factory method - var cut1 = RenderComponent( - ChildContent() - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddChildContent() - ); - } - - [Fact] - public void ComponentWithParamsAsChildContent() - { - // Using factory method - var cut1 = RenderComponent( - ChildContent( - ("Heading", "Alert heading"), - ("Type", AlertType.Warning), - ChildContent("

Hello World

") - ) - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddChildContent(alertParameters => alertParameters - .Add(p => p.Heading, "Alert heading") - .Add(p => p.Type, AlertType.Warning) - .AddChildContent("

Hello World

") - ) - ); - } - - [Fact] - public void ComponentAndMarkupAsChildContent() - { - // Using factory method - var cut1 = RenderComponent( - ChildContent("

Below you will find a most interesting alert!

"), - ChildContent( - ("Heading", "Alert heading"), - ("Type", AlertType.Warning), - ChildContent("

Hello World

") - ) - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddChildContent("

Below you will find a most interesting alert!

") - .AddChildContent(childParams => childParams - .Add(p => p.Heading, "Alert heading") - .Add(p => p.Type, AlertType.Warning) - .AddChildContent("

Hello World

") - ) - ); - } - - [Fact] - public void HtmlAsRenderFragment() - { - // Using factory method - var cut1 = RenderComponent( - RenderFragment("Content", "

Hello World

") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .Add(p => p.Content, "

Hello World

") - ); - } - - [Fact] - public void ComponentAsRenderFragment() - { - // Using factory method - var cut1 = RenderComponent( - RenderFragment("Content") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .Add(p => p.Content) - ); - } - - [Fact] - public void ComponentWithParamsAsRenderFragment() - { - // Using factory method - var cut1 = RenderComponent( - RenderFragment("Content", - ("Heading", "Alert heading"), - ("Type", AlertType.Warning), - ChildContent("

Hello World

") - ) - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .Add(p => p.Content, alertParameters => alertParameters - .Add(p => p.Heading, "Alert heading") - .Add(p => p.Type, AlertType.Warning) - .AddChildContent("

Hello World

") - ) - ); - } - - [Fact] - public void ComponentAndMarkupAsRenderFragment() - { - // Using factory method - var cut1 = RenderComponent( - RenderFragment("Content", "

Below you will find a most interesting alert!

"), - RenderFragment("Content", - ("Heading", "Alert heading"), - ("Type", AlertType.Warning), - ChildContent("

Hello World

") - ) - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .Add(p => p.Content, "

Below you will find a most interesting alert!

") - .Add(p => p.Content, childParams => childParams - .Add(p => p.Heading, "Alert heading") - .Add(p => p.Type, AlertType.Warning) - .AddChildContent("

Hello World

") - ) - ); - } - - [Fact] - public void HtmlTemplateParams() - { - // Using factory method - var cut1 = RenderComponent>( - ("Items", new string[] { "Foo", "Bar", "Baz" }), - Template("Template", item => $"{item}") - ); - - // Using parameter builder - var cut2 = RenderComponent>(parameters => parameters - .Add(p => p.Items, new[] { "Foo", "Bar", "Baz" }) - .Add(p => p.Template, item => $"{item}") - ); - } - - [Fact] - public void HtmlAndComponentTemplateParams() - { - // Using factory method - var cut1 = RenderComponent>( - ("Items", new string[] { "Foo", "Bar", "Baz" }), - Template("Template", value => new ComponentParameter[] - { - ("Value", value) - }) - ); - - // Using parameter builder - var cut2 = RenderComponent>(parameters => parameters - .Add(p => p.Items, new[] { "Foo", "Bar", "Baz" }) - .Add(p => p.Template, value => itemParams => itemParams - .Add(p => p.Value, value) - ) - ); - } - - [Fact] - public void UnmatchedParamsTest() - { - // Using factory method - var cut1 = RenderComponent( - ("some-unknown-param", "a value") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddUnmatched("some-unknown-param", "a value") - ); - } - - [Fact] - public void UnnamedCascadingParamsTest() - { - var isDarkTheme = true; - - // Using factory method - var cut1 = RenderComponent( - CascadingValue(isDarkTheme) - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddCascadingValue(isDarkTheme) - ); - - // Using parameter builder and selecting unnamed cascading parameter - var cut3 = RenderComponent(parameters => parameters - .Add(p => p.IsDarkTheme, isDarkTheme) - ); - } - - [Fact] - public void NamedCascadingParamsTest() - { - // Using factory method - var cut1 = RenderComponent( - CascadingValue("LoggedInUser", "Egil Hansen") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .Add(p => p.UserName, "Egil Hansen") - ); - } - - [Fact] - public void UnnamedAndNamedCascadingParamsTest() - { - var isDarkTheme = true; - - // Using factory method - var cut1 = RenderComponent( - CascadingValue(isDarkTheme), - CascadingValue("LoggedInUser", "Egil Hansen"), - CascadingValue("LoggedInEmail", "egil@example.com") - ); - - // Using parameter builder - var cut2 = RenderComponent(parameters => parameters - .AddCascadingValue(isDarkTheme) - .Add(p => p.UserName, "Egil Hansen") - .Add(p => p.Email, "egil@example.com") - ); - - // Using parameter builder and selecting unnamed cascading parameter - var cut3 = RenderComponent(parameters => parameters - .Add(p => p.IsDarkTheme, isDarkTheme) - .Add(p => p.UserName, "Egil Hansen") - .Add(p => p.Email, "egil@example.com") - ); - } -} \ No newline at end of file diff --git a/docs/samples/tests/xunit/AsyncDataTest.cs b/docs/samples/tests/xunit/AsyncDataTest.cs index edb90e0cc..676a780b4 100644 --- a/docs/samples/tests/xunit/AsyncDataTest.cs +++ b/docs/samples/tests/xunit/AsyncDataTest.cs @@ -6,14 +6,14 @@ namespace Bunit.Docs.Samples; -public class AsyncDataTest : TestContext +public class AsyncDataTest : BunitContext { [Fact] public void LoadDataAsync() { // Arrange var textService = new TaskCompletionSource(); - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.TextService, textService.Task) ); @@ -32,7 +32,7 @@ public void LoadDataAsyncWithTimeout() { // Arrange var textService = new TaskCompletionSource(); - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.TextService, textService.Task) ); @@ -51,7 +51,7 @@ public void LoadDataAsyncAssertion() { // Arrange var textService = new TaskCompletionSource(); - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.TextService, textService.Task) ); diff --git a/docs/samples/tests/xunit/CascadingParams1Test.cs b/docs/samples/tests/xunit/CascadingParams1Test.cs index a6816f45c..25285b32b 100644 --- a/docs/samples/tests/xunit/CascadingParams1Test.cs +++ b/docs/samples/tests/xunit/CascadingParams1Test.cs @@ -8,14 +8,14 @@ namespace Bunit.Docs.Samples; -public class CascadingParams1Test : TestContext +public class CascadingParams1Test : BunitContext { [Fact] public void Test() { var isDarkTheme = true; - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.IsDarkTheme, isDarkTheme) ); } diff --git a/docs/samples/tests/xunit/CascadingParams2Test.cs b/docs/samples/tests/xunit/CascadingParams2Test.cs index 2d72965e8..30f537acf 100644 --- a/docs/samples/tests/xunit/CascadingParams2Test.cs +++ b/docs/samples/tests/xunit/CascadingParams2Test.cs @@ -8,12 +8,12 @@ namespace Bunit.Docs.Samples; -public class CascadingParams2Test : TestContext +public class CascadingParams2Test : BunitContext { [Fact] public void Test() { - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.UserName, "Name of User") ); } diff --git a/docs/samples/tests/xunit/CascadingParams3Test.cs b/docs/samples/tests/xunit/CascadingParams3Test.cs index 23e736fff..4df60541a 100644 --- a/docs/samples/tests/xunit/CascadingParams3Test.cs +++ b/docs/samples/tests/xunit/CascadingParams3Test.cs @@ -8,14 +8,14 @@ namespace Bunit.Docs.Samples; -public class CascadingParams3Test : TestContext +public class CascadingParams3Test : BunitContext { [Fact] public void Test() { var isDarkTheme = true; - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .Add(p => p.IsDarkTheme, isDarkTheme) .Add(p => p.UserName, "Name of User") .Add(p => p.Email, "user@example.com") diff --git a/docs/samples/tests/xunit/ChildContentParams1Test.cs b/docs/samples/tests/xunit/ChildContentParams1Test.cs index 87299ec7b..f6c07a368 100644 --- a/docs/samples/tests/xunit/ChildContentParams1Test.cs +++ b/docs/samples/tests/xunit/ChildContentParams1Test.cs @@ -8,12 +8,12 @@ namespace Bunit.Docs.Samples; -public class ChildContentParams1Test : TestContext +public class ChildContentParams1Test : BunitContext { [Fact] public void Test() { - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .AddChildContent("

Hello World

") ); } diff --git a/docs/samples/tests/xunit/ChildContentParams2Test.cs b/docs/samples/tests/xunit/ChildContentParams2Test.cs index cc2e57c74..26835567d 100644 --- a/docs/samples/tests/xunit/ChildContentParams2Test.cs +++ b/docs/samples/tests/xunit/ChildContentParams2Test.cs @@ -8,12 +8,12 @@ namespace Bunit.Docs.Samples; -public class ChildContentParams2Test : TestContext +public class ChildContentParams2Test : BunitContext { [Fact] public void Test() { - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .AddChildContent() ); } diff --git a/docs/samples/tests/xunit/ChildContentParams3Test.cs b/docs/samples/tests/xunit/ChildContentParams3Test.cs index 58aaa4d98..a31e67954 100644 --- a/docs/samples/tests/xunit/ChildContentParams3Test.cs +++ b/docs/samples/tests/xunit/ChildContentParams3Test.cs @@ -8,12 +8,12 @@ namespace Bunit.Docs.Samples; -public class ChildContentParams3Test : TestContext +public class ChildContentParams3Test : BunitContext { [Fact] public void Test() { - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .AddChildContent(alertParameters => alertParameters .Add(p => p.Heading, "Alert heading") .Add(p => p.Type, AlertType.Warning) diff --git a/docs/samples/tests/xunit/ChildContentParams4Test.cs b/docs/samples/tests/xunit/ChildContentParams4Test.cs index cbbf4e0b6..b2c2477bb 100644 --- a/docs/samples/tests/xunit/ChildContentParams4Test.cs +++ b/docs/samples/tests/xunit/ChildContentParams4Test.cs @@ -8,12 +8,12 @@ namespace Bunit.Docs.Samples; -public class ChildContentParams4Test : TestContext +public class ChildContentParams4Test : BunitContext { [Fact] public void Test() { - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .AddChildContent("

Below you will find a most interesting alert!

") .AddChildContent(childParams => childParams .Add(p => p.Heading, "Alert heading") diff --git a/docs/samples/tests/xunit/ClickMeTest.cs b/docs/samples/tests/xunit/ClickMeTest.cs index 4e6a2186e..23b7284f2 100644 --- a/docs/samples/tests/xunit/ClickMeTest.cs +++ b/docs/samples/tests/xunit/ClickMeTest.cs @@ -4,13 +4,13 @@ namespace Bunit.Docs.Samples; -public class ClickMeTest : TestContext +public class ClickMeTest : BunitContext { [Fact] public void Test() { // Arrange - var cut = RenderComponent(); + var cut = Render(); var buttonElement = cut.Find("button"); // Act diff --git a/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs b/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs index b811e54a3..dfef6cfb2 100644 --- a/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs +++ b/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs @@ -1,12 +1,10 @@ -#if NET5_0_OR_GREATER - using Microsoft.AspNetCore.Components.Web; using Xunit; using Bunit; namespace Bunit.Docs.Samples { - public class ComponentFactoryExampleTest : TestContext + public class ComponentFactoryExampleTest : BunitContext { [Fact] public void ReplacesFooWithBarDuringTest() @@ -15,7 +13,7 @@ public void ReplacesFooWithBarDuringTest() ComponentFactories.Add(new FooBarComponentFactory()); // Act - var cut = RenderComponent(parameters => parameters + var cut = Render(parameters => parameters .AddChildContent()); // Assert that there are no in render tree, @@ -24,6 +22,4 @@ public void ReplacesFooWithBarDuringTest() Assert.Single(cut.FindComponents()); } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/docs/samples/tests/xunit/CounterTest.cs b/docs/samples/tests/xunit/CounterTest.cs index 366a3f5f4..2f76a42b0 100644 --- a/docs/samples/tests/xunit/CounterTest.cs +++ b/docs/samples/tests/xunit/CounterTest.cs @@ -3,13 +3,13 @@ namespace Bunit.Docs.Samples; -public class CounterTest : TestContext +public class CounterTest : BunitContext { [Fact] public void CounterShouldIncrementWhenClicked() { // Arrange: render the Counter.razor component - var cut = RenderComponent(); + var cut = Render(); // Act: find and click the