diff --git a/.editorconfig b/.editorconfig index 1ee6999e5..4c989e4aa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -453,6 +453,7 @@ dotnet_diagnostic.S112.severity = none # S112: General exceptions should never b dotnet_diagnostic.S1075.severity = suggestion # S1075: URIs should not be hardcoded 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.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 @@ -490,6 +491,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 06d6fb08b..2edfec9e2 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: @@ -44,10 +45,6 @@ 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 @@ -74,8 +71,6 @@ 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.generators/ -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 @@ -129,10 +124,6 @@ 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 @@ -207,10 +198,6 @@ 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 diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index e8ebf51f1..5460c6a55 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -72,10 +72,6 @@ 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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9172732d0..4aa8f9894 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,10 +57,6 @@ 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 @@ -99,8 +95,6 @@ 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 - name: 🛠️ Upload library to NuGet.org repository diff --git a/CHANGELOG.md b/CHANGELOG.md index 99cfcca00..f73620e34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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 @@ -670,7 +674,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 765ddd563..e2fa35c0b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,10 +2,6 @@ - 3.1.* - 5.0.* - 6.0.* - 7.0.* 8.0.* 9.0.0-* @@ -40,12 +36,12 @@ AllEnabledByDefault true - 7 + 8 true - + true @@ -56,7 +52,7 @@ + Condition="$(MSBuildProjectName) != 'bunit.template' AND $(MSBuildProjectName) != 'AngleSharpWrappers.Tests'"> 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 a1f0bb490..ff3bbd61f 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 @@ -29,9 +29,7 @@ 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/)| diff --git a/benchmark/Directory.Build.props b/benchmark/Directory.Build.props deleted file mode 100644 index 62cb9cc94..000000000 --- a/benchmark/Directory.Build.props +++ /dev/null @@ -1,14 +0,0 @@ - - - - enable - 10.0 - enable - 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 358670ae2..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 ffeb33523..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 4ce0606e1..9a284fd0b 100644 --- a/bunit.sln +++ b/bunit.sln @@ -31,20 +31,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}" @@ -52,19 +45,9 @@ 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 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{F6084D31-2A92-4794-A47E-A8F2254E6970}" - ProjectSection(SolutionItems) = preProject - benchmark\Directory.Build.props = benchmark\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.benchmarks", "benchmark\bunit.benchmarks\bunit.benchmarks.csproj", "{9F7A0623-8294-4A5D-946F-70C481732AA5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.benchmarks.assets", "benchmark\bunit.benchmarks.assets\bunit.benchmarks.assets.csproj", "{3619481F-DF6F-4399-9FED-450EE545A19E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.query", "src\bunit.web.query\bunit.web.query.csproj", "{0FF92169-7D8F-46A2-8327-A2F028CB426F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.query.tests", "tests\bunit.web.query.tests\bunit.web.query.tests.csproj", "{DE975A0C-0672-4248-913E-D267C1001801}" @@ -75,44 +58,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.generators.tests", "t 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 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 {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Release|Any CPU.Build.0 = Release|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Release|Any CPU.Build.0 = Release|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Release|Any CPU.Build.0 = Release|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -133,25 +96,24 @@ Global {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 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} - {9F7A0623-8294-4A5D-946F-70C481732AA5} = {F6084D31-2A92-4794-A47E-A8F2254E6970} - {3619481F-DF6F-4399-9FED-450EE545A19E} = {F6084D31-2A92-4794-A47E-A8F2254E6970} {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} {09046981-D9EC-4295-8502-721AC54E1F12} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {A7C6A2AA-FF8F-4ED1-8590-5324FC566059} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} + {56889DE7-5E66-4E9C-815B-CBCFC9961612} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {24106918-1C86-4769-BDA6-9C80E64CD260} 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/bunit.docs.samples.csproj b/docs/samples/components/bunit.docs.samples.csproj index aa97c0fe7..4617a87b1 100644 --- a/docs/samples/components/bunit.docs.samples.csproj +++ b/docs/samples/components/bunit.docs.samples.csproj @@ -1,47 +1,13 @@ - netstandard2.0;net5.0;net6.0;net7.0;net8.0;net9.0 - latest - 3.0 + net8.0;net9.0 Bunit.Docs.Samples enable CA1014,NU5104 false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/samples/tests/Directory.Build.props b/docs/samples/tests/Directory.Build.props index 8422a0457..8b4e7a76d 100644 --- a/docs/samples/tests/Directory.Build.props +++ b/docs/samples/tests/Directory.Build.props @@ -1,6 +1,6 @@ - netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + net8.0;net9.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 2d6428b0b..4bfdc389b 100644 --- a/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj +++ b/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj @@ -14,7 +14,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 a51a9ff84..0cd6ceefd 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 601c8a4c3..be87dd348 100644 --- a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj +++ b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj @@ -19,7 +19,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 580ab4096..3cce43104 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.Equal(1, cut.FindComponents().Count); } } -} - -#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