From 7cad632ed6d6ce0c985e3aec697a881ccaba5b77 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 22 Feb 2022 15:38:48 +0000 Subject: [PATCH 01/49] Set version to '1.7-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 63fa435b1..aa44cc1de 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.6-preview", + "version": "1.7-preview", "assemblyVersion": { "precision": "revision" }, From a162d40b6a20e70fced095f8df4bff86f3185ac3 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 22 Feb 2022 16:46:25 +0000 Subject: [PATCH 02/49] fix: dotnet push bug --- .github/workflows/release-preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-preview.yml b/.github/workflows/release-preview.yml index a10c48094..e8d4dd05d 100644 --- a/.github/workflows/release-preview.yml +++ b/.github/workflows/release-preview.yml @@ -50,8 +50,8 @@ jobs: dotnet pack src/bunit.template/ -c Release -o ${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - name: 🛠️ Upload library to GitHub Package Repository - run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/bunit-dev/index.json --skip-duplicate --no-symbols true + run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/bunit-dev/index.json --skip-duplicate --no-symbols - name: 🛠️ Upload library to NuGet.org repository if: github.event.inputs.nugetRelease == 'true' - run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/*.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols true + run: dotnet nuget push ${GITHUB_WORKSPACE}/packages/*.nupkg -k ${{ secrets.NUGET_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols From ea208f09fa35f7f3a14507673ea23c08f20adfcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Mar 2022 15:11:18 +0000 Subject: [PATCH 03/49] build(deps): bump Moq from 4.16.1 to 4.17.2 Bumps [Moq](https://github.com/moq/moq4) from 4.16.1 to 4.17.2. - [Release notes](https://github.com/moq/moq4/releases) - [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md) - [Commits](https://github.com/moq/moq4/compare/v4.16.1...v4.17.2) --- updated-dependencies: - dependency-name: Moq dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- tests/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index c30b70047..a5ad6b90d 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -17,7 +17,7 @@ - + From 98e562314eef3692d8c333ff35ecdb491a0a90a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Mar 2022 15:08:54 +0000 Subject: [PATCH 04/49] build(deps): bump SonarAnalyzer.CSharp from 8.35.0.42613 to 8.36.1.44192 Bumps SonarAnalyzer.CSharp from 8.35.0.42613 to 8.36.1.44192. --- updated-dependencies: - dependency-name: SonarAnalyzer.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3f5466258..63f02b805 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -48,7 +48,7 @@ - + From 73995ecf8da46184624dc7343dc046afd4f1b147 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Mar 2022 10:39:49 +0000 Subject: [PATCH 05/49] build(deps): bump Meziantou.Analyzer from 1.0.695 to 1.0.697 Bumps [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 1.0.695 to 1.0.697. - [Release notes](https://github.com/meziantou/Meziantou.Analyzer/releases) - [Commits](https://github.com/meziantou/Meziantou.Analyzer/commits) --- updated-dependencies: - dependency-name: Meziantou.Analyzer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 63f02b805..ca8610c20 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -47,7 +47,7 @@ - + From 8c35a4e99ada7b43d08f02942c5b71ed71657213 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 15 Mar 2022 15:45:31 +0100 Subject: [PATCH 06/49] fix: Change step by step guide to include setup of DocFx --- CHANGELOG.md | 3 +++ docs/README.md | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ff60c5c..c4786ba2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Fixed +- Fixed step by step guide for building and viewing the documentation locally. By [@linkdotnet](https://github.com/linkdotnet). + ## [1.6.4] - 2022-02-22 A quick minor release that primiarily fixes a regression in 1.5.12. diff --git a/docs/README.md b/docs/README.md index 2aa0756f2..d0839667c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,11 +18,19 @@ These sample components, source files, and tests source files are included in th ## Building and Viewing Docs Locally -To build and view the documentation locally, follow these steps: +The following chapter describes how you can run and view the documentation locally + +### Requirements +You will need the following tools installed: +* The [`dotnet serve` tool](https://github.com/natemcmaster/dotnet-serve) +* [DocFx](https://dotnet.github.io/docfx/tutorial/docfx_getting_started.html#2-use-docfx-as-a-command-line-tool) to generate the html files + +### View the documentation 1. From `docs/site` run `dotnet build`. If you get warnings from running `dotnet build`, try running it again. -2. From `docs/` run `serve-docs.cmd`. This will start up a local web server, hosting the generated documentation site on http://localhost:8080, using the [`dotnet serve` tool](https://github.com/natemcmaster/dotnet-serve). -3. After changing samples from `docs/samples`, run `dotnet test`. This will compile the sample components and run the sample tests. +2. From `docs/` run `docfx`. This will generate all the html site based on the markdown files. +3. From `docs/` run `serve-docs.cmd`. This will start up a local web server, hosting the generated documentation site. +4. After changing samples from `docs/samples`, run `dotnet test`. This will compile the sample components and run the sample tests. ## Documentation Writing Rules From 87482964ee34431a68dcac9c70cb32030fc396e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:12:27 +0000 Subject: [PATCH 07/49] build(deps): bump Meziantou.Analyzer from 1.0.697 to 1.0.698 Bumps [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 1.0.697 to 1.0.698. - [Release notes](https://github.com/meziantou/Meziantou.Analyzer/releases) - [Commits](https://github.com/meziantou/Meziantou.Analyzer/commits) --- updated-dependencies: - dependency-name: Meziantou.Analyzer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index ca8610c20..e0fc6c0ee 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -47,7 +47,7 @@ - + From b20cf4ce5f21c6c433060ceaa058bda050256066 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Sun, 3 Apr 2022 11:18:41 +0200 Subject: [PATCH 08/49] feat: add DisposeComponents to TestContext/TestRenderer Feature/detach testcontext base --- CHANGELOG.md | 3 + .../components/DisposableComponent.razor | 21 +++ .../ExceptionInDisposeAsyncComponent.razor | 8 + .../ExceptionInDisposeComponent.razor | 7 + .../tests/xunit/DisposeComponentsTest.cs | 49 ++++++ docs/samples/tests/xunit/RenderTreeTest.cs | 4 +- .../docs/interaction/dispose-components.md | 25 +++ docs/site/docs/interaction/index.md | 1 + docs/site/docs/toc.md | 1 + src/bunit.core/Rendering/FragmentContainer.cs | 2 +- src/bunit.core/Rendering/ITestRenderer.cs | 5 + .../{WrapperComponent.cs => RootComponent.cs} | 15 +- src/bunit.core/Rendering/TestRenderer.cs | 31 +++- src/bunit.core/TestContextBase.cs | 145 +++++++++--------- src/bunit.web/TestContextWrapper.cs | 5 + tests/bunit.core.tests/TestContextBaseTest.cs | 61 ++++++++ .../TestContextBaseTest.net5.cs | 75 ++++++++- .../DisposeComponents/ChildDispose.razor | 11 ++ .../DisposeComponents/DisposeFragments.razor | 8 + .../DisposeComponents/ParentDispose.razor | 13 ++ .../BlazorE2E/ComponentRenderingTest.cs | 3 +- 21 files changed, 406 insertions(+), 87 deletions(-) create mode 100644 docs/samples/components/DisposableComponent.razor create mode 100644 docs/samples/components/ExceptionInDisposeAsyncComponent.razor create mode 100644 docs/samples/components/ExceptionInDisposeComponent.razor create mode 100644 docs/samples/tests/xunit/DisposeComponentsTest.cs create mode 100644 docs/site/docs/interaction/dispose-components.md rename src/bunit.core/Rendering/{WrapperComponent.cs => RootComponent.cs} (50%) create mode 100644 tests/bunit.core.tests/TestContextBaseTest.cs create mode 100644 tests/bunit.testassets/SampleComponents/DisposeComponents/ChildDispose.razor create mode 100644 tests/bunit.testassets/SampleComponents/DisposeComponents/DisposeFragments.razor create mode 100644 tests/bunit.testassets/SampleComponents/DisposeComponents/ParentDispose.razor diff --git a/CHANGELOG.md b/CHANGELOG.md index c4786ba2b..5ca9a8892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Added +- Added `DisposeComponents` to `TestContextBase`. It will dispose and remove all components rendered by the `TestContextBase`. By [@linkdotnet](https://github.com/linkdotnet). + ### Fixed - Fixed step by step guide for building and viewing the documentation locally. By [@linkdotnet](https://github.com/linkdotnet). diff --git a/docs/samples/components/DisposableComponent.razor b/docs/samples/components/DisposableComponent.razor new file mode 100644 index 000000000..9ef793669 --- /dev/null +++ b/docs/samples/components/DisposableComponent.razor @@ -0,0 +1,21 @@ +@using Microsoft.AspNetCore.Components.Routing +@implements IDisposable +@inject NavigationManager NavigationManager +@code { + [Parameter] public Action LocationChangedCallback { get; set; } + + protected override void OnInitialized() + { + NavigationManager.LocationChanged += OnLocationChanged; + } + + public void Dispose() + { + NavigationManager.LocationChanged -= OnLocationChanged; + } + + private void OnLocationChanged(object sender, LocationChangedEventArgs e) + { + LocationChangedCallback(e.Location); + } +} \ No newline at end of file diff --git a/docs/samples/components/ExceptionInDisposeAsyncComponent.razor b/docs/samples/components/ExceptionInDisposeAsyncComponent.razor new file mode 100644 index 000000000..eabb32cc6 --- /dev/null +++ b/docs/samples/components/ExceptionInDisposeAsyncComponent.razor @@ -0,0 +1,8 @@ +@implements IAsyncDisposable +@code { + public async ValueTask DisposeAsync() + { + await Task.Delay(10); + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/docs/samples/components/ExceptionInDisposeComponent.razor b/docs/samples/components/ExceptionInDisposeComponent.razor new file mode 100644 index 000000000..8be8c9c6c --- /dev/null +++ b/docs/samples/components/ExceptionInDisposeComponent.razor @@ -0,0 +1,7 @@ +@implements IDisposable +@code { + public void Dispose() + { + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/docs/samples/tests/xunit/DisposeComponentsTest.cs b/docs/samples/tests/xunit/DisposeComponentsTest.cs new file mode 100644 index 000000000..87d64eb00 --- /dev/null +++ b/docs/samples/tests/xunit/DisposeComponentsTest.cs @@ -0,0 +1,49 @@ +using System; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace Bunit.Docs.Samples; + +public class DisposeComponentsTest +{ + [Fact] + public void DisposeElements() + { + using var ctx = new TestContext(); + var calledTimes = 0; + var cut = ctx.RenderComponent(parameters => parameters + .Add(p => p.LocationChangedCallback, url => calledTimes++) + ); + + ctx.DisposeComponents(); + + ctx.Services.GetRequiredService().NavigateTo("newurl"); + + Assert.Equal(0, calledTimes); + } + + [Fact] + public void ShouldCatchExceptionInDispose() + { + using var ctx = new TestContext(); + ctx.RenderComponent(); + + var act = ctx.DisposeComponents; + + Assert.Throws(act); + } + +#if NET5_0_OR_GREATER + [Fact] + public void ShouldCatchExceptionInDisposeAsync() + { + using var ctx = new TestContext(); + ctx.RenderComponent(); + + ctx.DisposeComponents(); + var exception = ctx.Renderer.UnhandledException.Result; + Assert.IsType(exception); + } +#endif +} \ No newline at end of file diff --git a/docs/samples/tests/xunit/RenderTreeTest.cs b/docs/samples/tests/xunit/RenderTreeTest.cs index ea81d3077..0d77e0424 100644 --- a/docs/samples/tests/xunit/RenderTreeTest.cs +++ b/docs/samples/tests/xunit/RenderTreeTest.cs @@ -19,7 +19,7 @@ public void PrintCascadingValueTest() .Add(p => p.Value, "FOO") ); - // The component will be rendered as a chld of last + // The component will be rendered as a child of last // component added to the RenderTree property. var cut = ctx.RenderComponent(); @@ -37,7 +37,7 @@ public void PrintCascadingValue2Test() .Add(p => p.Value, "BAR?") ); - // The component will be rendered as a chld of last + // The component will be rendered as a child of last // component added to the RenderTree property. var cut = ctx.RenderComponent(); diff --git a/docs/site/docs/interaction/dispose-components.md b/docs/site/docs/interaction/dispose-components.md new file mode 100644 index 000000000..a3c22385c --- /dev/null +++ b/docs/site/docs/interaction/dispose-components.md @@ -0,0 +1,25 @@ +--- +uid: dispose-components +title: Disposing components and their children +--- + +# Disposing components +To dispose all components rendered with a `TestContext`, use the [`DisposeComponents`](xref:Bunit.TestContextBase.DisposeComponents) method. Calling this method will dispose all rendered components, calling any `IDisposable.Dispose` or/and `IAsyncDisposable.DisposeAsync` methods they might have, and remove the components from the render tree, starting with the root components and then walking down the render tree to all the child components. + +Disposing rendered components enables testing of logic in `Dispose` methods, e.g., event handlers, that should be detached to avoid memory leaks. + +The following example of this: + +[!code-csharp[](../../../samples/tests/xunit/DisposeComponentsTest.cs#L13-L23)] + +> [!WARNING] +> For `IAsyncDisposable` (since .net5) relying on [`WaitForState()`](xref:Bunit.RenderedFragmentWaitForHelperExtensions.WaitForState(Bunit.IRenderedFragmentBase,System.Func{System.Boolean},System.Nullable{System.TimeSpan})) or [`WaitForAssertion()`](xref:Bunit.RenderedFragmentWaitForHelperExtensions.WaitForAssertion(Bunit.IRenderedFragmentBase,System.Action,System.Nullable{System.TimeSpan})) will not work as a disposed component will not trigger a new render cycle. + +## Checking for exceptions +`Dispose` as well as `DisposeAsync` can throw exceptions which can be asserted as well. If a component under test throws an exception in `Dispose` the [`DisposeComponents`](xref:Bunit.TestContextBase.DisposeComponents) will throw the exception to the user code: + +[!code-csharp[](../../../samples/tests/xunit/DisposeComponentsTest.cs#L29-L34)] + +`DisposeAsync` behaves a bit different. The following example will demonstrate how to assert an exception in `DisposeAsync`: + +[!code-csharp[](../../../samples/tests/xunit/DisposeComponentsTest.cs#L41-L46)] \ No newline at end of file diff --git a/docs/site/docs/interaction/index.md b/docs/site/docs/interaction/index.md index 6bbf51095..96e06fdde 100644 --- a/docs/site/docs/interaction/index.md +++ b/docs/site/docs/interaction/index.md @@ -10,3 +10,4 @@ This section covers the various ways to interact with a component under test, e. - **:** This covers how to invoke event handlers bound to elements rendered by a component under test. - **:** This covers how to manually trigger a render cycle for a component under test. - **:** This covers how to await one or more asynchronous changes to the state of a component under test before continuing the test. +- **:** This covers how to dispose components and their children. diff --git a/docs/site/docs/toc.md b/docs/site/docs/toc.md index eb1e025b7..2564fb3db 100644 --- a/docs/site/docs/toc.md +++ b/docs/site/docs/toc.md @@ -13,6 +13,7 @@ ## [Trigger event handlers](xref:trigger-event-handlers) ## [Trigger renders](xref:trigger-renders) ## [Awaiting an async state change](xref:awaiting-async-state) +## [Disposing components](xref:dispose-components) # [Verifying output](xref:verification) ## [Verify markup](xref:verify-markup) diff --git a/src/bunit.core/Rendering/FragmentContainer.cs b/src/bunit.core/Rendering/FragmentContainer.cs index 293182628..743d84e17 100644 --- a/src/bunit.core/Rendering/FragmentContainer.cs +++ b/src/bunit.core/Rendering/FragmentContainer.cs @@ -35,4 +35,4 @@ public static RenderFragment Wrap(RenderFragment wrappingTarget) builder.CloseComponent(); }; } -} +} \ No newline at end of file diff --git a/src/bunit.core/Rendering/ITestRenderer.cs b/src/bunit.core/Rendering/ITestRenderer.cs index c4d3bee97..ec8bb5357 100644 --- a/src/bunit.core/Rendering/ITestRenderer.cs +++ b/src/bunit.core/Rendering/ITestRenderer.cs @@ -73,4 +73,9 @@ IRenderedComponentBase FindComponent(IRenderedFragmentBa /// Parent component to search. IReadOnlyList> FindComponents(IRenderedFragmentBase parentComponent) where TComponent : IComponent; + + /// + /// Disposes all components rendered by the . + /// + public void DisposeComponents(); } diff --git a/src/bunit.core/Rendering/WrapperComponent.cs b/src/bunit.core/Rendering/RootComponent.cs similarity index 50% rename from src/bunit.core/Rendering/WrapperComponent.cs rename to src/bunit.core/Rendering/RootComponent.cs index 0d4c2a67b..1db4d190b 100644 --- a/src/bunit.core/Rendering/WrapperComponent.cs +++ b/src/bunit.core/Rendering/RootComponent.cs @@ -3,19 +3,18 @@ namespace Bunit.Rendering; /// /// Wrapper class that provides access to a . /// -internal sealed class WrapperComponent : IComponent +internal sealed class RootComponent : IComponent { private readonly RenderFragment renderFragment; private RenderHandle renderHandle; - public WrapperComponent(RenderFragment renderFragment) => this.renderFragment = renderFragment; + public RootComponent(RenderFragment renderFragment) => this.renderFragment = renderFragment; public void Attach(RenderHandle renderHandle) => this.renderHandle = renderHandle; - public Task SetParametersAsync(ParameterView parameters) => throw new InvalidOperationException($"WrapperComponent shouldn't receive any parameters"); + public Task SetParametersAsync(ParameterView parameters) => throw new InvalidOperationException($"{nameof(RootComponent)} shouldn't receive any parameters"); - public void Render() - { - renderHandle.Render(renderFragment); - } -} + public void Render() => renderHandle.Render(renderFragment); + + public void Detach() => renderHandle.Render(_ => { }); +} \ No newline at end of file diff --git a/src/bunit.core/Rendering/TestRenderer.cs b/src/bunit.core/Rendering/TestRenderer.cs index d269beb33..04992e0d7 100644 --- a/src/bunit.core/Rendering/TestRenderer.cs +++ b/src/bunit.core/Rendering/TestRenderer.cs @@ -10,6 +10,7 @@ public class TestRenderer : Renderer, ITestRenderer { private readonly object renderTreeAccessLock = new(); private readonly Dictionary renderedComponents = new(); + private readonly List rootComponents = new(); private readonly ILogger logger; private readonly IRenderedComponentActivator activator; private TaskCompletionSource unhandledExceptionTsc = new(); @@ -117,6 +118,31 @@ public IReadOnlyList> FindComponents FindComponents(parentComponent, int.MaxValue); + + /// + public void DisposeComponents() + { + // The dispatcher will always return a completed task, + // when dealing with an IAsyncDisposable. + // Therefore checking for a completed task and awaiting it + // will only work on IDisposable + var disposeTask = Dispatcher.InvokeAsync(() => + { + foreach (var root in rootComponents) + { + root.Detach(); + } + }); + + if (!disposeTask.IsCompleted) + { + disposeTask.GetAwaiter().GetResult(); + } + + rootComponents.Clear(); + AssertNoUnhandledExceptions(); + } + /// protected override void ProcessPendingRender() { @@ -214,10 +240,11 @@ private TResult Render(RenderFragment renderFragment, Func { - var root = new WrapperComponent(renderFragment); + var root = new RootComponent(renderFragment); var rootComponentId = AssignRootComponentId(root); var result = activator(rootComponentId); renderedComponents.Add(rootComponentId, result); + rootComponents.Add(root); root.Render(); return result; }); @@ -358,4 +385,4 @@ private void AssertNoUnhandledExceptions() } } } -} +} \ No newline at end of file diff --git a/src/bunit.core/TestContextBase.cs b/src/bunit.core/TestContextBase.cs index 860934bd2..a16d0319f 100644 --- a/src/bunit.core/TestContextBase.cs +++ b/src/bunit.core/TestContextBase.cs @@ -1,93 +1,100 @@ using Bunit.Rendering; -namespace Bunit +namespace Bunit; + +/// +/// A test context is a factory that makes it possible to create components under tests. +/// +public abstract class TestContextBase : IDisposable { + private bool disposed; + private ITestRenderer? testRenderer; + /// - /// A test context is a factory that makes it possible to create components under tests. + /// Gets the renderer used by the test context. /// - public abstract class TestContextBase : IDisposable + public ITestRenderer Renderer { - private bool disposed; - private ITestRenderer? testRenderer; - - /// - /// Gets the renderer used by the test context. - /// - public ITestRenderer Renderer + get { - get + if (testRenderer is null) { - if (testRenderer is null) - { - testRenderer = Services.GetRequiredService(); - } - - return testRenderer; + testRenderer = Services.GetRequiredService(); } + + return testRenderer; } + } - /// - /// Gets the service collection and service provider that is used when a - /// component is rendered by the test context. - /// - public TestServiceProvider Services { get; } + /// + /// Gets the service collection and service provider that is used when a + /// component is rendered by the test context. + /// + public TestServiceProvider Services { get; } - /// - /// Gets the that all components rendered with the - /// RenderComponent<TComponent>() methods, are rendered inside. - /// - /// - /// Use this to add default layout- or root-components which a component under test - /// should be rendered under. - /// - public RootRenderTree RenderTree { get; } = new(); + /// + /// Gets the that all components rendered with the + /// RenderComponent<TComponent>() methods, are rendered inside. + /// + /// + /// Use this to add default layout- or root-components which a component under test + /// should be rendered under. + /// + public RootRenderTree RenderTree { get; } = new(); #if NET5_0_OR_GREATER - /// - /// Gets the . Factories added to it - /// will be used to create components during testing, starting with the last added - /// factory. If no factories in the collection can create a requested component, - /// then the default Blazor factory is used. - /// - public ComponentFactoryCollection ComponentFactories { get; } = new(); + /// + /// Gets the . Factories added to it + /// will be used to create components during testing, starting with the last added + /// factory. If no factories in the collection can create a requested component, + /// then the default Blazor factory is used. + /// + public ComponentFactoryCollection ComponentFactories { get; } = new(); #endif - /// - /// Initializes a new instance of the class. - /// - protected TestContextBase() - { - Services = new TestServiceProvider(); + /// + /// Initializes a new instance of the class. + /// + protected TestContextBase() + { + Services = new TestServiceProvider(); #if NET5_0_OR_GREATER - Services.AddSingleton(new BunitComponentActivator(ComponentFactories)); + Services.AddSingleton(new BunitComponentActivator(ComponentFactories)); #endif - } + } - /// - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } + /// + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } - /// - /// Disposes of the test context resources. - /// - /// - /// The disposing parameter should be false when called from a finalizer, and true when called from the - /// method. In other words, it is true when deterministically called and false when non-deterministically called. - /// - /// Set to true if called from , false if called from a finalizer.f. - protected virtual void Dispose(bool disposing) - { - if (disposed || !disposing) - return; + /// + /// Disposes of the test context resources. + /// + /// + /// The disposing parameter should be false when called from a finalizer, and true when called from the + /// method. In other words, it is true when deterministically called and false when non-deterministically called. + /// + /// Set to true if called from , false if called from a finalizer.f. + protected virtual void Dispose(bool disposing) + { + if (disposed || !disposing) + return; - disposed = true; + disposed = true; - // The service provider should dispose of any - // disposable object it has created, when it is disposed. - Services.Dispose(); - } + // The service provider should dispose of any + // disposable object it has created, when it is disposed. + Services.Dispose(); + } + + /// + /// Disposes all components rendered via this . + /// + public void DisposeComponents() + { + Renderer.DisposeComponents(); } } diff --git a/src/bunit.web/TestContextWrapper.cs b/src/bunit.web/TestContextWrapper.cs index e41e41760..a6a9c57c0 100644 --- a/src/bunit.web/TestContextWrapper.cs +++ b/src/bunit.web/TestContextWrapper.cs @@ -78,6 +78,11 @@ public virtual IRenderedComponent Render(RenderFragment public virtual IRenderedFragment Render(RenderFragment renderFragment) => TestContext?.Render(renderFragment) ?? throw new InvalidOperationException("The TestContext has not been initialized."); + /// + /// Disposes all components rendered via this . + /// + public virtual void DisposeComponents() => TestContext?.DisposeComponents(); + /// /// Dummy method required to allow Blazor's compiler to generate /// C# from .razor files. diff --git a/tests/bunit.core.tests/TestContextBaseTest.cs b/tests/bunit.core.tests/TestContextBaseTest.cs new file mode 100644 index 000000000..e82ddbec8 --- /dev/null +++ b/tests/bunit.core.tests/TestContextBaseTest.cs @@ -0,0 +1,61 @@ +using Bunit.TestAssets.SampleComponents.DisposeComponents; + +namespace Bunit; + +public partial class TestContextBaseTest : TestContext +{ + [Fact(DisplayName = "DisposeComponents disposes rendered components in parent to child order")] + public void Test101() + { + var callStack = new List(); + RenderComponent(ps => ps.Add(p => p.CallStack, callStack)); + + DisposeComponents(); + + callStack.Count.ShouldBe(2); + callStack[0].ShouldBe("ParentDispose"); + callStack[1].ShouldBe("ChildDispose"); + } + + [Fact(DisplayName = "DisposeComponents disposes multiple rendered components")] + public void Test102() + { + var callStack = new List(); + RenderComponent(ps => ps.Add(p => p.CallStack, callStack)); + RenderComponent(ps => ps.Add(p => p.CallStack, callStack)); + + DisposeComponents(); + + callStack.Count.ShouldBe(2); + } + + [Fact(DisplayName = "DisposeComponents rethrows exceptions from Dispose methods in components")] + public void Test103() + { + RenderComponent(); + var action = () => DisposeComponents(); + + action.ShouldThrow(); + } + + [Fact(DisplayName = "DisposeComponents disposes components nested in render fragments")] + public void Test104() + { + var callStack = new List(); + Render(DisposeFragments.ChildDisposeAsFragment(callStack)); + + DisposeComponents(); + + callStack.Count.ShouldBe(1); + } + + private sealed class ThrowExceptionComponent : ComponentBase, IDisposable + { + public void Dispose() + { +#pragma warning disable S3877 + throw new NotSupportedException(); +#pragma warning restore S3877 + } + } +} diff --git a/tests/bunit.core.tests/TestContextBaseTest.net5.cs b/tests/bunit.core.tests/TestContextBaseTest.net5.cs index e1b13a719..d8756d4d2 100644 --- a/tests/bunit.core.tests/TestContextBaseTest.net5.cs +++ b/tests/bunit.core.tests/TestContextBaseTest.net5.cs @@ -1,9 +1,10 @@ - #if NET5_0_OR_GREATER +using Bunit.TestAssets.SampleComponents.DisposeComponents; + namespace Bunit; -public class TestContextBaseTest : TestContext +public partial class TestContextBaseTest : TestContext { [Fact(DisplayName = "ComponentFactories CanCreate() method are checked during component instantiation")] public void Test0001() @@ -45,6 +46,73 @@ public void Test0003() secondMock.Verify(x => x.Create(typeof(Simple1)), Times.Once); } + [Fact(DisplayName = "DisposeComponents captures exceptions from DisposeAsync in Renderer.UnhandledException")] + public async Task Test201() + { + RenderComponent(); + + DisposeComponents(); + + var exception = await Renderer.UnhandledException; + exception.ShouldBeOfType(); + } + + [Fact(DisplayName = "DisposeComponents calls DisposeAsync on rendered components")] + public async Task Test202() + { + var cut = RenderComponent(); + var instance = cut.Instance; + + DisposeComponents(); + + // Windows timer resolution is around 15ms therefore we want to have a higher value than the test + // itself to prohibit flakiness + await Task.Delay(25); + instance.WasDisposed.ShouldBeTrue(); + } + + [Fact(DisplayName = "DisposeComponents should dispose components added via ComponentFactory")] + public void Test203() + { + ComponentFactories.Add(); + var cut = RenderComponent(ps => ps.Add(p => p.CallStack, new List())); + var instance = cut.FindComponent().Instance; + + DisposeComponents(); + + instance.WasDisposed.ShouldBeTrue(); + } + + private sealed class MyChildDisposeStub : ComponentBase, IDisposable + { + public bool WasDisposed { get; private set; } + + public void Dispose() + { + WasDisposed = true; + } + } + + private sealed class AsyncThrowExceptionComponent : ComponentBase, IAsyncDisposable + { + public async ValueTask DisposeAsync() + { + await Task.Delay(10); + throw new NotSupportedException(); + } + } + + private sealed class AsyncDisposableComponent : ComponentBase, IAsyncDisposable + { + public bool WasDisposed { get; private set; } + + public async ValueTask DisposeAsync() + { + await Task.Delay(10); + WasDisposed = true; + } + } + private static Mock CreateMockComponentFactory(Func canCreate, Func create) { var result = new Mock(MockBehavior.Strict); @@ -53,5 +121,4 @@ private static Mock CreateMockComponentFactory(FuncTest +@code { + [CascadingParameter] + public ICollection CallStack { get; set; } = Array.Empty(); + + public void Dispose() + { + CallStack.Add(nameof(ChildDispose)); + } +} \ No newline at end of file diff --git a/tests/bunit.testassets/SampleComponents/DisposeComponents/DisposeFragments.razor b/tests/bunit.testassets/SampleComponents/DisposeComponents/DisposeFragments.razor new file mode 100644 index 000000000..63ec43212 --- /dev/null +++ b/tests/bunit.testassets/SampleComponents/DisposeComponents/DisposeFragments.razor @@ -0,0 +1,8 @@ +@code { + public static RenderFragment ChildDisposeAsFragment(List callStack) + { + return @ + + ; + } +} diff --git a/tests/bunit.testassets/SampleComponents/DisposeComponents/ParentDispose.razor b/tests/bunit.testassets/SampleComponents/DisposeComponents/ParentDispose.razor new file mode 100644 index 000000000..f5cb6ba4c --- /dev/null +++ b/tests/bunit.testassets/SampleComponents/DisposeComponents/ParentDispose.razor @@ -0,0 +1,13 @@ +@implements IDisposable + + + +@code { + [CascadingParameter] + public ICollection CallStack { get; set; } = Array.Empty(); + + public void Dispose() + { + CallStack.Add(nameof(ParentDispose)); + } +} diff --git a/tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs b/tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs index d42c7b7c6..a2322c6c8 100644 --- a/tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs +++ b/tests/bunit.web.tests/BlazorE2E/ComponentRenderingTest.cs @@ -5,6 +5,7 @@ using System.Numerics; using Bunit.TestAssets.BlazorE2E; using Bunit.TestAssets.BlazorE2E.HierarchicalImportsTest.Subdir; +using Bunit.TestAssets.SampleComponents.DisposeComponents; using Xunit.Abstractions; namespace Bunit.BlazorE2E; @@ -12,7 +13,7 @@ namespace Bunit.BlazorE2E; /// /// This tests are based on the tests from the following AspNetCore tests class. /// The aim is to only modify the original tests to not use Selenium, and instead use the -/// . +/// . /// https://github.com/dotnet/aspnetcore/blob/master/src/Components/test/E2ETest/Tests/ComponentRenderingTest.cs. /// public class ComponentRenderingTest : TestContext From a9235ffd82c0baa498e4e23671455854abdc882e Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Sun, 3 Apr 2022 10:21:12 +0000 Subject: [PATCH 09/49] build: attempt to fix #667 by removing "blame" from test runs --- .github/workflows/verification.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index d3b0472b7..e6b2ae6a7 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -63,9 +63,9 @@ jobs: - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions - name: 🗳️ Pack library run: | From 73af7f338c2ae6e84ba1995e2e5b52c336f087be Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 4 Apr 2022 09:03:14 +0000 Subject: [PATCH 10/49] Revert "build: attempt to fix #667 by removing "blame" from test runs" This reverts commit a9235ffd82c0baa498e4e23671455854abdc882e. --- .github/workflows/verification.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index e6b2ae6a7..d3b0472b7 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -63,9 +63,9 @@ jobs: - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - name: 🗳️ Pack library run: | From 7d5fd0c13ff4124ed15427e3d9a17b42ecd3b9c8 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 4 Apr 2022 09:21:39 +0000 Subject: [PATCH 11/49] fix: change delay in tests to make them pass on windows --- tests/bunit.core.tests/TestContextBaseTest.net5.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/bunit.core.tests/TestContextBaseTest.net5.cs b/tests/bunit.core.tests/TestContextBaseTest.net5.cs index d8756d4d2..8943db49e 100644 --- a/tests/bunit.core.tests/TestContextBaseTest.net5.cs +++ b/tests/bunit.core.tests/TestContextBaseTest.net5.cs @@ -67,7 +67,7 @@ public async Task Test202() // Windows timer resolution is around 15ms therefore we want to have a higher value than the test // itself to prohibit flakiness - await Task.Delay(25); + await Task.Delay(50); instance.WasDisposed.ShouldBeTrue(); } @@ -97,7 +97,7 @@ private sealed class AsyncThrowExceptionComponent : ComponentBase, IAsyncDisposa { public async ValueTask DisposeAsync() { - await Task.Delay(10); + await Task.Delay(30); throw new NotSupportedException(); } } @@ -108,7 +108,7 @@ private sealed class AsyncDisposableComponent : ComponentBase, IAsyncDisposable public async ValueTask DisposeAsync() { - await Task.Delay(10); + await Task.Delay(30); WasDisposed = true; } } @@ -121,4 +121,4 @@ private static Mock CreateMockComponentFactory(Func Date: Mon, 4 Apr 2022 09:31:41 +0000 Subject: [PATCH 12/49] fix: remove coverage collection during release builds this is an attempt at fixing #667 --- tests/Directory.Build.props | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index a5ad6b90d..7048d12b2 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -16,15 +16,21 @@ - + + + + + + + From 1de30f31f76cf1141454850af36893f35049ca2b Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 4 Apr 2022 09:32:15 +0000 Subject: [PATCH 13/49] fix: update run-test script with better console output --- tests/run-tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/run-tests.ps1 b/tests/run-tests.ps1 index f63de628f..3a149819f 100644 --- a/tests/run-tests.ps1 +++ b/tests/run-tests.ps1 @@ -10,14 +10,14 @@ for ($num = 1 ; $num -le $maxRuns ; $num++) if($filter) { - dotnet test .\bunit.core.tests\bunit.core.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo --filter $filter - dotnet test .\bunit.web.tests\bunit.web.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo --filter $filter - dotnet test .\bunit.xunit.tests\bunit.xunit.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo --filter $filter + dotnet test .\bunit.core.tests\bunit.core.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --filter $filter --logger:"console;verbosity=normal" + dotnet test .\bunit.web.tests\bunit.web.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --filter $filter --logger:"console;verbosity=normal" + dotnet test .\bunit.web.testcomponents.tests\bunit.web.testcomponents.teststests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --filter $filter --logger:"console;verbosity=normal" } else { - dotnet test .\bunit.core.tests\bunit.core.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo - dotnet test .\bunit.web.tests\bunit.web.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo - dotnet test .\bunit.xunit.tests\bunit.xunit.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s -f net5.0 --nologo + dotnet test .\bunit.core.tests\bunit.core.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --logger:"console;verbosity=normal" + dotnet test .\bunit.web.tests\bunit.web.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --logger:"console;verbosity=normal" + dotnet test .\bunit.web.testcomponents.tests\bunit.web.testcomponents.tests.csproj -c $mode --no-restore --no-build --blame-hang --blame-hang-timeout 100s --nologo --logger:"console;verbosity=normal" } } From 8bc935cd4c9a6fb4f97f303fd45c0120ddb24958 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 5 Apr 2022 16:09:52 +0000 Subject: [PATCH 14/49] feat: Add SetAuthenticationType to TestAuthorizationContext commit 8cb3ba33be1ac3a259750196e2d7373fad0fb582 Author: Egil Hansen Date: Tue Apr 5 16:05:50 2022 +0000 fix wording in docs commit 056ab7a3f87400fe8841e9ec2a66a6d6e3b94533 Merge: a229078 08f3dd9 Author: Tim Purdum Date: Fri Mar 25 18:25:08 2022 -0500 Merge branch 'main' into main commit a229078c14c31340b9ddb590710a9b55fbe2d0b5 Author: Tim Purdum Date: Fri Mar 25 18:23:11 2022 -0500 Update docs/site/docs/test-doubles/faking-auth.md Co-authored-by: Egil Hansen commit d3e6637ded383e90235dbbf9fc93bf87210b2a22 Author: Tim Purdum Date: Mon Feb 28 18:03:25 2022 +0000 update changelog and documentation commit 9ed52e8ebad18e30be1db849854537524cfb59a1 Author: Tim Purdum Date: Mon Feb 28 17:50:45 2022 +0000 build fixes, unit tests commit 3753389d7c05b343f90a91b0369b49fc41a08453 Author: Tim Purdum Date: Mon Feb 28 11:02:27 2022 -0600 Implement SetAuthenticationType --- CHANGELOG.md | 8 +++-- docs/samples/components/UserRights.razor | 6 ++++ docs/samples/tests/xunit/UserRightsTest.cs | 19 +++++++++++ docs/site/docs/test-doubles/faking-auth.md | 8 +++++ .../FakeAuthenticationStateProvider.cs | 33 ++++++++++++++----- .../Authorization/TestAuthorizationContext.cs | 12 ++++++- .../SimpleAuthViewWithCustomAuthType.razor | 8 +++++ .../Authorization/AuthorizationTest.cs | 29 ++++++++++++++++ 8 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 tests/bunit.testassets/SampleComponents/SimpleAuthViewWithCustomAuthType.razor diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ca9a8892..cfb767104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,14 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] ### Added -- Added `DisposeComponents` to `TestContextBase`. It will dispose and remove all components rendered by the `TestContextBase`. By [@linkdotnet](https://github.com/linkdotnet). + +- Added method `SetAuthenticationType` to `TestAuthorizationContext` to allow for custom authentication type checks. By [@TimPurdum](https://github.com/timpurdum). + +- Added `DisposeComponents` to `TestContextBase`. It will dispose and remove all components rendered by the `TestContextBase`. By [@linkdotnet](https://github.com/linkdotnet). ### Fixed -- Fixed step by step guide for building and viewing the documentation locally. By [@linkdotnet](https://github.com/linkdotnet). + +- Fixed step by step guide for building and viewing the documentation locally. By [@linkdotnet](https://github.com/linkdotnet). ## [1.6.4] - 2022-02-22 diff --git a/docs/samples/components/UserRights.razor b/docs/samples/components/UserRights.razor index a1d9c585d..b962122e8 100644 --- a/docs/samples/components/UserRights.razor +++ b/docs/samples/components/UserRights.razor @@ -21,6 +21,12 @@
  • You are a CONTENT EDITOR
  • + + @if(context.User.Identity?.AuthenticationType == "custom-auth-type") + { +
  • You have the authentication type CUSTOM AUTH TYPE
  • + } +
    @code diff --git a/docs/samples/tests/xunit/UserRightsTest.cs b/docs/samples/tests/xunit/UserRightsTest.cs index 00058885a..14ee4574e 100644 --- a/docs/samples/tests/xunit/UserRightsTest.cs +++ b/docs/samples/tests/xunit/UserRightsTest.cs @@ -146,5 +146,24 @@ public void Test005()
  • You are a CONTENT EDITOR
  • "); } + + [Fact(DisplayName = "Custom authentication type")] + public void Test007() + { + // Arrange + using var ctx = new TestContext(); + var authContext = ctx.AddTestAuthorization(); + authContext.SetAuthorized("TEST USER"); + authContext.SetAuthenticationType("custom-auth-type"); + + // Act + var cut = ctx.RenderComponent(); + + // Assert + cut.MarkupMatches(@"

    Hi TEST USER, you have these claims and rights:

    +
      +
    • You have the authentication type CUSTOM AUTH TYPE
    • +
    "); + } } } diff --git a/docs/site/docs/test-doubles/faking-auth.md b/docs/site/docs/test-doubles/faking-auth.md index 91f228fce..26156400a 100644 --- a/docs/site/docs/test-doubles/faking-auth.md +++ b/docs/site/docs/test-doubles/faking-auth.md @@ -109,3 +109,11 @@ Let’s try to combine all the possibilities shown in the previous examples into [!code-csharp[UserRightsTest.cs](../../../samples/tests/xunit/UserRightsTest.cs?start=129&end=147&highlight=4-8)] With this example done, all auth-related test scenarios should be covered. If you find that one is missing, please let us know in the [bUnit discussion forum](https://github.com/egil/bUnit/discussions). + +### Authentication types + +To specify a authentication type for the authenticated and authorized user, do the following: + +[!code-csharp[UserRightsTest.cs](../../../samples/tests/xunit/UserRightsTest.cs?start=153&end=166&highlight=5)] + +The highlighted line shows how the method is used to change the `Identity.AuthenticationType` of the user. diff --git a/src/bunit.web/TestDoubles/Authorization/FakeAuthenticationStateProvider.cs b/src/bunit.web/TestDoubles/Authorization/FakeAuthenticationStateProvider.cs index 5347fd6b7..6b3a6244e 100644 --- a/src/bunit.web/TestDoubles/Authorization/FakeAuthenticationStateProvider.cs +++ b/src/bunit.web/TestDoubles/Authorization/FakeAuthenticationStateProvider.cs @@ -18,8 +18,13 @@ public class FakeAuthenticationStateProvider : AuthenticationStateProvider /// Identity's user name. /// Roles that this user principal has. /// Claims to add to user principal. - public FakeAuthenticationStateProvider(string userName, IEnumerable? roles = null, IEnumerable? claims = null) - => SetAuthenticatedState(userName, roles, claims); + /// The authentication type for the user principal. + public FakeAuthenticationStateProvider( + string userName, + IEnumerable? roles = null, + IEnumerable? claims = null, + string? authenticationType = null) + => SetAuthenticatedState(userName, roles, claims, authenticationType); /// /// Initializes a new instance of the class. @@ -38,9 +43,14 @@ public FakeAuthenticationStateProvider(string userName, IEnumerable? rol /// Identity's user name. /// Roles that this user principal has. /// Claims to add to user principal. - public void TriggerAuthenticationStateChanged(string userName, IEnumerable? roles = null, IEnumerable? claims = null) + /// The authentication type for the user principal. + public void TriggerAuthenticationStateChanged( + string userName, + IEnumerable? roles = null, + IEnumerable? claims = null, + string? authenticationType = null) { - SetAuthenticatedState(userName, roles, claims); + SetAuthenticatedState(userName, roles, claims, authenticationType); NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); } @@ -76,12 +86,16 @@ private void SetAuthorizingState() authState = new TaskCompletionSource(); } - private void SetAuthenticatedState(string userName, IEnumerable? roles, IEnumerable? claims) + private void SetAuthenticatedState( + string userName, + IEnumerable? roles, + IEnumerable? claims, + string? authenticationType) { if (authState.Task.IsCompleted) authState = new TaskCompletionSource(); - authState.SetResult(CreateAuthenticationState(userName, roles, claims)); + authState.SetResult(CreateAuthenticationState(userName, roles, claims, authenticationType)); } /// @@ -90,20 +104,23 @@ private void SetAuthenticatedState(string userName, IEnumerable? roles, /// Identity's user name. /// Roles that this user principal has. /// Claims to add to user principal. + /// The authentication type for the user principal. /// Instance of AuthenticationState with user principal. private static AuthenticationState CreateAuthenticationState( string username, IEnumerable? roles = null, - IEnumerable? claims = null) + IEnumerable? claims = null, + string? authenticationType = null) { roles = roles ?? Array.Empty(); claims = claims ?? Array.Empty(); + authenticationType = authenticationType ?? "bUnit Fake Authentication"; var usernameClaim = new Claim(ClaimsIdentity.DefaultNameClaimType, username); var roleClaims = roles.Select(x => new Claim(ClaimsIdentity.DefaultRoleClaimType, x)); var allClaims = roleClaims.Concat(claims).Prepend(usernameClaim); - var identity = new ClaimsIdentity(claims: allClaims, authenticationType: "bUnit Fake Authentication"); + var identity = new ClaimsIdentity(claims: allClaims, authenticationType: authenticationType); var principal = new ClaimsPrincipal(identity); return new AuthenticationState(principal); diff --git a/src/bunit.web/TestDoubles/Authorization/TestAuthorizationContext.cs b/src/bunit.web/TestDoubles/Authorization/TestAuthorizationContext.cs index f7e1753e4..6354767a3 100644 --- a/src/bunit.web/TestDoubles/Authorization/TestAuthorizationContext.cs +++ b/src/bunit.web/TestDoubles/Authorization/TestAuthorizationContext.cs @@ -139,7 +139,7 @@ public TestAuthorizationContext SetPolicies(params string[] policies) } /// - /// Sets the claims on the curren user/principal. + /// Sets the claims on the current user/principal. /// /// Claims to set. public TestAuthorizationContext SetClaims(params Claim[] claims) @@ -149,4 +149,14 @@ public TestAuthorizationContext SetClaims(params Claim[] claims) return this; } + + /// + /// Sets the Identity.AuthenticationType for the current user/principa;. + /// + /// The authentication type to set. + public TestAuthorizationContext SetAuthenticationType(string authenticationType) + { + this.authProvider.TriggerAuthenticationStateChanged(this.UserName, this.Roles, this.Claims, authenticationType); + return this; + } } diff --git a/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithCustomAuthType.razor b/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithCustomAuthType.razor new file mode 100644 index 000000000..ddcefcfe8 --- /dev/null +++ b/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithCustomAuthType.razor @@ -0,0 +1,8 @@ +@using Microsoft.AspNetCore.Components.Authorization + + + @if (context.User.Identity?.AuthenticationType == "custom-auth-type") + { +

    Authorized content with custom auth type.

    + } +
    diff --git a/tests/bunit.web.tests/TestDoubles/Authorization/AuthorizationTest.cs b/tests/bunit.web.tests/TestDoubles/Authorization/AuthorizationTest.cs index 476370445..a2665a954 100644 --- a/tests/bunit.web.tests/TestDoubles/Authorization/AuthorizationTest.cs +++ b/tests/bunit.web.tests/TestDoubles/Authorization/AuthorizationTest.cs @@ -240,4 +240,33 @@ public void Test020() cut.MarkupMatches("

    True

    "); } + + [Fact(DisplayName = "SimpleAuthViewWithCustomAuthType with set auth type")] + public void Test021() + { + // arrange + var authContext = this.AddTestAuthorization(); + authContext.SetAuthorized("TestUser"); + authContext.SetAuthenticationType("custom-auth-type"); + + // act + var cut = RenderComponent(); + + // assert + cut.MarkupMatches("

    Authorized content with custom auth type.

    "); + } + + [Fact(DisplayName = "SimpleAuthViewWithCustomAuthType without set auth type")] + public void Test022() + { + // arrange + var authContext = this.AddTestAuthorization(); + authContext.SetAuthorized("TestUser"); + + // act + var cut = RenderComponent(); + + // assert + cut.MarkupMatches(string.Empty); + } } From f49ef1bf58c4d5b6acd654593e5fa7c0c1a9d6fa Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 20:32:26 +0200 Subject: [PATCH 15/49] fix: FakeNavigationManager doesn't throw exception when navigating to external url * fix: FakeNavigationManager doesn't throw exception when navigating to external url * fix: Refactored NavigationManager to not rely on localhost checks * fix: Readded setting base uri in dispatcher block * fix: Remove redundant base qualifier Fixes #665 --- CHANGELOG.md | 2 + .../FakeNavigationManager.cs | 70 +++++++++++++++++-- .../FakeNavigationManagerTest.cs | 27 ++++++- 3 files changed, 93 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfb767104..d4828f7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad - Fixed step by step guide for building and viewing the documentation locally. By [@linkdotnet](https://github.com/linkdotnet). +- `FakeNavigationManager.NavigateTo` could lead to exceptions when navigating to external url's. Reported by (@TDroogers)[https://github.com/TDroogers]. Fixed by [@linkdotnet](https://github.com/linkdotnet). + ## [1.6.4] - 2022-02-22 A quick minor release that primiarily fixes a regression in 1.5.12. diff --git a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs index 90df7f8a4..8a5b9d3a8 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs @@ -2,6 +2,8 @@ namespace Bunit.TestDoubles; +using URI = Uri; + /// /// Represents a fake that captures calls to /// for testing purposes. @@ -34,13 +36,33 @@ public FakeNavigationManager(ITestRenderer renderer) /// protected override void NavigateToCore(string uri, bool forceLoad) { + var absoluteUri = GetNewAbsoluteUri(uri); + var changedBaseUri = HasDifferentBaseUri(absoluteUri); + + if (changedBaseUri) + { + BaseUri = GetBaseUri(absoluteUri); + } + Uri = ToAbsoluteUri(uri).OriginalString; history.Push(new NavigationHistory(uri, new NavigationOptions(forceLoad))); renderer.Dispatcher.InvokeAsync(() => { - Uri = ToAbsoluteUri(uri).OriginalString; - NotifyLocationChanged(isInterceptedLink: false); + Uri = absoluteUri.OriginalString; + + // Only notify of changes if user navigates within the same + // base url (domain). Otherwise, the user navigated away + // from the app, and Blazor's NavigationManager would + // not notify of location changes. + if (!changedBaseUri) + { + NotifyLocationChanged(isInterceptedLink: false); + } + else + { + BaseUri = GetBaseUri(absoluteUri); + } }); } #endif @@ -50,6 +72,14 @@ protected override void NavigateToCore(string uri, bool forceLoad) /// protected override void NavigateToCore(string uri, NavigationOptions options) { + var absoluteUri = GetNewAbsoluteUri(uri); + var changedBaseUri = HasDifferentBaseUri(absoluteUri); + + if (changedBaseUri) + { + BaseUri = GetBaseUri(absoluteUri); + } + Uri = ToAbsoluteUri(uri).OriginalString; if (options.ReplaceHistoryEntry && history.Count > 0) @@ -59,9 +89,39 @@ protected override void NavigateToCore(string uri, NavigationOptions options) renderer.Dispatcher.InvokeAsync(() => { - Uri = ToAbsoluteUri(uri).OriginalString; - NotifyLocationChanged(isInterceptedLink: false); + Uri = absoluteUri.OriginalString; + + // Only notify of changes if user navigates within the same + // base url (domain). Otherwise, the user navigated away + // from the app, and Blazor's NavigationManager would + // not notify of location changes. + if (!changedBaseUri) + { + NotifyLocationChanged(isInterceptedLink: false); + } + else + { + BaseUri = GetBaseUri(absoluteUri); + } }); } #endif -} + + private URI GetNewAbsoluteUri(string uri) + => URI.IsWellFormedUriString(uri, UriKind.Relative) + ? ToAbsoluteUri(uri) + : new URI(uri, UriKind.Absolute); + + private bool HasDifferentBaseUri(URI absoluteUri) + => URI.Compare( + new URI(BaseUri, UriKind.Absolute), + absoluteUri, + UriComponents.SchemeAndServer, + UriFormat.Unescaped, + StringComparison.OrdinalIgnoreCase) != 0; + + private static string GetBaseUri(URI uri) + { + return uri.Scheme + "://" + uri.Authority + "/"; + } +} \ No newline at end of file diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 98b4ad701..fe7534aa5 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -138,5 +138,30 @@ public void Test201() .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", new NavigationOptions() { ReplaceHistoryEntry = true })); } #endif + + [Fact(DisplayName = "Navigate to an external url should set BaseUri")] + public void Test008() + { + const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; + var sut = CreateFakeNavigationMananger(); + + sut.NavigateTo(externalUri); + + sut.BaseUri.ShouldBe("https://bunit.dev/"); + sut.Uri.ShouldBe(externalUri); + } + + [Fact(DisplayName = "Navigate to external url should not invoke LocationChanged event")] + public void Test009() + { + var locationChangedInvoked = false; + const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; + var sut = CreateFakeNavigationMananger(); + sut.LocationChanged += (s, e) => locationChangedInvoked = true; + + sut.NavigateTo(externalUri); + + locationChangedInvoked.ShouldBeFalse(); + } } -} +} \ No newline at end of file From dc02a02f32b68c95ad624e84527aec797a2292dd Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 4 Apr 2022 20:04:14 +0200 Subject: [PATCH 16/49] add: Update to latest dotnet version including preview --- .github/workflows/verification.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index d3b0472b7..5238b6e98 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -31,20 +31,15 @@ jobs: with: fetch-depth: 0 - - name: ⚙️ Setup dotnet 3.1.x - uses: actions/setup-dotnet@v1 + - name: ⚙️ Setup dotnet versions + uses: actions/setup-dotnet@v2 with: - dotnet-version: '3.1.x' - - - name: ⚙️ Setup dotnet 5.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '5.0.x' - - - name: ⚙️ Setup dotnet 6.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x + dotnet-version: | + 3.1.x + 5.0.x + 6.0.x + 7.0.x + include-prerelease: true - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.0 From f69091e0317e493ac4e2584b966bdf27123ec5a1 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 4 Apr 2022 20:49:02 +0200 Subject: [PATCH 17/49] feat: dotnet7 support including nightly verification against nightly version --- .github/workflows/verification-nightly.yml | 31 +++++++++++++++++++ .github/workflows/verification.yml | 2 -- Directory.Build.props | 1 + global.json | 2 +- src/bunit.core/bunit.core.csproj | 10 ++++-- .../bunit.web.testcomponents.csproj | 14 +++++++-- src/bunit.web/bunit.web.csproj | 11 +++++-- src/bunit/bunit.csproj | 2 +- .../bunit.core.tests/bunit.core.tests.csproj | 4 +-- .../bunit.testassets/bunit.testassets.csproj | 8 +++-- .../bunit.web.testcomponents.tests.csproj | 2 +- tests/bunit.web.tests/bunit.web.tests.csproj | 4 +-- 12 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/verification-nightly.yml diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml new file mode 100644 index 000000000..fbecc2b51 --- /dev/null +++ b/.github/workflows/verification-nightly.yml @@ -0,0 +1,31 @@ +name: verification against nightly aspnet core builds + +on: + push: + branches: + - 'feature/*' + schedule: + - cron: "0 0 * * *" + +jobs: + verify-bunit: + name: 👌 Verify bUnit + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/dotnet/nightly/sdk:7.0 + + steps: + - name: 🌛 Show dotnet version + run: | + dotnet --info + + - name: 🛒 Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: 🧪 Run unit tests + run: | + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none \ No newline at end of file diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 5238b6e98..44e446306 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -2,8 +2,6 @@ name: verification on: push: - branches: - - main paths: - 'src/**' - 'tests/**' diff --git a/Directory.Build.props b/Directory.Build.props index e0fc6c0ee..c33851691 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,6 +5,7 @@ 3.1.22 5.0.0 6.0.0 + 7.0.0 diff --git a/global.json b/global.json index 18562b58c..83105ca8e 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestMajor", - "allowPrerelease": false + "allowPrerelease": true } } diff --git a/src/bunit.core/bunit.core.csproj b/src/bunit.core/bunit.core.csproj index 016b4caec..eb3c0e459 100644 --- a/src/bunit.core/bunit.core.csproj +++ b/src/bunit.core/bunit.core.csproj @@ -1,7 +1,7 @@ - netstandard2.1;net5.0;net6.0 + netstandard2.1;net5.0;net6.0;net7.0 Bunit Bunit.Core @@ -36,4 +36,10 @@ - + + + + + + + \ No newline at end of file diff --git a/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj b/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj index 207937c5c..c251d1faf 100644 --- a/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj +++ b/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj @@ -1,7 +1,7 @@ - netstandard2.1;net5.0 + netstandard2.1;net5.0;net6.0;net7.0 Bunit Bunit.Web.TestComponents @@ -37,8 +37,18 @@ NOTE: This package represents experimental features of bUnit that has been super + + + + + + + + + + - + \ No newline at end of file diff --git a/src/bunit.web/bunit.web.csproj b/src/bunit.web/bunit.web.csproj index 9f674b6e1..40ae65536 100644 --- a/src/bunit.web/bunit.web.csproj +++ b/src/bunit.web/bunit.web.csproj @@ -1,7 +1,7 @@ - netstandard2.1;net5.0;net6.0 + netstandard2.1;net5.0;net6.0;net7.0 Bunit Bunit.Web @@ -43,6 +43,13 @@ + + + + + + + @@ -52,4 +59,4 @@ - + \ No newline at end of file diff --git a/src/bunit/bunit.csproj b/src/bunit/bunit.csproj index 8561fdcd4..e41667b58 100644 --- a/src/bunit/bunit.csproj +++ b/src/bunit/bunit.csproj @@ -1,6 +1,6 @@ - netstandard2.1;net5.0;net6.0 + netstandard2.1;net5.0;net6.0;net7.0 true false false diff --git a/tests/bunit.core.tests/bunit.core.tests.csproj b/tests/bunit.core.tests/bunit.core.tests.csproj index 078000124..872cf4327 100644 --- a/tests/bunit.core.tests/bunit.core.tests.csproj +++ b/tests/bunit.core.tests/bunit.core.tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0 Bunit Bunit.Core.Tests @@ -12,4 +12,4 @@ - + \ No newline at end of file diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index b4bfdbc5d..c9564c714 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -1,7 +1,7 @@ - netstandard2.1;net5.0;net6.0 + netstandard2.1;net5.0;net6.0;net7.0 Bunit.TestAssets Bunit.TestAssets true @@ -28,6 +28,10 @@ + + + + @@ -36,4 +40,4 @@ - + \ No newline at end of file diff --git a/tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj b/tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj index efad497d2..41b29a705 100644 --- a/tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj +++ b/tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj @@ -19,4 +19,4 @@ - + \ No newline at end of file diff --git a/tests/bunit.web.tests/bunit.web.tests.csproj b/tests/bunit.web.tests/bunit.web.tests.csproj index 98649017a..3b642445f 100644 --- a/tests/bunit.web.tests/bunit.web.tests.csproj +++ b/tests/bunit.web.tests/bunit.web.tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1;net5.0;net6.0 + netcoreapp3.1;net5.0;net6.0;net7.0 Bunit Bunit.Web.Tests @@ -12,4 +12,4 @@ - + \ No newline at end of file From 0d8b8b9a3ebeb401ff223e68d2ed4deb1c691a95 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 5 Apr 2022 09:24:50 +0200 Subject: [PATCH 18/49] add: Changelog entries --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4828f7d4..35c93cc76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad - Added method `SetAuthenticationType` to `TestAuthorizationContext` to allow for custom authentication type checks. By [@TimPurdum](https://github.com/timpurdum). - Added `DisposeComponents` to `TestContextBase`. It will dispose and remove all components rendered by the `TestContextBase`. By [@linkdotnet](https://github.com/linkdotnet). + +- Added .NET 7 (preview 2) as a target framework for bUnit, bUnit.core and bUnit.web. Enabled nightly build which verifies against .NET nightly builds. Reported by [@egil](https://github.com/egil). By [@linkdotnet](https://github.com/linkdotnet). ### Fixed From 054d3dbc4aaffdff41c9c59ceb969c782707db3a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 5 Apr 2022 09:25:44 +0200 Subject: [PATCH 19/49] fix: Remove analyzer warning as it is intended --- .../SampleComponents/ThrowsOnParameterSet.razor | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor index 0211ff61b..ca32e0936 100644 --- a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor +++ b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor @@ -3,6 +3,7 @@ private string value = string.Empty; [Parameter] +#pragma warning disable BL0007 // Component parameter should be auto property public string Value { get => value; @@ -11,4 +12,5 @@ throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(value)} is invalid"); } } -} +#pragma warning restore BL0007 // Component parameter should be auto property +} \ No newline at end of file From 5dd9e83a90976fdb7cfc988058b44b0659f3a9e0 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 5 Apr 2022 18:46:10 +0200 Subject: [PATCH 20/49] fix: Moved analyzer warning to editorconfig --- .editorconfig | 1 + .../SampleComponents/ThrowsOnParameterSet.razor | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 5623e9f3f..edf4a53c0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -463,6 +463,7 @@ dotnet_diagnostic.BL0003.severity = none dotnet_diagnostic.BL0004.severity = none dotnet_diagnostic.BL0005.severity = none dotnet_diagnostic.BL0006.severity = none +dotnet_diagnostic.BL0007.severity = none ########################################## # Custom Test Code Analyzers Rules diff --git a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor index ca32e0936..6736ac2c6 100644 --- a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor +++ b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor @@ -3,7 +3,6 @@ private string value = string.Empty; [Parameter] -#pragma warning disable BL0007 // Component parameter should be auto property public string Value { get => value; @@ -12,5 +11,4 @@ throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(value)} is invalid"); } } -#pragma warning restore BL0007 // Component parameter should be auto property } \ No newline at end of file From 7fd1391bd661b6d4440394caa3997cb47ec84ed7 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 08:07:35 +0200 Subject: [PATCH 21/49] fix: Use wildcard for .net7 Co-authored-by: Egil Hansen --- Directory.Build.props | 2 +- src/bunit.core/bunit.core.csproj | 6 +++--- .../bunit.web.testcomponents.csproj | 4 ++-- src/bunit.web/bunit.web.csproj | 8 ++++---- tests/bunit.testassets/bunit.testassets.csproj | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c33851691..65c996a03 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ 3.1.22 5.0.0 6.0.0 - 7.0.0 + 7.0.0-preview.2.* diff --git a/src/bunit.core/bunit.core.csproj b/src/bunit.core/bunit.core.csproj index eb3c0e459..bd222dc4e 100644 --- a/src/bunit.core/bunit.core.csproj +++ b/src/bunit.core/bunit.core.csproj @@ -37,9 +37,9 @@ - - - + + + \ No newline at end of file diff --git a/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj b/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj index c251d1faf..6582e951b 100644 --- a/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj +++ b/src/bunit.web.testcomponents/bunit.web.testcomponents.csproj @@ -43,8 +43,8 @@ NOTE: This package represents experimental features of bUnit that has been super - - + + diff --git a/src/bunit.web/bunit.web.csproj b/src/bunit.web/bunit.web.csproj index 40ae65536..656525041 100644 --- a/src/bunit.web/bunit.web.csproj +++ b/src/bunit.web/bunit.web.csproj @@ -44,10 +44,10 @@ - - - - + + + + diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index c9564c714..3fc061195 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -29,8 +29,8 @@ - - + + From 722fee010598828995de119ebdb4f9aae56257bf Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 08:08:10 +0200 Subject: [PATCH 22/49] fix Rephrased changelog Co-authored-by: Egil Hansen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35c93cc76..eed99b5b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad - Added `DisposeComponents` to `TestContextBase`. It will dispose and remove all components rendered by the `TestContextBase`. By [@linkdotnet](https://github.com/linkdotnet). -- Added .NET 7 (preview 2) as a target framework for bUnit, bUnit.core and bUnit.web. Enabled nightly build which verifies against .NET nightly builds. Reported by [@egil](https://github.com/egil). By [@linkdotnet](https://github.com/linkdotnet). +- Added .NET 7 as a target framework for bUnit. By [@linkdotnet](https://github.com/linkdotnet). ### Fixed From db88ff55b772dea145d351887e9f1db05f9f9878 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:06:04 +0200 Subject: [PATCH 23/49] feat: Added on failure create issue --- .github/nightly-failed.md | 6 ++++++ .github/workflows/verification-nightly.yml | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .github/nightly-failed.md diff --git a/.github/nightly-failed.md b/.github/nightly-failed.md new file mode 100644 index 000000000..eee5c37af --- /dev/null +++ b/.github/nightly-failed.md @@ -0,0 +1,6 @@ +--- +title: Nightly Build failed! +labels: input needed +--- + +The nightly build failed. Please investigate. \ No newline at end of file diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index fbecc2b51..97533e9e5 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -26,6 +26,15 @@ jobs: - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none \ No newline at end of file + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + + - name: Create issue if failed + if: failure() + uses: JasonEtco/create-an-issue@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + filename: .github/nightly-failed.md + update_existing: true From 8f4d4bccc85efa3f74eeb34dae0d7a45bdf4e987 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:06:17 +0200 Subject: [PATCH 24/49] fix: simplify version --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 65c996a03..cbecc447c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ 3.1.22 5.0.0 6.0.0 - 7.0.0-preview.2.* + 7.0.0-* From 2c790ae963bba1fcb802f5204d6a75ef68cbd645 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:14:17 +0200 Subject: [PATCH 25/49] fix: Use emoji --- .github/workflows/verification-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index 97533e9e5..423a23577 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -30,7 +30,7 @@ jobs: dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - - name: Create issue if failed + - name: ⚡ Create issue if failed if: failure() uses: JasonEtco/create-an-issue@v2 env: From cb020591c7c36136f131c4fb65a9bf9cbf4ae6a1 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:18:39 +0200 Subject: [PATCH 26/49] feat: add nightly nuget packages --- .github/workflows/verification-nightly.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index 423a23577..fbb88ceec 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -24,6 +24,10 @@ jobs: with: fetch-depth: 0 + - name: 📦 Setup nuget nightly builds + run: | + dotnet nuget add source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json + - name: 🧪 Run unit tests run: | dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none From 71d3b80735e9f26516ebd00bdcd3b18893848eee Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:46:27 +0200 Subject: [PATCH 27/49] fix: Set restore explicitly with detailed logging --- .github/workflows/verification-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index fbb88ceec..f12a63fa6 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -26,7 +26,7 @@ jobs: - name: 📦 Setup nuget nightly builds run: | - dotnet nuget add source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json + dotnet restore --verbosity detailed -s https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json -s https://api.nuget.org/v3/index.json - name: 🧪 Run unit tests run: | From 59c78e8ae0b833b46a412a5b43f8f09b82198d23 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 13:53:53 +0200 Subject: [PATCH 28/49] fix: enriched more information about the build --- .github/nightly-failed.md | 6 +++++- .github/workflows/verification-nightly.yml | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/nightly-failed.md b/.github/nightly-failed.md index eee5c37af..6e5e215f1 100644 --- a/.github/nightly-failed.md +++ b/.github/nightly-failed.md @@ -3,4 +3,8 @@ title: Nightly Build failed! labels: input needed --- -The nightly build failed. Please investigate. \ No newline at end of file +The nightly build failed against the nightly .NET 7 SDK failed. Please investigate. + +## Additional information + +`dotnet --version`: `{{env.DOTNET_VERSION}}` \ No newline at end of file diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index f12a63fa6..8e4a94cc0 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -34,11 +34,18 @@ jobs: dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + - name: 🧾 Collect dotnet information + if: failure() + run: | + echo "DOTNET_VERSION=$(dotnet --version)" >> $GITHUB_ENV + echo $DOTNET_VERSION + - name: ⚡ Create issue if failed if: failure() uses: JasonEtco/create-an-issue@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ADJECTIVE: DOTNET_VERSION with: filename: .github/nightly-failed.md update_existing: true From faf11d39ffedcd1aa021dd1f42b409d306ff1e3e Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 19:03:26 +0200 Subject: [PATCH 29/49] fix: Remove debugging stuff --- .github/workflows/verification-nightly.yml | 3 --- .github/workflows/verification.yml | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index 8e4a94cc0..30704d819 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -1,9 +1,6 @@ name: verification against nightly aspnet core builds on: - push: - branches: - - 'feature/*' schedule: - cron: "0 0 * * *" diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 44e446306..5238b6e98 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -2,6 +2,8 @@ name: verification on: push: + branches: + - main paths: - 'src/**' - 'tests/**' From ac79b184d25467f88c6bc04684c3d51a1a8d6b18 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 6 Apr 2022 21:14:22 +0200 Subject: [PATCH 30/49] fix: better issue description and re-enabled pragma to silence error --- .github/nightly-failed.md | 2 +- .../SampleComponents/ThrowsOnParameterSet.razor | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/nightly-failed.md b/.github/nightly-failed.md index 6e5e215f1..4fc9dacf0 100644 --- a/.github/nightly-failed.md +++ b/.github/nightly-failed.md @@ -1,5 +1,5 @@ --- -title: Nightly Build failed! +title: Verification against .NET 7 nightly failed labels: input needed --- diff --git a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor index 6736ac2c6..e1db8ec48 100644 --- a/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor +++ b/tests/bunit.testassets/SampleComponents/ThrowsOnParameterSet.razor @@ -3,6 +3,8 @@ private string value = string.Empty; [Parameter] + // Temporary solution as the analyzer seems to ignore the .editorconfig +#pragma warning disable BL0007 // Component parameter should be auto public string Value { get => value; @@ -11,4 +13,5 @@ throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(value)} is invalid"); } } +#pragma warning restore BL0007 // Component parameter should be auto property } \ No newline at end of file From 32056ecae303ced7f66e5f5dc3e4d1c601eea93d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Apr 2022 20:29:00 +0000 Subject: [PATCH 31/49] build(deps): bump SonarAnalyzer.CSharp from 8.36.1.44192 to 8.37.0.45539 (#669) Bumps SonarAnalyzer.CSharp from 8.36.1.44192 to 8.37.0.45539. --- updated-dependencies: - dependency-name: SonarAnalyzer.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Egil Hansen --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index cbecc447c..f7f2feb40 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -49,7 +49,7 @@ - + From 680dea28069e9535671e1dbf06ff224e26cf69e4 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 21:47:23 +0000 Subject: [PATCH 32/49] build: remove GitHubActionsTestLogger --- tests/Directory.Build.props | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 7048d12b2..64685e372 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -27,10 +27,6 @@ - - - - From 210acdced074d572c05569fbe8f7e0ababf76c19 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 21:49:53 +0000 Subject: [PATCH 33/49] build: remove GitHubLogger from test runs --- .github/workflows/verification.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 5238b6e98..ec4bb5b15 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -58,9 +58,9 @@ jobs: - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - name: 🗳️ Pack library run: | From b71dca27273e20b22638d8f527d88e303d110451 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 21:51:03 +0000 Subject: [PATCH 34/49] build: remove GitHubLogger from nightly verification --- .github/workflows/verification-nightly.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index 30704d819..557f8c3a8 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -27,9 +27,9 @@ jobs: - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger GitHubActions --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - name: 🧾 Collect dotnet information if: failure() From 32b7d72eff2e699ceadefd5a8083682515f50297 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 22:08:45 +0000 Subject: [PATCH 35/49] build: add NET 7 to release preview --- .github/workflows/release-preview.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release-preview.yml b/.github/workflows/release-preview.yml index e8d4dd05d..ee90c1636 100644 --- a/.github/workflows/release-preview.yml +++ b/.github/workflows/release-preview.yml @@ -28,15 +28,15 @@ jobs: - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.0 - - name: ⚙️ Setup dotnet 5.0.x - uses: actions/setup-dotnet@v1 + - name: ⚙️ Setup dotnet versions + uses: actions/setup-dotnet@v2 with: - dotnet-version: '5.0.x' - - - name: ⚙️ Setup dotnet 6.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x + dotnet-version: | + 3.1.x + 5.0.x + 6.0.x + 7.0.x + include-prerelease: true - name: 🛠️ Update tokens in project files uses: cschleiden/replace-tokens@v1 From 47593bba1c851b729776d85eb8b635493c91bd83 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 22:09:25 +0000 Subject: [PATCH 36/49] build: add NET 7 to release workflow --- .github/workflows/release.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 54b148479..478cc1aa3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,15 +59,15 @@ jobs: with: setAllVars: true - - name: ⚙️ Setup dotnet 5.0.x - uses: actions/setup-dotnet@v1 + - name: ⚙️ Setup dotnet versions + uses: actions/setup-dotnet@v2 with: - dotnet-version: '5.0.x' - - - name: ⚙️ Setup dotnet 6.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x + dotnet-version: | + 3.1.x + 5.0.x + 6.0.x + 7.0.x + include-prerelease: true - name: 🛠️ Update changelog uses: thomaseizinger/keep-a-changelog-new-release@1.2.1 From f238f7ed09cca7b1e0a93ae36c1271ce1c97e030 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Wed, 6 Apr 2022 22:10:19 +0000 Subject: [PATCH 37/49] build: add NET 7 to docs deploy workflow --- .github/workflows/docs-deploy.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 8cba662e3..b82936b97 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -60,20 +60,15 @@ jobs: with: files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj"]' - - name: ⚙️ Setup dotnet 3.1.x - uses: actions/setup-dotnet@v1 + - name: ⚙️ Setup dotnet versions + uses: actions/setup-dotnet@v2 with: - dotnet-version: '3.1.x' - - - name: ⚙️ Setup dotnet 5.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '5.0.x' - - - name: ⚙️ Setup dotnet 6.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 6.0.x + dotnet-version: | + 3.1.x + 5.0.x + 6.0.x + 7.0.x + include-prerelease: true - name: 🛠️ Building bUnit run: dotnet build /p:PublicRelease=true From 17ffcbefd3f3b4fa72a1b5424bce662fe3957c27 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 7 Apr 2022 10:39:30 +0000 Subject: [PATCH 38/49] build: verification-nightly no-restore tweaks --- .github/workflows/verification-nightly.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-nightly.yml index 557f8c3a8..034c38caf 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-nightly.yml @@ -23,13 +23,13 @@ jobs: - name: 📦 Setup nuget nightly builds run: | - dotnet restore --verbosity detailed -s https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json -s https://api.nuget.org/v3/index.json + dotnet restore --verbosity normal -s https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json -s https://api.nuget.org/v3/index.json - name: 🧪 Run unit tests run: | - dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.core.tests/bunit.core.tests.csproj -c release --no-restore -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.tests/bunit.web.tests.csproj -c release --no-restore -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none + dotnet test ./tests/bunit.web.testcomponents.tests/bunit.web.testcomponents.tests.csproj -c release --no-restore -f net7.0 --logger:"console;verbosity=normal" --blame-hang --blame-hang-timeout 1m --blame-hang-dump-type none - name: 🧾 Collect dotnet information if: failure() From 601b1d239ed831dafc11b5ac9591fb9e7bcc170f Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 7 Apr 2022 10:42:48 +0000 Subject: [PATCH 39/49] build: renamed verification-nightly to verification-dotnet-nightly --- ...verification-nightly.yml => verification-dotnet-nightly.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{verification-nightly.yml => verification-dotnet-nightly.yml} (97%) diff --git a/.github/workflows/verification-nightly.yml b/.github/workflows/verification-dotnet-nightly.yml similarity index 97% rename from .github/workflows/verification-nightly.yml rename to .github/workflows/verification-dotnet-nightly.yml index 034c38caf..e767f68d0 100644 --- a/.github/workflows/verification-nightly.yml +++ b/.github/workflows/verification-dotnet-nightly.yml @@ -1,4 +1,4 @@ -name: verification against nightly aspnet core builds +name: verification-dotnet-nightly on: schedule: From 9510240e7840339588411bbc330bc802bfc438b3 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 7 Apr 2022 10:44:18 +0000 Subject: [PATCH 40/49] build: enable manual trigger of verification-dotnet-nightly --- .github/workflows/verification-dotnet-nightly.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/verification-dotnet-nightly.yml b/.github/workflows/verification-dotnet-nightly.yml index e767f68d0..f7f855255 100644 --- a/.github/workflows/verification-dotnet-nightly.yml +++ b/.github/workflows/verification-dotnet-nightly.yml @@ -3,6 +3,7 @@ name: verification-dotnet-nightly on: schedule: - cron: "0 0 * * *" + workflow_dispatch: jobs: verify-bunit: From e2fb461ca7a082a8bde4e7117707317ee8db5ac3 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Tue, 12 Apr 2022 07:49:35 +0200 Subject: [PATCH 41/49] fix: Wording --- .github/nightly-failed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/nightly-failed.md b/.github/nightly-failed.md index 4fc9dacf0..6b032a82d 100644 --- a/.github/nightly-failed.md +++ b/.github/nightly-failed.md @@ -3,7 +3,7 @@ title: Verification against .NET 7 nightly failed labels: input needed --- -The nightly build failed against the nightly .NET 7 SDK failed. Please investigate. +The nightly build failed against the nightly .NET 7 SDK. Please investigate. ## Additional information From 11cb9b8f0e93b6c2627a59786bcdc7681a055186 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:40:17 +0000 Subject: [PATCH 42/49] build(deps): bump Meziantou.Analyzer from 1.0.698 to 1.0.699 Bumps [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 1.0.698 to 1.0.699. - [Release notes](https://github.com/meziantou/Meziantou.Analyzer/releases) - [Commits](https://github.com/meziantou/Meziantou.Analyzer/commits) --- updated-dependencies: - dependency-name: Meziantou.Analyzer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index f7f2feb40..436861bdd 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -48,7 +48,7 @@ - + From 5f0f02e8ea00a8d06b1f3f131f72b56cdb26d632 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Apr 2022 16:34:17 +0000 Subject: [PATCH 43/49] build(deps): bump System.Text.Json from 6.0.2 to 6.0.3 Bumps [System.Text.Json](https://github.com/dotnet/runtime) from 6.0.2 to 6.0.3. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v6.0.2...v6.0.3) --- updated-dependencies: - dependency-name: System.Text.Json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- tests/bunit.testassets/bunit.testassets.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index 3fc061195..a37313c70 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -18,7 +18,7 @@ - + From e615862beaa9f40a9b96426f46e032494082474d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:12:04 +0000 Subject: [PATCH 44/49] build(deps): bump Meziantou.Analyzer from 1.0.699 to 1.0.700 Bumps [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 1.0.699 to 1.0.700. - [Release notes](https://github.com/meziantou/Meziantou.Analyzer/releases) - [Commits](https://github.com/meziantou/Meziantou.Analyzer/commits) --- updated-dependencies: - dependency-name: Meziantou.Analyzer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 436861bdd..b388bdc54 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -48,7 +48,7 @@ - + From 0f4ab15d338b169fcfdb02800ef7d41d2e5840c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 15:09:32 +0000 Subject: [PATCH 45/49] build(deps): bump Meziantou.Analyzer from 1.0.700 to 1.0.701 Bumps [Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer) from 1.0.700 to 1.0.701. - [Release notes](https://github.com/meziantou/Meziantou.Analyzer/releases) - [Commits](https://github.com/meziantou/Meziantou.Analyzer/commits) --- updated-dependencies: - dependency-name: Meziantou.Analyzer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index b388bdc54..572ce043a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -48,7 +48,7 @@ - + From 79b46d950eab22a2cda1de11c5df44c666ac21be Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 28 Apr 2022 07:51:31 +0200 Subject: [PATCH 46/49] feat: added color output on .net related actions --- .github/workflows/docs-deploy.yml | 5 +++++ .github/workflows/release-preview.yml | 5 +++++ .github/workflows/verification-dotnet-nightly.yml | 5 +++++ .github/workflows/verification.yml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index b82936b97..5cbd12559 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -69,6 +69,11 @@ jobs: 6.0.x 7.0.x include-prerelease: true + + - name: 🎨 Setup color + run: | + echo "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=1" >> $GITHUB_ENV + echo "TERM=xterm" >> $GITHUB_ENV - name: 🛠️ Building bUnit run: dotnet build /p:PublicRelease=true diff --git a/.github/workflows/release-preview.yml b/.github/workflows/release-preview.yml index ee90c1636..d52c21dd0 100644 --- a/.github/workflows/release-preview.yml +++ b/.github/workflows/release-preview.yml @@ -37,6 +37,11 @@ jobs: 6.0.x 7.0.x include-prerelease: true + + - name: 🎨 Setup color + run: | + echo "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=1" >> $GITHUB_ENV + echo "TERM=xterm" >> $GITHUB_ENV - name: 🛠️ Update tokens in project files uses: cschleiden/replace-tokens@v1 diff --git a/.github/workflows/verification-dotnet-nightly.yml b/.github/workflows/verification-dotnet-nightly.yml index f7f855255..43bc8865b 100644 --- a/.github/workflows/verification-dotnet-nightly.yml +++ b/.github/workflows/verification-dotnet-nightly.yml @@ -22,6 +22,11 @@ jobs: with: fetch-depth: 0 + - name: 🎨 Setup color + run: | + echo "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=1" >> $GITHUB_ENV + echo "TERM=xterm" >> $GITHUB_ENV + - name: 📦 Setup nuget nightly builds run: | dotnet restore --verbosity normal -s https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json -s https://api.nuget.org/v3/index.json diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index ec4bb5b15..384b85c1f 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -41,6 +41,11 @@ jobs: 7.0.x include-prerelease: true + - name: 🎨 Setup color + run: | + echo "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION=1" >> $GITHUB_ENV + echo "TERM=xterm" >> $GITHUB_ENV + - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.0 with: From 0121f538bfb76bab82452354787d72beb53f1384 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 15:12:05 +0000 Subject: [PATCH 47/49] build(deps): bump Serilog from 2.10.0 to 2.11.0 Bumps [Serilog](https://github.com/serilog/serilog) from 2.10.0 to 2.11.0. - [Release notes](https://github.com/serilog/serilog/releases) - [Changelog](https://github.com/serilog/serilog/blob/dev/CHANGES.md) - [Commits](https://github.com/serilog/serilog/compare/v2.10.0...v2.11.0) --- updated-dependencies: - dependency-name: Serilog dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- tests/bunit.testassets/bunit.testassets.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index a37313c70..67066b6a3 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -11,7 +11,7 @@ - + From c665dcf1b5ea5a68bc73fb08973e07eca14fdf51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Apr 2022 20:00:20 +0000 Subject: [PATCH 48/49] build(deps): bump SonarAnalyzer.CSharp from 8.37.0.45539 to 8.38.0.46746 Bumps SonarAnalyzer.CSharp from 8.37.0.45539 to 8.38.0.46746. --- updated-dependencies: - dependency-name: SonarAnalyzer.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 572ce043a..03f4d688e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -49,7 +49,7 @@ - + From 680ec77b6c38252aa3cbeed5d7c2eb24a942915c Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 29 Apr 2022 16:55:27 +0000 Subject: [PATCH 49/49] Set version to '1.7' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index aa44cc1de..dcab24ace 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.7-preview", + "version": "1.7", "assemblyVersion": { "precision": "revision" },