From e1bc92c2ed64b2982f8f59d1e01b68ecb36d15ea Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 14 Aug 2024 21:50:39 +0200 Subject: [PATCH 01/73] fix: Only throw bUnit created exceptions to the user (#1519) * fix: Only throw bUnit created exceptions to the user * fix: .NET 9 p7 issues * chore: Bump packages * fix: S3993 --- .github/workflows/release.yml | 2 +- CHANGELOG.md | 4 ++++ Directory.Build.props | 2 +- benchmark/bunit.benchmarks/bunit.benchmarks.csproj | 2 +- src/Directory.Build.props | 2 +- src/bunit.web/Extensions/InputFile/InputFileExtensions.cs | 4 ++-- .../Implementation/VirtualizeJSRuntimeInvocationHandler.cs | 6 ++++++ src/bunit.web/Rendering/BunitHtmlParser.cs | 4 ++++ .../Localization/PlaceholderStringLocalization.cs | 2 ++ tests/bunit.generators.tests/bunit.generators.tests.csproj | 4 ++-- tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs | 1 + tests/bunit.testassets/bunit.testassets.csproj | 4 ++-- .../NavigationManager/FakeNavigationManagerTest.cs | 2 +- 13 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9172732d0..9baec9601 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,7 +65,7 @@ jobs: 9.0.x - name: 🛠️ Update changelog - uses: thomaseizinger/keep-a-changelog-new-release@3.0.0 + uses: thomaseizinger/keep-a-changelog-new-release@3.1.0 with: version: ${{ env.NBGV_SemVer2 }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 781da071e..00ca02203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Fixed + +- `UploadFile` should only throw an exception when the file size exceeds the maximum allowed size. Reported by [@candritzky](https://github.com/candritzky). Fixed by [@linkdotnet](https://github.com/linkdotnet). + ## [1.30.3] - 2024-07-21 ### Fixed diff --git a/Directory.Build.props b/Directory.Build.props index d9a96bfbf..c4b492f6a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -52,7 +52,7 @@ - + - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 991738e81..66d27a5ee 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -63,7 +63,7 @@ See the full changelog at https://github.com/bUnit-dev/bUnit/releases - + diff --git a/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs b/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs index 39c6d7395..1611c3772 100644 --- a/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs +++ b/src/bunit.web/Extensions/InputFile/InputFileExtensions.cs @@ -38,9 +38,9 @@ public static void UploadFiles( uploadTask.GetAwaiter().GetResult(); } - if (uploadTask.Exception is { InnerException: not null } e) + if (uploadTask.Exception?.InnerException is IOException e) { - ExceptionDispatchInfo.Capture(e.InnerException).Throw(); + ExceptionDispatchInfo.Capture(e).Throw(); } } } diff --git a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs index 59c80ac56..bfaf1c71c 100644 --- a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs +++ b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs @@ -47,9 +47,15 @@ protected internal override Task HandleAsync(JSRuntimeInvocation invocat if (!invocation.Identifier.Equals(JsFunctionsPrefix + "dispose", StringComparison.Ordinal)) { // Assert expectations about the internals of the component +#if !NET9_0_OR_GREATER Debug.Assert(invocation.Identifier.Equals(JsFunctionsPrefix + "init", StringComparison.Ordinal), "Received an unexpected invocation identifier from the component."); Debug.Assert(invocation.Arguments.Count == 3, "Received an unexpected amount of arguments from the component."); Debug.Assert(invocation.Arguments[0] is not null, "Received an unexpected null argument, expected an DotNetObjectReference instance."); +#else + Debug.Assert(invocation.Identifier.Equals(JsFunctionsPrefix + "init", StringComparison.Ordinal)); + Debug.Assert(invocation.Arguments.Count == 3); + Debug.Assert(invocation.Arguments[0] is not null); +#endif InvokeOnSpacerBeforeVisible(invocation.Arguments[0]!); diff --git a/src/bunit.web/Rendering/BunitHtmlParser.cs b/src/bunit.web/Rendering/BunitHtmlParser.cs index f56c008b4..6f8edb5f7 100644 --- a/src/bunit.web/Rendering/BunitHtmlParser.cs +++ b/src/bunit.web/Rendering/BunitHtmlParser.cs @@ -105,7 +105,11 @@ private static (IElement? Context, string? MatchedElement) GetParseContextFromTa int startIndex, IDocument document) { +#if !NET9_0_OR_GREATER Debug.Assert(document.Body is not null, "Body of the document should never be null at this point."); +#else + Debug.Assert(document.Body is not null); +#endif IElement? result = null; diff --git a/src/bunit.web/TestDoubles/Localization/PlaceholderStringLocalization.cs b/src/bunit.web/TestDoubles/Localization/PlaceholderStringLocalization.cs index 0424e0d53..2112326d5 100644 --- a/src/bunit.web/TestDoubles/Localization/PlaceholderStringLocalization.cs +++ b/src/bunit.web/TestDoubles/Localization/PlaceholderStringLocalization.cs @@ -17,7 +17,9 @@ public IEnumerable GetAllStrings(bool includeParentCultures) /// /// Will throw exception to prompt the user. /// +#pragma warning disable S2325 // "WithCulture" is public API and can't be changed public IStringLocalizer WithCulture(CultureInfo culture) +#pragma warning restore S2325 => throw new MissingMockStringLocalizationException(nameof(WithCulture), culture); /// diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index 236bac0a1..eb1708596 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs b/tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs index 71e49829e..7ced47dc8 100644 --- a/tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs +++ b/tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs @@ -3,6 +3,7 @@ namespace Xunit; +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public sealed class RepeatAttribute : DataAttribute { public int Count { get; } diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index d9746eafc..07c94fb4a 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index e8a274fab..ca09b9423 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -356,7 +356,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseComponent(); } - private void InterceptNavigation(LocationChangingContext context) + private static void InterceptNavigation(LocationChangingContext context) { throw new NotSupportedException("Don't intercept"); } From 5d1165b3076ba0f55bc3ecaeb3d85c2d2e6bbe25 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:40:31 +0000 Subject: [PATCH 02/73] build(deps): Bump Nerdbank.GitVersioning from 3.6.139 to 3.6.141 (#1516) Bumps [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) from 3.6.139 to 3.6.141. - [Release notes](https://github.com/dotnet/Nerdbank.GitVersioning/releases) - [Commits](https://github.com/dotnet/Nerdbank.GitVersioning/compare/v3.6.139...v3.6.141) --- updated-dependencies: - dependency-name: Nerdbank.GitVersioning dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/bunit.generators/bunit.generators.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bunit.generators/bunit.generators.csproj b/src/bunit.generators/bunit.generators.csproj index dd92ab878..dc358a049 100644 --- a/src/bunit.generators/bunit.generators.csproj +++ b/src/bunit.generators/bunit.generators.csproj @@ -80,6 +80,6 @@ runtime; build; native; contentfiles; analyzers - + From f1246689734da0ef04c27084ee6ca551e6245370 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 16 Aug 2024 14:41:12 +0000 Subject: [PATCH 03/73] Set version to '1.31' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index d009bb001..64c0ce06b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.31-preview", + "version": "1.31", "assemblyVersion": { "precision": "revision" }, From a735e1bf3f71d92c5bf3b062b3fb5e6bc5e6b68f Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 16 Aug 2024 14:41:13 +0000 Subject: [PATCH 04/73] Set version to '1.32-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index d009bb001..259e66b43 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.31-preview", + "version": "1.32-preview", "assemblyVersion": { "precision": "revision" }, From fa26750e8e60793d4663f6505b2fba3b223bf3d3 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 16 Aug 2024 14:51:52 +0000 Subject: [PATCH 05/73] Updated CHANGELOG.md for 1.31.3 release --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ca02203..e3fd8f659 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.31.3] - 2024-08-16 + ### Fixed - `UploadFile` should only throw an exception when the file size exceeds the maximum allowed size. Reported by [@candritzky](https://github.com/candritzky). Fixed by [@linkdotnet](https://github.com/linkdotnet). @@ -1386,7 +1388,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.30.3...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...HEAD +[1.31.3]: https://github.com/bUnit-dev/bUnit/compare/v1.30.3...1.31.3 [1.30.3]: https://github.com/bUnit-dev/bUnit/compare/v1.29.5...v1.30.3 [1.29.5]: https://github.com/bUnit-dev/bUnit/compare/v1.28.9...1.29.5 [1.28.9]: https://github.com/bUnit-dev/bUnit/compare/v1.27.17...v1.28.9 From dcf92a49cfe392d367a8fafc718de615bb61a5e9 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 19 Aug 2024 17:42:52 +0000 Subject: [PATCH 06/73] docs: Added Limitation for UploadFiles --- docs/site/docs/test-doubles/input-file.md | 43 ++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/site/docs/test-doubles/input-file.md b/docs/site/docs/test-doubles/input-file.md index bae083b5d..c34442d0f 100644 --- a/docs/site/docs/test-doubles/input-file.md +++ b/docs/site/docs/test-doubles/input-file.md @@ -25,4 +25,45 @@ inputFile.UploadFile(fileToUpload); // Assertions... ``` -To upload binary content, create an `InputFileContent` with the `InputFileContent.CreateFromBinary()` method. \ No newline at end of file +To upload binary content, create an `InputFileContent` with the `InputFileContent.CreateFromBinary()` method. + +## Known limitations +bUnit's support for the `InputFile` component is limited when uploading and resizing images (using the provided stream). + +```razor + + + +@code { + private string imageBase64 = string.Empty; + + private async Task Upload(InputFileChangeEventArgs args) + { + var file = args.File; + var preview = await file.RequestImageFileAsync("image/png", 100, 100); + await using var stream = preview.OpenReadStream(); + var buffer = new byte[stream.Length]; + await using var memoryStream = new MemoryStream(buffer); + await stream.CopyToAsync(memoryStream); + var base64 = Convert.ToBase64String(buffer); + imageBase64 = $"data:image/png;base64,{base64}"; + } +} +``` + +When using the `RequestImageFileAsync` method, the `UploadFiles` method will not be able to upload the file inside a test. Blazor has some internal checks, bUnit can not overcome easily. So the following test will fail: + +```csharp +[Fact] +public void UploadFileTest() +{ + var cut = Render(); + + cut.FindComponent().UploadFiles(InputFileContent.CreateFromBinary([1,2], "test.png")); + + cut.Find("img").GetAttribute("src").Should().NotBeNullOrEmpty(); // Will fail + Renderer.UnhandledException.Should().BeNull(); // Will fail +} +``` + +To work around this limitation, refactoring the logic into a service that is injected into the component and then mocking the service in the test is a possible solution. \ No newline at end of file From e2c13d60078dd75f8d792c7690dd94e2947ebdab Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 2 Sep 2024 08:02:44 +0200 Subject: [PATCH 07/73] chore: Bump packages --- .github/workflows/release.yml | 5 ++--- src/Directory.Build.props | 2 +- .../bunit.generators.internal.csproj | 2 +- src/bunit.generators/bunit.generators.csproj | 2 +- .../template/Company.BlazorTests1.csproj | 2 +- tests/Directory.Build.props | 2 +- .../bunit.generators.tests.csproj | 12 ++++++------ 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9baec9601..bb6882b43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -111,9 +111,7 @@ jobs: run: git push origin stable - name: 🛠️ Create GitHub release - uses: thomaseizinger/create-release@1.0.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: thomaseizinger/create-release@2.0.0 with: tag_name: v${{ env.NBGV_SemVer2 }} target_commitish: ${{ env.RELEASE_COMMIT_HASH }} @@ -121,6 +119,7 @@ jobs: body: ${{ steps.changelog_reader.outputs.changes }} draft: false prerelease: ${{ env.NBGV_PublicRelease == 'False' }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: ⏩ Merge stable with main, push to origin id: mergeMainline diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 66d27a5ee..a46475d45 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -63,7 +63,7 @@ See the full changelog at https://github.com/bUnit-dev/bUnit/releases - + diff --git a/src/bunit.generators.internal/bunit.generators.internal.csproj b/src/bunit.generators.internal/bunit.generators.internal.csproj index baec0ddd1..f752855fb 100644 --- a/src/bunit.generators.internal/bunit.generators.internal.csproj +++ b/src/bunit.generators.internal/bunit.generators.internal.csproj @@ -16,7 +16,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/bunit.generators/bunit.generators.csproj b/src/bunit.generators/bunit.generators.csproj index dc358a049..b7f7c14b4 100644 --- a/src/bunit.generators/bunit.generators.csproj +++ b/src/bunit.generators/bunit.generators.csproj @@ -80,6 +80,6 @@ runtime; build; native; contentfiles; analyzers - + diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 4a443a344..cddc2d51c 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -17,7 +17,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 5c1e49b76..cf39b2404 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -25,7 +25,7 @@ - + diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index eb1708596..ff5b9bf20 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -13,14 +13,14 @@ - + - + - - - - + + + + From 11696faa3177023face73fa077c93d0253ea53c6 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 3 Sep 2024 20:49:56 +0100 Subject: [PATCH 08/73] docs: Fix heading (#1537) * Fix heading Fix heading not rendering correctly. * Fix heading Be gone, crazy space. --- .../docs/providing-input/passing-parameters-to-components.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/site/docs/providing-input/passing-parameters-to-components.md b/docs/site/docs/providing-input/passing-parameters-to-components.md index 4db2fccf1..a69b91875 100644 --- a/docs/site/docs/providing-input/passing-parameters-to-components.md +++ b/docs/site/docs/providing-input/passing-parameters-to-components.md @@ -466,7 +466,8 @@ When rendering a `RenderFragment` using the 's `Add` method, if a component parameter is only annotated with the `[SupplyParameterFromQuery]` attribute. Instead, pass a query string parameters by setting it using the . From 3d03d6f01f84757f7e78e9766600a7526417110c Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 3 Sep 2024 20:49:56 +0100 Subject: [PATCH 09/73] docs: Fix heading (#1537) * Fix heading Fix heading not rendering correctly. * Fix heading Be gone, crazy space. --- .../docs/providing-input/passing-parameters-to-components.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/site/docs/providing-input/passing-parameters-to-components.md b/docs/site/docs/providing-input/passing-parameters-to-components.md index 4db2fccf1..a69b91875 100644 --- a/docs/site/docs/providing-input/passing-parameters-to-components.md +++ b/docs/site/docs/providing-input/passing-parameters-to-components.md @@ -466,7 +466,8 @@ When rendering a `RenderFragment` using the 's `Add` method, if a component parameter is only annotated with the `[SupplyParameterFromQuery]` attribute. Instead, pass a query string parameters by setting it using the . From f8674d7f7d8c84026d025c51d30d31d2a1d8517d Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 4 Sep 2024 09:30:37 +0200 Subject: [PATCH 10/73] docs: Fix AddFakePersistentComponentState examples (Fixes #1539) (#1540) --- .../test-doubles/faking-persistentcomponentstate.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/site/docs/test-doubles/faking-persistentcomponentstate.md b/docs/site/docs/test-doubles/faking-persistentcomponentstate.md index c03f78110..9e28aa42c 100644 --- a/docs/site/docs/test-doubles/faking-persistentcomponentstate.md +++ b/docs/site/docs/test-doubles/faking-persistentcomponentstate.md @@ -12,7 +12,7 @@ bUnit comes with fake version of the `PersistentComponentState` type in Blazor t To use the fake `PersistentComponentState` in bUnit, call the `AddFakePersistentComponentState` extension method on `TestContext`: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); ``` Calling `AddFakePersistentComponentState` returns a `FakePersistentComponentState` type, which has three methods; one to persist data, one to get persisted data, and one that triggers any "OnPersisting" callbacks added to the `PersistentComponentState`. @@ -20,7 +20,7 @@ Calling `AddFakePersistentComponentState` returns a `FakePersistentComponentStat To add data to the `PersistentComponentState` before running a test, i.e. to verify that a component uses the persisted state, use the `Persist` method: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var key = "STATE KEY"; var data = ...; // data to persist @@ -31,7 +31,7 @@ fakeState.Persist(key, data); To trigger a callback registered with the `PersistentComponentState.RegisterOnPersisting` method, use the `TriggerOnPersisting` method on `FakePersistentComponentState`: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); // render component @@ -41,7 +41,7 @@ fakeState.TriggerOnPersisting(); To check if data has been persisted, use the `TryTake` method: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var key = "STATE KEY"; // render component, call TriggerOnPersisting @@ -95,7 +95,7 @@ To test that the `` component uses persisted weather data instead of ```csharp // Arrange -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); // Persist a single weather forecast with a temperature of 42 fakeState.Persist("weather-data", new [] { new WeatherForecast { Temperature = 42 } }); @@ -111,7 +111,7 @@ To test that the `` component correctly persists weather data when it ```csharp // Arrange -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var cut = RenderComponent(); // Act - trigger the FetchData components PersistForecasts method From f022007120e09bd99af38150d51d28661c7d9519 Mon Sep 17 00:00:00 2001 From: bUnit Bot <83116870+bUnitBot@users.noreply.github.com> Date: Wed, 4 Sep 2024 08:01:30 +0000 Subject: [PATCH 11/73] Update main with documentation in stable (#1541) * docs: Fix heading (#1537) * Fix heading Fix heading not rendering correctly. * Fix heading Be gone, crazy space. * docs: Fix AddFakePersistentComponentState examples (Fixes #1539) (#1540) --------- Co-authored-by: Martin Costello Co-authored-by: Steven Giesel --- .../test-doubles/faking-persistentcomponentstate.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/site/docs/test-doubles/faking-persistentcomponentstate.md b/docs/site/docs/test-doubles/faking-persistentcomponentstate.md index c03f78110..9e28aa42c 100644 --- a/docs/site/docs/test-doubles/faking-persistentcomponentstate.md +++ b/docs/site/docs/test-doubles/faking-persistentcomponentstate.md @@ -12,7 +12,7 @@ bUnit comes with fake version of the `PersistentComponentState` type in Blazor t To use the fake `PersistentComponentState` in bUnit, call the `AddFakePersistentComponentState` extension method on `TestContext`: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); ``` Calling `AddFakePersistentComponentState` returns a `FakePersistentComponentState` type, which has three methods; one to persist data, one to get persisted data, and one that triggers any "OnPersisting" callbacks added to the `PersistentComponentState`. @@ -20,7 +20,7 @@ Calling `AddFakePersistentComponentState` returns a `FakePersistentComponentStat To add data to the `PersistentComponentState` before running a test, i.e. to verify that a component uses the persisted state, use the `Persist` method: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var key = "STATE KEY"; var data = ...; // data to persist @@ -31,7 +31,7 @@ fakeState.Persist(key, data); To trigger a callback registered with the `PersistentComponentState.RegisterOnPersisting` method, use the `TriggerOnPersisting` method on `FakePersistentComponentState`: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); // render component @@ -41,7 +41,7 @@ fakeState.TriggerOnPersisting(); To check if data has been persisted, use the `TryTake` method: ```csharp -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var key = "STATE KEY"; // render component, call TriggerOnPersisting @@ -95,7 +95,7 @@ To test that the `` component uses persisted weather data instead of ```csharp // Arrange -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); // Persist a single weather forecast with a temperature of 42 fakeState.Persist("weather-data", new [] { new WeatherForecast { Temperature = 42 } }); @@ -111,7 +111,7 @@ To test that the `` component correctly persists weather data when it ```csharp // Arrange -var fakeState = AddFakePersistentComponentState(); +var fakeState = this.AddFakePersistentComponentState(); var cut = RenderComponent(); // Act - trigger the FetchData components PersistForecasts method From 4d44cfb9ade095598ccc86a9a4aaf7dbf4f81419 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 11 Sep 2024 08:30:10 +0200 Subject: [PATCH 12/73] fix: Fix tests for net9 --- src/bunit.generators/bunit.generators.csproj | 2 +- .../template/Company.BlazorTests1.csproj | 2 +- tests/Directory.Build.props | 2 +- .../bunit.generators.tests.csproj | 4 +-- ...irtualizeJSRuntimeInvocationHandlerTest.cs | 34 +++++++++++++------ 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/bunit.generators/bunit.generators.csproj b/src/bunit.generators/bunit.generators.csproj index b7f7c14b4..35db4af3c 100644 --- a/src/bunit.generators/bunit.generators.csproj +++ b/src/bunit.generators/bunit.generators.csproj @@ -70,7 +70,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index cddc2d51c..2801d2147 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -17,7 +17,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index cf39b2404..b1a3039cd 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -25,7 +25,7 @@ - + diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index ff5b9bf20..3c3f50905 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -13,10 +13,10 @@ - + - + diff --git a/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs b/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs index 7df771ecb..79cf12382 100644 --- a/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs +++ b/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs @@ -11,10 +11,10 @@ namespace Bunit.JSInterop.ComponentSupport; public class VirtualizeJSRuntimeInvocationHandlerTest : TestContext { - public static readonly IEnumerable ItemsInCollection = new object[][] - { - new object[] { 0 }, new object[] { 7 }, new object[] { 30 }, new object[] { 60 }, new object[] { 100 }, new object[] { 300 }, new object[] { 500 }, - }; + public static readonly IEnumerable ItemsInCollection = + [ + [0], [7], [30], [60], [100], [300], [500], + ]; [Theory(DisplayName = "Can render component using with ChildContent")] [MemberData(nameof(ItemsInCollection))] @@ -22,6 +22,9 @@ public void Test001(int itemsInDataSource) { var cut = RenderComponent>(ps => ps .Add(p => p.Items, CreateItems(itemsInDataSource)) +#if NET9_0_OR_GREATER + .Add(p => p.MaxItemCount, itemsInDataSource) +#endif .Add(p => p.ChildContent, item => $"

{item}

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

{item}

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

{item}

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

{item}

")); cut.FindAll("p").Count.ShouldBe(itemsInDataSource); @@ -63,12 +75,8 @@ public void Test011(int itemsInDataSource) public static readonly IEnumerable ItemCountItemSizeOverscanCount = ItemsInCollection.Select(x => new object[][] { - new object[] { x[0], 1, 3 }, - new object[] { x[0], 1_000_000, 3 }, - new object[] { x[0], 50, 1 }, - new object[] { x[0], 50, 1_000_000 }, - new object[] { x[0], 1, 1 }, - new object[] { x[0], 1_000_000, 1_000_000 }, + [x[0], 1, 3], [x[0], 1_000_000, 3], [x[0], 50, 1], [x[0], 50, 1_000_000], [x[0], 1, 1], [x[0], 1_000_000, 1_000_000 + ], }).SelectMany(x => x); [Theory(DisplayName = "Can render component using and different ItemSize and OverscanCount")] @@ -79,6 +87,9 @@ public void Test030(int itemsInDataSource, float itemSize, int overscanCount) .Add(p => p.ItemsProvider, CreateItemsProvider(itemsInDataSource)) .Add(p => p.ItemContent, item => $"

{item}

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

{item}

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

")); cut.FindAll(".placeholder").Count.ShouldBe(itemsInDataSource); From d6888eb2994b7a23b783050c636fc30e76dd91cd Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 11 Sep 2024 17:03:39 +0200 Subject: [PATCH 13/73] refactor: Use TheoryData --- ...irtualizeJSRuntimeInvocationHandlerTest.cs | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs b/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs index 79cf12382..4ca33d9c9 100644 --- a/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs +++ b/tests/bunit.web.tests/JSInterop/InvocationHandlers/VirtualizeJSRuntimeInvocationHandlerTest.cs @@ -11,10 +11,10 @@ namespace Bunit.JSInterop.ComponentSupport; public class VirtualizeJSRuntimeInvocationHandlerTest : TestContext { - public static readonly IEnumerable ItemsInCollection = - [ - [0], [7], [30], [60], [100], [300], [500], - ]; + public static readonly TheoryData ItemsInCollection = new() + { + 0, 7, 30, 60, 100, 300, 500, + }; [Theory(DisplayName = "Can render component using with ChildContent")] [MemberData(nameof(ItemsInCollection))] @@ -72,12 +72,51 @@ public void Test011(int itemsInDataSource) cut.FindAll("p").Count.ShouldBe(itemsInDataSource); } - public static readonly IEnumerable ItemCountItemSizeOverscanCount = - ItemsInCollection.Select(x => new object[][] - { - [x[0], 1, 3], [x[0], 1_000_000, 3], [x[0], 50, 1], [x[0], 50, 1_000_000], [x[0], 1, 1], [x[0], 1_000_000, 1_000_000 - ], - }).SelectMany(x => x); + public static readonly TheoryData ItemCountItemSizeOverscanCount = new() + { + { 0, 1, 3 }, + { 0, 1_000_000, 3 }, + { 0, 50, 1 }, + { 0, 50, 1_000_000 }, + { 0, 1, 1 }, + { 0, 1_000_000, 1_000_000 }, + { 7, 1, 3 }, + { 7, 1_000_000, 3 }, + { 7, 50, 1 }, + { 7, 50, 1_000_000 }, + { 7, 1, 1 }, + { 7, 1_000_000, 1_000_000 }, + { 30, 1, 3 }, + { 30, 1_000_000, 3 }, + { 30, 50, 1 }, + { 30, 50, 1_000_000 }, + { 30, 1, 1 }, + { 30, 1_000_000, 1_000_000 }, + { 60, 1, 3 }, + { 60, 1_000_000, 3 }, + { 60, 50, 1 }, + { 60, 50, 1_000_000 }, + { 60, 1, 1 }, + { 60, 1_000_000, 1_000_000 }, + { 100, 1, 3 }, + { 100, 1_000_000, 3 }, + { 100, 50, 1 }, + { 100, 50, 1_000_000 }, + { 100, 1, 1 }, + { 100, 1_000_000, 1_000_000 }, + { 300, 1, 3 }, + { 300, 1_000_000, 3 }, + { 300, 50, 1 }, + { 300, 50, 1_000_000 }, + { 300, 1, 1 }, + { 300, 1_000_000, 1_000_000 }, + { 500, 1, 3 }, + { 500, 1_000_000, 3 }, + { 500, 50, 1 }, + { 500, 50, 1_000_000 }, + { 500, 1, 1 }, + { 500, 1_000_000, 1_000_000 } + }; [Theory(DisplayName = "Can render component using and different ItemSize and OverscanCount")] [MemberData(nameof(ItemCountItemSizeOverscanCount))] From c75e9bd3935d10931802274748f39fc24ab76d9a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 12 Sep 2024 07:32:29 +0200 Subject: [PATCH 14/73] fix: Remove explicit dependency --- tests/bunit.generators.tests/bunit.generators.tests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index 3c3f50905..4ec1f4acd 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -17,7 +17,6 @@ - From 10b4525e75c97a27081182ea618844547ed4b47d Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 11 Sep 2024 08:19:33 +0200 Subject: [PATCH 15/73] fix: Use docfx.json as replacement target --- .github/workflows/docs-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index e8ebf51f1..bd0cf29b3 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -60,10 +60,10 @@ jobs: with: path: ./CHANGELOG.md - - name: 🛠️ Update tokens in project files + - name: 🛠️ Update tokens in files uses: cschleiden/replace-tokens@v1 with: - files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' + files: '["docs/site/*.md", "docs/**/*.md", "docs/**/docfx.json", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' env: RELEASE_VERSION: ${{ steps.changelog_reader.outputs.version }} RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} From d3b0242817ca6537b9301f30303d02a9cd23f9ae Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 13 Sep 2024 17:10:10 +0200 Subject: [PATCH 16/73] feat: use Central Package Management --- .editorconfig | 1 + .github/workflows/ci.yml | 7 +- Directory.Build.props | 18 +- Directory.Packages.props | 165 ++++++++++++++++++ benchmark/Directory.Build.props | 3 - bunit.sln | 20 +-- .../components/bunit.docs.samples.csproj | 56 +----- docs/samples/myfile.json | 20 +++ docs/samples/samples.sln | 5 + docs/samples/tests/Directory.Build.props | 17 +- .../mstest/bunit.docs.mstest.samples.csproj | 15 +- .../nunit/bunit.docs.nunit.samples.csproj | 10 +- .../razor/bunit.docs.razor.samples.csproj | 13 +- .../xunit/ComponentFactoryExampleTest.cs | 2 +- .../xunit/bunit.docs.xunit.samples.csproj | 25 ++- src/Directory.Build.props | 16 +- src/bunit.core/bunit.core.csproj | 41 +---- .../Web.AngleSharp/WrapperElementGenerator.cs | 14 +- .../bunit.generators.internal.csproj | 14 +- src/bunit.generators/Directory.Build.props | 4 - .../AddStubGenerator.cs | 27 ++- .../Web.Stubs/AttributeLineGenerator.cs | 6 +- .../ComponentStubAttribute.cs | 2 +- .../ComponentStubAttributeGenerator.cs | 24 +-- src/bunit.generators/bunit.generators.csproj | 39 +---- src/bunit.template/bunit.template.csproj | 11 +- src/bunit.web.query/bunit.web.query.csproj | 46 ++--- src/bunit.web/bunit.web.csproj | 93 +++------- src/bunit/bunit.csproj | 7 + tests/Directory.Build.props | 20 ++- .../bunit.core.tests/bunit.core.tests.csproj | 11 -- .../Directory.Build.props | 4 - .../Web.Stub/Components/CounterComponent.cs | 10 +- .../bunit.generators.tests.csproj | 24 +-- .../bunit.testassets/bunit.testassets.csproj | 53 ++---- .../bunit.web.query.tests.csproj | 10 -- tests/bunit.web.tests/bunit.web.tests.csproj | 10 -- 37 files changed, 386 insertions(+), 477 deletions(-) create mode 100644 Directory.Packages.props create mode 100644 docs/samples/myfile.json delete mode 100644 src/bunit.generators/Directory.Build.props delete mode 100644 tests/bunit.generators.tests/Directory.Build.props diff --git a/.editorconfig b/.editorconfig index 1ee6999e5..678b64563 100644 --- a/.editorconfig +++ b/.editorconfig @@ -453,6 +453,7 @@ dotnet_diagnostic.S112.severity = none # S112: General exceptions should never b dotnet_diagnostic.S1075.severity = suggestion # S1075: URIs should not be hardcoded dotnet_diagnostic.S1186.severity = suggestion # S1186: Methods should not be empty dotnet_diagnostic.S2292.severity = suggestion # S2292: Trivial properties should be auto-implemented +dotnet_diagnostic.S3267.severity = suggestion # S3267: Convert foreach loop to LINQ query dotnet_diagnostic.S4158.severity = none # BUGGY with C#9 code - doesnt understand local methods # Razor specific rules diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31b34874a..28d2a8ebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -149,7 +149,7 @@ jobs: **/*hangdump.dmp **/*crashdump.dmp - validate_template: + validate-template: runs-on: ubuntu-latest needs: [ create-nuget ] steps: @@ -178,6 +178,7 @@ jobs: run: | dotnet new bunit --no-restore -o ${{ github.workspace }}/TemplateTestXunit echo '' >> ${{ github.workspace }}/TemplateTestXunit/Directory.Build.props + echo 'false' >> ${{ github.workspace }}/TemplateTestXunit/Directory.Packages.props dotnet restore ${{ github.workspace }}/TemplateTestXunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} dotnet test ${{ github.workspace }}/TemplateTestXunit @@ -185,6 +186,7 @@ jobs: run: | dotnet new bunit --framework nunit --no-restore -o ${{ github.workspace }}/TemplateTestNunit echo '' >> ${{ github.workspace }}/TemplateTestNunit/Directory.Build.props + echo 'false' >> ${{ github.workspace }}/TemplateTestNunit/Directory.Packages.props dotnet restore ${{ github.workspace }}/TemplateTestNunit --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} dotnet test ${{ github.workspace }}/TemplateTestNunit @@ -192,6 +194,7 @@ jobs: run: | dotnet new bunit --framework mstest --no-restore -o ${{ github.workspace }}/TemplateTestMstest echo '' >> ${{ github.workspace }}/TemplateTestMstest/Directory.Build.props + echo 'false' >> ${{ github.workspace }}/TemplateTestMstest/Directory.Packages.props dotnet restore ${{ github.workspace }}/TemplateTestMstest --source https://api.nuget.org/v3/index.json --source ${{ env.NUGET_DIRECTORY }} dotnet test ${{ github.workspace }}/TemplateTestMstest @@ -254,7 +257,7 @@ jobs: release-preview: if: github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/v2') runs-on: ubuntu-latest - needs: [ validate-nuget, run-test, validate_template, validate-docs ] + needs: [ validate-nuget, run-test, validate-template, validate-docs ] steps: - uses: actions/download-artifact@v4 with: diff --git a/Directory.Build.props b/Directory.Build.props index c4b492f6a..a3c2a053a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,15 +1,6 @@ - - 3.1.* - 5.0.* - 6.0.* - 7.0.* - 8.0.* - 9.0.0-* - - Egil Hansen @@ -49,14 +40,7 @@ true - - - - - - - + diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 000000000..ed2bd1ef2 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,165 @@ + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/benchmark/Directory.Build.props b/benchmark/Directory.Build.props index 62cb9cc94..27b0bf9c3 100644 --- a/benchmark/Directory.Build.props +++ b/benchmark/Directory.Build.props @@ -1,9 +1,6 @@ - enable - 10.0 - enable CA1014,NU5104 false diff --git a/bunit.sln b/bunit.sln index 4ce0606e1..676bde85f 100644 --- a/bunit.sln +++ b/bunit.sln @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{A5D7B6 .config\dotnet-tools.json = .config\dotnet-tools.json global.json = global.json version.json = version.json + Directory.Packages.props = Directory.Packages.props EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9A2B3B34-D41C-43E8-BC7D-246BEBE48D59}" @@ -56,15 +57,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".workflows", ".workflows", .github\workflows\release.yml = .github\workflows\release.yml EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{F6084D31-2A92-4794-A47E-A8F2254E6970}" - ProjectSection(SolutionItems) = preProject - benchmark\Directory.Build.props = benchmark\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.benchmarks", "benchmark\bunit.benchmarks\bunit.benchmarks.csproj", "{9F7A0623-8294-4A5D-946F-70C481732AA5}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.benchmarks.assets", "benchmark\bunit.benchmarks.assets\bunit.benchmarks.assets.csproj", "{3619481F-DF6F-4399-9FED-450EE545A19E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.query", "src\bunit.web.query\bunit.web.query.csproj", "{0FF92169-7D8F-46A2-8327-A2F028CB426F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.web.query.tests", "tests\bunit.web.query.tests\bunit.web.query.tests.csproj", "{DE975A0C-0672-4248-913E-D267C1001801}" @@ -105,14 +97,6 @@ Global {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Debug|Any CPU.Build.0 = Debug|Any CPU {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Release|Any CPU.ActiveCfg = Release|Any CPU {7972A80F-30DC-4EF4-9294-7D4DD2965882}.Release|Any CPU.Build.0 = Release|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9F7A0623-8294-4A5D-946F-70C481732AA5}.Release|Any CPU.Build.0 = Release|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3619481F-DF6F-4399-9FED-450EE545A19E}.Release|Any CPU.Build.0 = Release|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Debug|Any CPU.Build.0 = Debug|Any CPU {0FF92169-7D8F-46A2-8327-A2F028CB426F}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -145,8 +129,6 @@ Global {6127D121-9387-451B-B15D-8350A32D3001} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} {FC122F63-8B22-4BAE-B96A-7AF3194CD204} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {7972A80F-30DC-4EF4-9294-7D4DD2965882} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} - {9F7A0623-8294-4A5D-946F-70C481732AA5} = {F6084D31-2A92-4794-A47E-A8F2254E6970} - {3619481F-DF6F-4399-9FED-450EE545A19E} = {F6084D31-2A92-4794-A47E-A8F2254E6970} {0FF92169-7D8F-46A2-8327-A2F028CB426F} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} {DE975A0C-0672-4248-913E-D267C1001801} = {6EA09ED4-B714-4E6F-B0E1-4D987F8AE520} {AE3DFB52-2BF4-4806-AD82-7FB7B38AC17F} = {9A2B3B34-D41C-43E8-BC7D-246BEBE48D59} diff --git a/docs/samples/components/bunit.docs.samples.csproj b/docs/samples/components/bunit.docs.samples.csproj index aa97c0fe7..5bc4c1ae9 100644 --- a/docs/samples/components/bunit.docs.samples.csproj +++ b/docs/samples/components/bunit.docs.samples.csproj @@ -1,61 +1,19 @@ - netstandard2.0;net5.0;net6.0;net7.0;net8.0;net9.0 + net8.0 latest - 3.0 Bunit.Docs.Samples enable CA1014,NU5104 false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - diff --git a/docs/samples/myfile.json b/docs/samples/myfile.json new file mode 100644 index 000000000..72ec0a029 --- /dev/null +++ b/docs/samples/myfile.json @@ -0,0 +1,20 @@ +'packages' was not matched. Did you mean one of the following? +package + +Description: + List references or packages of a .NET project. + +Usage: + dotnet list [] [command] [options] + +Arguments: + The project or solution file to operate on. If a file is not specified, the command will search the current + directory for one. [default: /Users/stevengiesel/repos/bUnit/docs/samples/] + +Options: + -?, -h, --help Show command line help. + +Commands: + package List all package references of the project or solution. + reference List all project-to-project references of the project. + diff --git a/docs/samples/samples.sln b/docs/samples/samples.sln index 153a2c535..ed724da75 100644 --- a/docs/samples/samples.sln +++ b/docs/samples/samples.sln @@ -18,6 +18,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.docs.xunit.samples", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.docs.razor.samples", "tests\razor\bunit.docs.razor.samples.csproj", "{C92CB47E-8A70-409C-9213-8D743BB29366}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7066A15B-F4AC-43FE-97FF-80B321F29A06}" + ProjectSection(SolutionItems) = preProject + ..\..\Directory.Packages.props = ..\..\Directory.Packages.props + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/docs/samples/tests/Directory.Build.props b/docs/samples/tests/Directory.Build.props index e5b3bbe6b..b79778dbc 100644 --- a/docs/samples/tests/Directory.Build.props +++ b/docs/samples/tests/Directory.Build.props @@ -1,27 +1,14 @@ - netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + net8.0 false true false true latest - 3.0 enable - CA1014,NU5104 + CA1014,NU5104,xUnit1031 false - - - - - - - - - - - - diff --git a/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj b/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj index 2d6428b0b..3dc4399a2 100644 --- a/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj +++ b/docs/samples/tests/mstest/bunit.docs.mstest.samples.csproj @@ -5,12 +5,15 @@ - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj b/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj index a51a9ff84..f0b0211a4 100644 --- a/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj +++ b/docs/samples/tests/nunit/bunit.docs.nunit.samples.csproj @@ -5,11 +5,11 @@ - - - - - + + + + + diff --git a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj index 9dff4b342..50e257101 100644 --- a/docs/samples/tests/razor/bunit.docs.razor.samples.csproj +++ b/docs/samples/tests/razor/bunit.docs.razor.samples.csproj @@ -5,13 +5,12 @@ - - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers NU1701 diff --git a/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs b/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs index 580ab4096..b811e54a3 100644 --- a/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs +++ b/docs/samples/tests/xunit/ComponentFactoryExampleTest.cs @@ -21,7 +21,7 @@ public void ReplacesFooWithBarDuringTest() // Assert that there are no in render tree, // but there is one in the render tree. Assert.Empty(cut.FindComponents()); - Assert.Equal(1, cut.FindComponents().Count); + Assert.Single(cut.FindComponents()); } } } diff --git a/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj b/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj index 96ed4edf4..ebb9e06e2 100644 --- a/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj +++ b/docs/samples/tests/xunit/bunit.docs.xunit.samples.csproj @@ -5,19 +5,18 @@ - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - NU1701 - + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + NU1701 + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a46475d45..9bfb6c0e8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -21,7 +21,9 @@ embedded true + + true true 1.25.3 @@ -51,10 +53,6 @@ See the full changelog at https://github.com/bUnit-dev/bUnit/releases - - True - \ - True \ @@ -62,8 +60,14 @@ See the full changelog at https://github.com/bUnit-dev/bUnit/releases - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/bunit.core/bunit.core.csproj b/src/bunit.core/bunit.core.csproj index e1e8b2818..41434ae48 100644 --- a/src/bunit.core/bunit.core.csproj +++ b/src/bunit.core/bunit.core.csproj @@ -14,40 +14,17 @@ - - - - + + + True + \ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/src/bunit.generators.internal/Web.AngleSharp/WrapperElementGenerator.cs b/src/bunit.generators.internal/Web.AngleSharp/WrapperElementGenerator.cs index b8b294e0a..81d0039e7 100644 --- a/src/bunit.generators.internal/Web.AngleSharp/WrapperElementGenerator.cs +++ b/src/bunit.generators.internal/Web.AngleSharp/WrapperElementGenerator.cs @@ -64,7 +64,7 @@ private static void GenerateOrdinaryMethod(StringBuilder source, IMethodSymbol m var methodParts = method.ToDisplayParts(GeneratorConfig.SymbolFormat); // It seems that the ToDisplayParts will return ... - // + // // public global::AngleSharp.Dom.IShadowRoot AttachShadow(global::AngleSharp.Dom.ShadowRootMode mode = 0) // // when called on a method with a default enum parameters specified. @@ -173,18 +173,6 @@ private static IEnumerable GetAllMembers(this INamedTypeSymbol symbol) } } - private static StringBuilder AppendInputArguments(this StringBuilder source, ImmutableArray parameters) - { - for (int i = 0; i < parameters.Length; i++) - { - if (i > 0) - source.Append(", "); - - source.Append($"{parameters[i].Type.ToDisplayString(GeneratorConfig.SymbolFormat)} {parameters[i].Name}"); - } - return source; - } - private static StringBuilder AppendCallParameters(this StringBuilder source, ImmutableArray parameters) { for (int i = 0; i < parameters.Length; i++) diff --git a/src/bunit.generators.internal/bunit.generators.internal.csproj b/src/bunit.generators.internal/bunit.generators.internal.csproj index f752855fb..cae79f712 100644 --- a/src/bunit.generators.internal/bunit.generators.internal.csproj +++ b/src/bunit.generators.internal/bunit.generators.internal.csproj @@ -15,16 +15,10 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers - + + + + diff --git a/src/bunit.generators/Directory.Build.props b/src/bunit.generators/Directory.Build.props deleted file mode 100644 index 6e4cd6d46..000000000 --- a/src/bunit.generators/Directory.Build.props +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs b/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs index 907dd6e78..6c7933786 100644 --- a/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs +++ b/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -29,18 +26,18 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterSourceOutput( classesToStub, - static (spc, source) => Execute(source, spc)); + static (spc, source) => Execute(source!, spc)); } - private static AddStubClassInfo GetStubClassInfo(GeneratorSyntaxContext context) + private static AddStubClassInfo? GetStubClassInfo(GeneratorSyntaxContext context) { var invocation = context.Node as InvocationExpressionSyntax; - if (!IsComponentFactoryStubMethod(invocation, context.SemanticModel)) + if (invocation is null || !IsComponentFactoryStubMethod(invocation, context.SemanticModel)) { return null; } - if (invocation?.Expression is not MemberAccessExpressionSyntax + if (invocation.Expression is not MemberAccessExpressionSyntax { Name: GenericNameSyntax { TypeArgumentList.Arguments.Count: 1 } genericName }) @@ -183,7 +180,7 @@ private static bool GenerateStubComponent(AddStubClassInfo classInfo, SourceProd sourceBuilder.AppendLine($"namespace {classInfo.TargetTypeNamespace};"); sourceBuilder.AppendLine(); sourceBuilder.AppendLine($"internal partial class {classInfo.StubClassName} : global::Microsoft.AspNetCore.Components.ComponentBase"); - sourceBuilder.Append("{"); + sourceBuilder.Append('{'); foreach (var member in classInfo.Properties) { @@ -212,19 +209,19 @@ private static bool GenerateStubComponent(AddStubClassInfo classInfo, SourceProd internal sealed record AddStubClassInfo { - public string StubClassName { get; set; } - public string TargetTypeNamespace { get; set; } - public string TargetTypeName { get; set; } + public required string StubClassName { get; set; } + public required string TargetTypeNamespace { get; set; } + public required string TargetTypeName { get; set; } public string UniqueQualifier => $"{TargetTypeNamespace}.{StubClassName}"; public ImmutableArray Properties { get; set; } = ImmutableArray.Empty; - public string Path { get; set; } + public required string Path { get; set; } public int Line { get; set; } public int Column { get; set; } } internal sealed record StubPropertyInfo { - public string Name { get; set; } - public string Type { get; set; } - public string AttributeLine { get; set; } + public required string Name { get; set; } + public required string Type { get; set; } + public required string AttributeLine { get; set; } } diff --git a/src/bunit.generators/Web.Stubs/AttributeLineGenerator.cs b/src/bunit.generators/Web.Stubs/AttributeLineGenerator.cs index 8185929a2..774b676bd 100644 --- a/src/bunit.generators/Web.Stubs/AttributeLineGenerator.cs +++ b/src/bunit.generators/Web.Stubs/AttributeLineGenerator.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Diagnostics.CodeAnalysis; using System.Text; using Microsoft.CodeAnalysis; @@ -6,6 +6,8 @@ namespace Bunit.Web.Stubs; internal static class AttributeLineGenerator { + [SuppressMessage("SonarLint", "S1862: Unused method parameters should be removed", Justification = "False Positive")] + [SuppressMessage("SonarLint", "S1871: Either merge this branch with the identical one", Justification = "False Positive")] public static string GetAttributeLine(ISymbol member) { var attribute = member.GetAttributes().First(SupportedAttributes.IsSupportedAttribute); @@ -64,7 +66,7 @@ public static string GetAttributeLine(ISymbol member) } } - attributeLine.Append("]"); + attributeLine.Append(']'); return attributeLine.ToString(); } } diff --git a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttribute.cs b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttribute.cs index f8c809770..ac206b060 100644 --- a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttribute.cs +++ b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttribute.cs @@ -2,7 +2,7 @@ namespace Bunit.Web.Stubs.AttributeStubGenerator; internal static class ComponentStubAttribute { - public static string ComponentStubAttributeSource = $$""" + public const string ComponentStubAttributeSource = $$""" {{HeaderProvider.Header}} #if NET5_0_OR_GREATER diff --git a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs index df91cc095..d36fcf184 100644 --- a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs +++ b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs @@ -1,5 +1,6 @@ using System.Collections.Immutable; -using System.Linq; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -32,14 +33,15 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterSourceOutput( classesToStub, - static (spc, source) => Execute(source, spc)); + static (spc, source) => Execute(source!, spc)); } private static bool IsClassWithComponentStubAttribute(SyntaxNode s) => s is ClassDeclarationSyntax c && c.AttributeLists.SelectMany(a => a.Attributes) .Any(at => at.Name.ToString().Contains("ComponentStub")); - private static StubClassInfo GetStubClassInfo(GeneratorAttributeSyntaxContext context) + [SuppressMessage("Bug", "CA1308: Normalize strings to uppercase", Justification = "On purpose")] + private static StubClassInfo? GetStubClassInfo(GeneratorAttributeSyntaxContext context) { foreach (var attribute in context.TargetSymbol.GetAttributes()) { @@ -50,7 +52,7 @@ private static StubClassInfo GetStubClassInfo(GeneratorAttributeSyntaxContext co var namespaceName = stubbedType.ContainingNamespace.ToDisplayString(); var className = context.TargetSymbol.Name; - var visibility = context.TargetSymbol.DeclaredAccessibility.ToString().ToLower(); + var visibility = context.TargetSymbol.DeclaredAccessibility.ToString().ToLowerInvariant(); var isPartial = ((ClassDeclarationSyntax)context.TargetNode).Modifiers.Any(SyntaxKind.PartialKeyword); var originalTypeToStub = attribute.AttributeClass?.TypeArguments.FirstOrDefault(); @@ -110,7 +112,7 @@ private static void Execute(StubClassInfo classInfo, SourceProductionContext con sourceBuilder.AppendLine( $"{classInfo.Visibility} partial class {classInfo.ClassName} : global::Microsoft.AspNetCore.Components.ComponentBase"); - sourceBuilder.Append("{"); + sourceBuilder.Append('{'); foreach (var member in classInfo.Properties) { @@ -170,18 +172,18 @@ private static bool CheckDiagnostics(StubClassInfo classInfo, SourceProductionCo internal sealed record StubClassInfo { - public string ClassName { get; set; } - public string Namespace { get; set; } + public required string ClassName { get; set; } + public required string Namespace { get; set; } public ImmutableArray Properties { get; set; } = ImmutableArray.Empty; - public string Visibility { get; set; } + public required string Visibility { get; set; } public bool IsNestedClass { get; set; } public bool IsPartial { get; set; } } internal sealed record StubPropertyInfo { - public string Name { get; set; } - public string Type { get; set; } - public string AttributeLine { get; set; } + public required string Name { get; set; } + public required string Type { get; set; } + public required string AttributeLine { get; set; } } diff --git a/src/bunit.generators/bunit.generators.csproj b/src/bunit.generators/bunit.generators.csproj index 35db4af3c..cde790b2c 100644 --- a/src/bunit.generators/bunit.generators.csproj +++ b/src/bunit.generators/bunit.generators.csproj @@ -32,54 +32,29 @@ bUnit.generators is an extension to bUnit that provides code generators for stubbing components. - MIT - https://github.com/bUnit-dev/bUnit - git - https://bunit.egilhansen.com - bUnit;razor components;blazor components;unit testing;testing blazor components;blazor server;blazor wasm - Egil Hansen - Egil Hansen - Egil Hansen - bUnit - true - bunit-logo.png - README.md - - Changes in bUnit #{RELEASE_VERSION}# - - #{RELEASE_NOTES}# - - See the full changelog at https://github.com/bUnit-dev/bUnit/releases - - - True - \ - - - True + + true \ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all - runtime; build; native; contentfiles; analyzers + runtime; build; native; contentfiles; analyzers; buildtransitive - - diff --git a/src/bunit.template/bunit.template.csproj b/src/bunit.template/bunit.template.csproj index 0a44fb6fc..a27501923 100644 --- a/src/bunit.template/bunit.template.csproj +++ b/src/bunit.template/bunit.template.csproj @@ -18,9 +18,16 @@ true false - content + content + + + True + \ + + + @@ -29,7 +36,7 @@ - + diff --git a/src/bunit.web.query/bunit.web.query.csproj b/src/bunit.web.query/bunit.web.query.csproj index 1fedede0d..1ca8a2a01 100644 --- a/src/bunit.web.query/bunit.web.query.csproj +++ b/src/bunit.web.query/bunit.web.query.csproj @@ -14,44 +14,18 @@ - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - - - - - - - - - - - - + + + True + \ + - - - - + + + + + diff --git a/src/bunit.web/bunit.web.csproj b/src/bunit.web/bunit.web.csproj index 86401722d..10001735d 100644 --- a/src/bunit.web/bunit.web.csproj +++ b/src/bunit.web/bunit.web.csproj @@ -20,86 +20,35 @@ - + + True + \ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - + + diff --git a/src/bunit/bunit.csproj b/src/bunit/bunit.csproj index 95d9e8ab4..ff44fca70 100644 --- a/src/bunit/bunit.csproj +++ b/src/bunit/bunit.csproj @@ -20,6 +20,13 @@ + + + True + \ + + + diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index b1a3039cd..bc6cb5d3e 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -22,17 +22,19 @@ NU1903 - - - - - - - - + + + + + + + + + + - + diff --git a/tests/bunit.core.tests/bunit.core.tests.csproj b/tests/bunit.core.tests/bunit.core.tests.csproj index 62e64bfdd..4b549fe17 100644 --- a/tests/bunit.core.tests/bunit.core.tests.csproj +++ b/tests/bunit.core.tests/bunit.core.tests.csproj @@ -11,15 +11,4 @@ - - - - - - all - runtime; build; native; contentfiles; analyzers - NU1701 - - - \ No newline at end of file diff --git a/tests/bunit.generators.tests/Directory.Build.props b/tests/bunit.generators.tests/Directory.Build.props deleted file mode 100644 index 1e156caa2..000000000 --- a/tests/bunit.generators.tests/Directory.Build.props +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/tests/bunit.generators.tests/Web.Stub/Components/CounterComponent.cs b/tests/bunit.generators.tests/Web.Stub/Components/CounterComponent.cs index a8ca311b7..b0b6e5def 100644 --- a/tests/bunit.generators.tests/Web.Stub/Components/CounterComponent.cs +++ b/tests/bunit.generators.tests/Web.Stub/Components/CounterComponent.cs @@ -7,6 +7,12 @@ public class CounterComponent : ComponentBase { [Parameter] public int Count { get; set; } [CascadingParameter(Name = "Cascading")] public int CascadingCount { get; set; } - [Parameter(CaptureUnmatchedValues = true)] public Dictionary UnmatchedValues { get; set; } - [Required] public string Unused { get; set; } + + [Parameter(CaptureUnmatchedValues = true)] + private Dictionary? UnmatchedValues { get; set; } + + [SuppressMessage("Design", "CS0246: The type or namespace name could not be found", + Justification = "This is on purpose")] + [Required] + public string Unused { get; set; } = default!; } diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index 4ec1f4acd..6a1d634b2 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -8,26 +8,20 @@ true false true + false true $(InterceptorsPreviewNamespaces);Bunit - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers - + + + + + + + + diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index 07c94fb4a..424468974 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -14,49 +14,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj index f37f4ff1d..a126ed03e 100644 --- a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj +++ b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj @@ -13,14 +13,4 @@ - - - - - all - runtime; build; native; contentfiles; analyzers - NU1701 - - - \ 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 09885c8f4..62408f8e3 100644 --- a/tests/bunit.web.tests/bunit.web.tests.csproj +++ b/tests/bunit.web.tests/bunit.web.tests.csproj @@ -11,15 +11,5 @@ - - - - - - all - runtime; build; native; contentfiles; analyzers - NU1701 - - \ No newline at end of file From 5d2a8535a158e9a9a7f14a69ee1b8394018116fb Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 09:56:24 +0000 Subject: [PATCH 17/73] fix: force all tests to use new parallel xunit algorithm https://xunit.net/docs/running-tests-in-parallel#algorithms --- .github/workflows/ci.yml | 2 +- NuGet.Config | 7 +++++++ bunit.sln | 3 ++- tests/bunit.core.tests/bunit.core.tests.csproj | 5 +++++ tests/bunit.core.tests/xunit.runner.json | 4 ---- .../bunit.generators.tests/bunit.generators.tests.csproj | 4 ++++ tests/bunit.web.query.tests/bunit.web.query.tests.csproj | 4 ++++ tests/bunit.web.tests/bunit.web.tests.csproj | 6 +++++- tests/bunit.web.tests/xunit.runner.json | 4 ---- tests/xunit.runner.json | 8 ++++++++ 10 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 NuGet.Config delete mode 100644 tests/bunit.core.tests/xunit.runner.json delete mode 100644 tests/bunit.web.tests/xunit.runner.json create mode 100644 tests/xunit.runner.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28d2a8ebe..aafaffdda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,7 +137,7 @@ jobs: 9.0.x - name: 🧪 Run unit tests - run: dotnet test -c release -p:VSTestUseMSBuildOutput=false + run: dotnet test -c release -p:VSTestUseMSBuildOutput=false --logger "console;verbosity=normal" - name: 📛 Upload hang- and crash-dumps on test failure if: failure() diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 000000000..c5e21601d --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/bunit.sln b/bunit.sln index 676bde85f..07a425cf2 100644 --- a/bunit.sln +++ b/bunit.sln @@ -9,10 +9,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".items", ".items", "{A5D7B6 .gitattributes = .gitattributes .gitignore = .gitignore Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props .config\dotnet-tools.json = .config\dotnet-tools.json global.json = global.json version.json = version.json - Directory.Packages.props = Directory.Packages.props EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9A2B3B34-D41C-43E8-BC7D-246BEBE48D59}" @@ -26,6 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6EA09ED4 tests\.editorconfig = tests\.editorconfig tests\Directory.Build.props = tests\Directory.Build.props tests\run-tests.ps1 = tests\run-tests.ps1 + tests\xunit.runner.json = tests\xunit.runner.json EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".text", ".text", "{392FCD4E-356A-412A-A854-8EE197EA65B9}" diff --git a/tests/bunit.core.tests/bunit.core.tests.csproj b/tests/bunit.core.tests/bunit.core.tests.csproj index 4b549fe17..55fcbfa41 100644 --- a/tests/bunit.core.tests/bunit.core.tests.csproj +++ b/tests/bunit.core.tests/bunit.core.tests.csproj @@ -11,4 +11,9 @@ + + + + + \ No newline at end of file diff --git a/tests/bunit.core.tests/xunit.runner.json b/tests/bunit.core.tests/xunit.runner.json deleted file mode 100644 index e37151e81..000000000 --- a/tests/bunit.core.tests/xunit.runner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "diagnosticMessages": false -} diff --git a/tests/bunit.generators.tests/bunit.generators.tests.csproj b/tests/bunit.generators.tests/bunit.generators.tests.csproj index 6a1d634b2..89098229e 100644 --- a/tests/bunit.generators.tests/bunit.generators.tests.csproj +++ b/tests/bunit.generators.tests/bunit.generators.tests.csproj @@ -30,4 +30,8 @@ + + + + diff --git a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj index a126ed03e..c9c1da279 100644 --- a/tests/bunit.web.query.tests/bunit.web.query.tests.csproj +++ b/tests/bunit.web.query.tests/bunit.web.query.tests.csproj @@ -13,4 +13,8 @@ + + + + \ 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 62408f8e3..b5319668b 100644 --- a/tests/bunit.web.tests/bunit.web.tests.csproj +++ b/tests/bunit.web.tests/bunit.web.tests.csproj @@ -11,5 +11,9 @@ - + + + + + \ No newline at end of file diff --git a/tests/bunit.web.tests/xunit.runner.json b/tests/bunit.web.tests/xunit.runner.json deleted file mode 100644 index e37151e81..000000000 --- a/tests/bunit.web.tests/xunit.runner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "diagnosticMessages": false -} diff --git a/tests/xunit.runner.json b/tests/xunit.runner.json new file mode 100644 index 000000000..2197c2b2b --- /dev/null +++ b/tests/xunit.runner.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "diagnosticMessages": false, + "methodDisplayOptions": "all", + "parallelAlgorithm": "conservative", + "maxParallelThreads": "2x", + "parallelizeTestCollections": true +} From ac8603c999c183535c4e72fc16c1ee9d6706d5da Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 10:11:05 +0000 Subject: [PATCH 18/73] chore: upgrade package dependencies --- Directory.Packages.props | 18 +++++++++--------- .../XunitExtensions/TheoryDataExtensions.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index ed2bd1ef2..fb4cd0bdd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -111,18 +111,18 @@ - - + + - + - + @@ -137,16 +137,16 @@ - - + + - + - - + + diff --git a/tests/bunit.testassets/XunitExtensions/TheoryDataExtensions.cs b/tests/bunit.testassets/XunitExtensions/TheoryDataExtensions.cs index 505c1edcc..22d975164 100644 --- a/tests/bunit.testassets/XunitExtensions/TheoryDataExtensions.cs +++ b/tests/bunit.testassets/XunitExtensions/TheoryDataExtensions.cs @@ -7,7 +7,7 @@ public static TheoryData Clone(this TheoryData existing) var result = new TheoryData(); foreach (var item in existing) { - result.Add((T)item[0]); + result.Add(item); } return result; } From 9175219fb3fe18494643c0d3e3c892ced7cd3496 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 10:24:17 +0000 Subject: [PATCH 19/73] ci: add test reporter for easier overview of test results --- .github/workflows/ci.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aafaffdda..06428e4ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,7 +137,18 @@ jobs: 9.0.x - name: 🧪 Run unit tests - run: dotnet test -c release -p:VSTestUseMSBuildOutput=false --logger "console;verbosity=normal" + run: dotnet test -c release -p:VSTestUseMSBuildOutput=false --verbosity normal --logger trx --results-directory TestResults --collect "XPlat Code Coverage" + + - name: Test Reports + uses: bibipkins/dotnet-test-reporter@v1.4.1 + if: always() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + comment-title: "Unit Test Results" + results-path: ./TestResults/*.trx + coverage-path: ./TestResults/**/coverage.cobertura.xml + coverage-type: cobertura + coverage-threshold: 0.00 - name: 📛 Upload hang- and crash-dumps on test failure if: failure() From 74da2fa586ce943e6a55f860517cac0e3aa33942 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 10:28:12 +0000 Subject: [PATCH 20/73] chore: set correct package versions available on nuget.org --- Directory.Packages.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index fb4cd0bdd..d00dd8b91 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -111,13 +111,13 @@ - - + + - + From 29af08e51ca244e2cbfe413fbad592c920ee6571 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 11:47:42 +0000 Subject: [PATCH 21/73] ci: collect test reports --- .github/workflows/ci.yml | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06428e4ca..549e5588c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -136,29 +136,34 @@ jobs: 8.0.x 9.0.x + - name: ⚙️ Setup GIT versioning + run: | + dotnet restore + dotnet tool restore + - name: 🧪 Run unit tests - run: dotnet test -c release -p:VSTestUseMSBuildOutput=false --verbosity normal --logger trx --results-directory TestResults --collect "XPlat Code Coverage" + run: dotnet test -c release --no-restore -p:VSTestUseMSBuildOutput=false --logger "trx" - - name: Test Reports - uses: bibipkins/dotnet-test-reporter@v1.4.1 - if: always() + - name: Test Report + uses: dorny/test-reporter@v1 + if: success() || failure() with: - github-token: ${{ secrets.GITHUB_TOKEN }} - comment-title: "Unit Test Results" - results-path: ./TestResults/*.trx - coverage-path: ./TestResults/**/coverage.cobertura.xml - coverage-type: cobertura - coverage-threshold: 0.00 + name: 'CI Test Results ${{ matrix.os }}' + reporter: 'dotnet-trx' + list-tests: 'failed' + list-suites: 'failed' + path: '**/*.trx' + fail-on-error: false - name: 📛 Upload hang- and crash-dumps on test failure - if: failure() + if: success() || failure() uses: actions/upload-artifact@v3 with: if-no-files-found: ignore name: test-dumps path: | - **/*hangdump.dmp - **/*crashdump.dmp + **/*.dmp + **/*.dmp validate-template: runs-on: ubuntu-latest From 31738c47c89f8b84b403f7554076716226705975 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 3 Oct 2024 10:07:23 +0000 Subject: [PATCH 22/73] docs: remove aws from main readme --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index a1f0bb490..a923f6597 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,6 @@ A huge thank you to the [sponsors of my work with bUnit](https://github.com/spon Syncfusion - - - @aws -
- Amazon Web Services -
- From 85f0a0795f4ed7079b6d1be6c72307aadd404add Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 3 Oct 2024 10:08:10 +0000 Subject: [PATCH 23/73] docs: remove aws from bunit.dev homepage --- docs/site/index.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/site/index.md b/docs/site/index.md index a5a62bfe9..aa7eef8bf 100644 --- a/docs/site/index.md +++ b/docs/site/index.md @@ -63,11 +63,6 @@ A huge thank you to the [sponsors of my work with bUnit](https://github.com/spon
Syncfusion - - @aws -
- Amazon Web Services -
## Contributors From 925cdab17618b89a5463192c7a9ae5dc8aa9b9fd Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 13:27:20 +0000 Subject: [PATCH 24/73] feat(test): DumpCapture that captures memory dump on test failure clean up ci dumpcapture code docs --- .config/dotnet-tools.json | 13 ++- .github/workflows/ci.yml | 4 +- tests/bunit.testassets/DumpCapture.cs | 92 +++++++++++++++++++ .../Asserting/MarkupMatchesTests.razor | 54 ++++++----- 4 files changed, 138 insertions(+), 25 deletions(-) create mode 100644 tests/bunit.testassets/DumpCapture.cs diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index b3e2a1dff..7b94efa69 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -6,13 +6,22 @@ "version": "1.10.175", "commands": [ "dotnet-serve" - ] + ], + "rollForward": false }, "docfx": { "version": "2.76.0", "commands": [ "docfx" - ] + ], + "rollForward": false + }, + "dotnet-dump": { + "version": "8.0.532401", + "commands": [ + "dotnet-dump" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 549e5588c..2503768d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -136,7 +136,7 @@ jobs: 8.0.x 9.0.x - - name: ⚙️ Setup GIT versioning + - name: ⚙️ Restore packages and tools run: | dotnet restore dotnet tool restore @@ -144,7 +144,7 @@ jobs: - name: 🧪 Run unit tests run: dotnet test -c release --no-restore -p:VSTestUseMSBuildOutput=false --logger "trx" - - name: Test Report + - name: 🛒 Test Report uses: dorny/test-reporter@v1 if: success() || failure() with: diff --git a/tests/bunit.testassets/DumpCapture.cs b/tests/bunit.testassets/DumpCapture.cs new file mode 100644 index 000000000..2f3a1ebfd --- /dev/null +++ b/tests/bunit.testassets/DumpCapture.cs @@ -0,0 +1,92 @@ +using System.Diagnostics; +using System.Runtime.CompilerServices; +using Xunit.Abstractions; + +namespace Bunit.TestAssets; + +///

+/// Wrap a test action or function in a try-catch block that captures a dump file if the test fails. +/// +/// +/// This requires the dotnet-dump tool to be installed as a local dotnet tool. +/// +public static class DumpCapture +{ + + public static async Task OnFailureAsync( + Action testAction, + ITestOutputHelper outputHelper, + [CallerMemberName] string testName = "", + [CallerFilePath] string testFilePath = "") + { + try + { + testAction(); + } + catch + { + await CaptureDump(testName, testFilePath, outputHelper); + throw; + } + } + + public static async Task OnFailureAsync( + Func testAction, + ITestOutputHelper outputHelper, + [CallerMemberName] string testName = "", + [CallerFilePath] string testFilePath = "") + { + try + { + await testAction(); + } + catch + { + await CaptureDump(testName, testFilePath, outputHelper); + throw; + } + } + + private static async Task CaptureDump(string testName, string testFilePath, ITestOutputHelper outputHelper) + { +#if NETSTANDARD2_1 + var processId = Process.GetCurrentProcess().Id; +#else + var processId = Environment.ProcessId; +#endif + var dumpFilePath = Path.Combine(Directory.GetCurrentDirectory(), $"{Path.GetFileNameWithoutExtension(testFilePath)}-{testName}-wait-failed-{Guid.NewGuid()}.dmp"); + // Attempt to start the dotnet-dump process + var startInfo = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = $"dotnet-dump collect -p {processId} -o {dumpFilePath}", + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + using var process = Process.Start(startInfo); + if (process is null) + { + outputHelper.WriteLine(" Failed to start dotnet-dump process."); + return; + } + +#if NETSTANDARD2_1 + process.WaitForExit(); +#else + await process.WaitForExitAsync(); +#endif + var output = await process.StandardOutput.ReadToEndAsync(); + var error = await process.StandardError.ReadToEndAsync(); + outputHelper.WriteLine($"Dump status: {{process.ExitCode}}. Dump file: {dumpFilePath}"); + if (!string.IsNullOrWhiteSpace(output)) + { + outputHelper.WriteLine($"Dump output: {output}"); + } + if (!string.IsNullOrWhiteSpace(error)) + { + outputHelper.WriteLine($"Dump error: {error}"); + } + } +} diff --git a/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor index 5c22485fc..c2d80e565 100644 --- a/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor +++ b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor @@ -1,35 +1,47 @@ +@using Bunit.TestAssets @using Bunit.TestAssets.SampleComponents @inherits TestContext - @code { + private readonly ITestOutputHelper outputHelper; + + public MarkupMatchesTests(ITestOutputHelper outputHelper) + { + this.outputHelper = outputHelper; + } - [Fact] - public void MarkupMatchesShouldNotBeBlockedByRenderer() - { - var tcs = new TaskCompletionSource(); + [Fact] + public async Task MarkupMatchesShouldNotBeBlockedByRenderer() + { + await DumpCapture.OnFailureAsync(() => + { + var tcs = new TaskCompletionSource(); - var cut = Render(@ ); + var cut = Render(@ ); - cut.MarkupMatches(@loading); + cut.MarkupMatches(@loading ); - tcs.SetResult(true); + tcs.SetResult(true); - cut.WaitForAssertion(() => cut.MarkupMatches(@done)); - } + cut.WaitForAssertion(() => cut.MarkupMatches(@done)); + }, + outputHelper); + } - [SuppressMessage("Usage", "xUnit1026:Theory method does not use parameter")] - [Theory] - [Repeat(2)] - public void MarkupMatchesShouldNotBeBlockedByRendererComplex(int repeatCount) - { - var tcs = new TaskCompletionSource(); + [Fact] + public async Task MarkupMatchesShouldNotBeBlockedByRendererComplex() + { + await DumpCapture.OnFailureAsync(() => + { + var tcs = new TaskCompletionSource(); - var cut = Render(@ ); + var cut = Render(@ ); - cut.MarkupMatches(@waiting); + cut.MarkupMatches(@waiting); - tcs.SetResult(true); + tcs.SetResult(true); - cut.WaitForAssertion(() => cut.MarkupMatches(@done)); - } + cut.WaitForAssertion(() => cut.MarkupMatches(@done)); + }, + outputHelper); + } } From d25af3eff31b93ff76f5d7322afc1cb86d0f8a06 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 14:56:54 +0000 Subject: [PATCH 25/73] fix: increase default timeout to allow expected renders to complete --- .../Asserting/MarkupMatchesTests.razor | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor index c2d80e565..d8723291f 100644 --- a/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor +++ b/tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor @@ -7,41 +7,30 @@ public MarkupMatchesTests(ITestOutputHelper outputHelper) { this.outputHelper = outputHelper; + TestContext.DefaultWaitTimeout = TimeSpan.FromSeconds(30); } [Fact] - public async Task MarkupMatchesShouldNotBeBlockedByRenderer() + public void MarkupMatchesShouldNotBeBlockedByRenderer() { - await DumpCapture.OnFailureAsync(() => - { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); + var cut = Render(@ ); + cut.MarkupMatches(@loading ); - var cut = Render(@ ); + tcs.SetResult(true); - cut.MarkupMatches(@loading ); - - tcs.SetResult(true); - - cut.WaitForAssertion(() => cut.MarkupMatches(@done)); - }, - outputHelper); + cut.WaitForAssertion(() => cut.MarkupMatches(@done)); } [Fact] - public async Task MarkupMatchesShouldNotBeBlockedByRendererComplex() + public void MarkupMatchesShouldNotBeBlockedByRendererComplex() { - await DumpCapture.OnFailureAsync(() => - { - var tcs = new TaskCompletionSource(); - - var cut = Render(@ ); - - cut.MarkupMatches(@waiting); + var tcs = new TaskCompletionSource(); + var cut = Render(@ ); + cut.MarkupMatches(@waiting); - tcs.SetResult(true); + tcs.SetResult(true); - cut.WaitForAssertion(() => cut.MarkupMatches(@done)); - }, - outputHelper); + cut.WaitForAssertion(() => cut.MarkupMatches(@done)); } } From adf989b5cdf1a9dea6f06a1a2f42b8fa0a54355c Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 15:18:07 +0000 Subject: [PATCH 26/73] fix: improve exception message to wait for issue --- .../WaitForHelpers/WaitForFailedException.cs | 28 +++++++++++++++++- .../WaitForHelpers/WaitForHelper.cs | 29 +++++++++++-------- ...tForElementsHelperExtensions.Async.Test.cs | 3 +- ...mentWaitForElementsHelperExtensionsTest.cs | 2 +- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs b/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs index a2e8ae560..3b9a8fc25 100644 --- a/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs +++ b/src/bunit.core/Extensions/WaitForHelpers/WaitForFailedException.cs @@ -15,10 +15,36 @@ public WaitForFailedException(string? errorMessage, Exception? innerException = } internal WaitForFailedException(string errorMessage, int checkCount, int componentRenderCount, int totalRenderCount, Exception? innerException = null) - : base(errorMessage + $" Check count: {checkCount}. Component render count: {componentRenderCount}. Total render count: {totalRenderCount}.", innerException) + : base(CreateMessage(errorMessage, checkCount, componentRenderCount, totalRenderCount), innerException) { } + private static string CreateMessage( + string errorMessage, + int checkCount, + int componentRenderCount, + int totalRenderCount) + { + return $""" + {errorMessage} + + If this test does not fail consistently, the reason may be that + the wait timeout is too short, and the runtime did not have enough + time to complete the necessary number of renders of the component under test. + This can happen on highly utilized or slower hardware, for example. + + To determine if this is the cause, compare the check and render count(s) below + and see if they match what is expected. If they do not, + consider increasing the timeout, either at the individual + method call level, e.g. WaitForElement("div", TimeSpan.FromSeconds(15)), + or via the static TestContext.DefaultWaitTimeout property. + + Check count: {checkCount}. + Component render count: {componentRenderCount}. + Total render count across all components: {totalRenderCount}. + """; + } + private WaitForFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { } } diff --git a/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs b/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs index 033c8c27a..8a153b713 100644 --- a/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs +++ b/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs @@ -59,19 +59,24 @@ protected WaitForHelper( .GetRequiredService() .Renderer; checkPassedCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - timer = new Timer(_ => - { - logger.LogWaiterTimedOut(renderedFragment.ComponentId); - checkPassedCompletionSource.TrySetException( - new WaitForFailedException( - TimeoutErrorMessage ?? string.Empty, - checkCount, - renderedFragment.RenderCount, - renderer.RenderCount, - capturedException)); - }); + WaitTask = CreateWaitTask(); - timer.Change(GetRuntimeTimeout(timeout), Timeout.InfiniteTimeSpan); + timer = new Timer( + static (state) => + { + var @this = (WaitForHelper)state!; + @this.logger.LogWaiterTimedOut(@this.renderedFragment.ComponentId); + @this.checkPassedCompletionSource.TrySetException( + new WaitForFailedException( + @this.TimeoutErrorMessage ?? string.Empty, + @this.checkCount, + @this.renderedFragment.RenderCount, + @this.renderer.RenderCount, + @this.capturedException)); + }, + this, + GetRuntimeTimeout(timeout), + Timeout.InfiniteTimeSpan); InitializeWaiting(); } diff --git a/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensions.Async.Test.cs b/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensions.Async.Test.cs index 24ab80b0e..70eb139d6 100644 --- a/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensions.Async.Test.cs +++ b/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensions.Async.Test.cs @@ -61,8 +61,7 @@ public async Task Test022() expected.InnerException.ShouldBeNull(); } - [Fact(DisplayName = "WaitForElements with specific count N throws exception after timeout when cssSelector does not result in N matching elements", - Skip = "Need to figure out how to make this deterministic.")] + [Fact(DisplayName = "WaitForElements with specific count N throws exception after timeout when cssSelector does not result in N matching elements")] [Trait("Category", "async")] public async Task Test023() { diff --git a/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensionsTest.cs b/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensionsTest.cs index 98844fc00..4ec41fda2 100644 --- a/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensionsTest.cs +++ b/tests/bunit.web.tests/Extensions/WaitForHelpers/RenderedFragmentWaitForElementsHelperExtensionsTest.cs @@ -61,7 +61,7 @@ public void Test022() expected.InnerException.ShouldBeNull(); } - [Fact(DisplayName = "WaitForElements with specific count N throws exception after timeout when cssSelector does not result in N matching elements", Skip = "Need to figure out how to make this deterministic.")] + [Fact(DisplayName = "WaitForElements with specific count N throws exception after timeout when cssSelector does not result in N matching elements")] [Trait("Category", "sync")] public void Test023() { From 96dba795bfb0a8628a678f7b583adb544e923714 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 24 Sep 2024 21:20:41 +0000 Subject: [PATCH 27/73] ci: use output from nbgv instead of env variables --- .github/workflows/ci.yml | 13 +++++++++++-- .github/workflows/docs-deploy.yml | 4 ++-- .github/workflows/prepare-release.yml | 13 +++++++++---- .github/workflows/rebase-v2-on-main.yml | 3 +-- .github/workflows/release.yml | 22 +++++++++++----------- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2503768d3..f239925d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,7 @@ jobs: - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 + id: nbgv with: setAllVars: true @@ -68,7 +69,7 @@ jobs: with: files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' env: - RELEASE_VERSION: ${{ env.NBGV_SimpleVersion }}${{ env.NBGV_PrereleaseVersion }} + RELEASE_VERSION: ${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }} RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} # Create the NuGet package in the folder from the environment variable NuGetDirectory @@ -235,15 +236,23 @@ jobs: - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 + id: nbgv with: setAllVars: true + - name: 🛠️ Get Changelog Entry + id: changelog_reader + uses: mindsers/changelog-reader-action@v2 + with: + version: Unreleased + path: ./CHANGELOG.md + - name: 🍥 Replace tokens in files uses: cschleiden/replace-tokens@v1 with: files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props", "docs/site/docfx.json"]' env: - RELEASE_VERSION: ${{ env.NBGV_SimpleVersion }}${{ env.NBGV_PrereleaseVersion }} + RELEASE_VERSION: ${{ steps.nbgv.outputs.SimpleVersion }}${{ steps.nbgv.outputs.PrereleaseVersion }} RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} - name: 📄 Build bUnit diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index bd0cf29b3..93cdde359 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -51,6 +51,7 @@ jobs: - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 + id: nbgv with: setAllVars: true @@ -123,9 +124,8 @@ jobs: - name: ⏭ Create pull request from stable to main when direct merge fails if: steps.mergeMainline.outcome == 'failure' uses: thomaseizinger/create-pull-request@1.4.0 - env: - GITHUB_TOKEN: ${{ secrets.BUNIT_BOT_TOKEN }} with: + github_token: ${{ secrets.BUNIT_BOT_TOKEN }} head: stable base: main title: Update main with documentation in stable diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 37c77fc79..5b48c8c0f 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -28,6 +28,12 @@ jobs: version: Unreleased path: ./CHANGELOG.md + - name: ⚙️ Setup GIT versioning + uses: dotnet/nbgv@v0.4.2 + id: nbgv + with: + setAllVars: true + - name: ☑ Check that release contains changes if: steps.changelog_reader.outputs.changes == '' run: | @@ -85,12 +91,11 @@ jobs: - name: ⏭ Create pull request for release branch uses: thomaseizinger/create-pull-request@1.4.0 - env: - GITHUB_TOKEN: ${{ secrets.BUNIT_BOT_TOKEN }} with: - head: release/v${{ env.NBGV_MajorMinorVersion }} + github_token: ${{ secrets.BUNIT_BOT_TOKEN }} + head: release/v${{ steps.nbgv.outputs.MajorMinorVersion }} base: stable - title: Release of new ${{ github.event.inputs.versionIncrement }} version v${{ env.NBGV_MajorMinorVersion }} + title: Release of new ${{ github.event.inputs.versionIncrement }} version v${{ steps.nbgv.outputs.MajorMinorVersion }} body: | This PR was created in response to a manual trigger of the [prepare-release workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). diff --git a/.github/workflows/rebase-v2-on-main.yml b/.github/workflows/rebase-v2-on-main.yml index 11178ce44..2786b4db7 100644 --- a/.github/workflows/rebase-v2-on-main.yml +++ b/.github/workflows/rebase-v2-on-main.yml @@ -48,9 +48,8 @@ jobs: - name: ⏭ Create pull request if: steps.rebaseV2.outcome == 'failure' uses: thomaseizinger/create-pull-request@1.4.0 - env: - GITHUB_TOKEN: ${{ secrets.BUNIT_BOT_TOKEN }} with: + github_token: ${{ secrets.BUNIT_BOT_TOKEN }} head: main base: v2 title: Rebase v2 on main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bb6882b43..b93f5fbca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,6 +50,7 @@ jobs: - name: ⚙️ Setup GIT versioning uses: dotnet/nbgv@v0.4.2 + id: nbgv with: setAllVars: true @@ -67,7 +68,7 @@ jobs: - name: 🛠️ Update changelog uses: thomaseizinger/keep-a-changelog-new-release@3.1.0 with: - version: ${{ env.NBGV_SemVer2 }} + version: ${{ steps.nbgv.outputs.SemVer2 }} - name: 🛠️ Update changelog compare URLs shell: bash @@ -78,14 +79,14 @@ jobs: - name: 🛠️ Commit CHANGELOG.md to stable branch run: | git add CHANGELOG.md - git commit -S -m "Updated CHANGELOG.md for ${{ env.NBGV_SimpleVersion }} release" + git commit -S -m "Updated CHANGELOG.md for ${{ steps.nbgv.outputs.SimpleVersion }} release" echo "RELEASE_COMMIT_HASH=$(git rev-parse stable)" >> $GITHUB_ENV - name: 🛠️ Get Changelog Entry id: changelog_reader uses: mindsers/changelog-reader-action@v2 with: - version: ${{ env.NBGV_SemVer2 }} + version: ${{ steps.nbgv.outputs.SemVer2 }} path: ./CHANGELOG.md - name: 🛠️ Update tokens in project files @@ -93,7 +94,7 @@ jobs: with: files: '["docs/site/*.md", "docs/**/*.md", "docs/**/*.tmpl.partial", "*.csproj", "**/*.csproj", "src/Directory.Build.props"]' env: - RELEASE_VERSION: ${{ env.NBGV_NuGetPackageVersion }} + RELEASE_VERSION: ${{ steps.nbgv.outputs.NuGetPackageVersion }} RELEASE_NOTES: ${{ steps.changelog_reader.outputs.changes }} - name: 🛠️ Packing library in release mode @@ -113,13 +114,13 @@ jobs: - name: 🛠️ Create GitHub release uses: thomaseizinger/create-release@2.0.0 with: - tag_name: v${{ env.NBGV_SemVer2 }} + tag_name: v${{ steps.nbgv.outputs.SemVer2 }} target_commitish: ${{ env.RELEASE_COMMIT_HASH }} - name: ${{ env.NBGV_SemVer2 }} + name: ${{ steps.nbgv.outputs.SemVer2 }} body: ${{ steps.changelog_reader.outputs.changes }} draft: false - prerelease: ${{ env.NBGV_PublicRelease == 'False' }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + prerelease: ${{ steps.nbgv.outputs.PublicRelease == 'False' }} + github_token: ${{ secrets.GITHUB_TOKEN }} - name: ⏩ Merge stable with main, push to origin id: mergeMainline @@ -132,12 +133,11 @@ jobs: - name: ⏭ Create pull request from stable to main when direct merge fails if: steps.mergeMainline.outcome == 'failure' uses: thomaseizinger/create-pull-request@1.4.0 - env: - GITHUB_TOKEN: ${{ secrets.BUNIT_BOT_TOKEN }} with: + github_token: ${{ secrets.BUNIT_BOT_TOKEN }} head: stable base: main - title: Update main with changes in stable after v${{ env.NBGV_SemVer2 }} release + title: Update main with changes in stable after v${{ steps.nbgv.outputs.SemVer2 }} release reviewers: ${{ github.actor }} # By default, we request a review from the person who triggered the workflow. body: | Hi @${{ github.actor }} From 71c5960b58eaf202e514ded5d840dbc3811143c5 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 15:55:02 +0000 Subject: [PATCH 28/73] fix: always perform at least one check in WaitFor to avoid timer not getting triggered before check gets a chance to complete --- .../WaitForHelpers/WaitForHelper.cs | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs b/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs index 8a153b713..f25ace989 100644 --- a/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs +++ b/src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs @@ -10,12 +10,12 @@ namespace Bunit.Extensions.WaitForHelpers; ///
public abstract class WaitForHelper : IDisposable { - private readonly Timer timer; private readonly TaskCompletionSource checkPassedCompletionSource; private readonly Func<(bool CheckPassed, T Content)> completeChecker; private readonly IRenderedFragmentBase renderedFragment; private readonly ILogger> logger; private readonly TestRenderer renderer; + private readonly Timer? timer; private bool isDisposed; private int checkCount; private Exception? capturedException; @@ -60,25 +60,37 @@ protected WaitForHelper( .Renderer; checkPassedCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + // Create the wait task and run the initial check + // and subscribe to the OnAfterRender event. + // This must happen before the timer is started, + // as the check happens inside the renderers synchronization context, + // and that may be blocked longer than the timeout on overloaded systems, + // resulting in the timer completing before a single check has + // has a chance to complete. WaitTask = CreateWaitTask(); - timer = new Timer( - static (state) => - { - var @this = (WaitForHelper)state!; - @this.logger.LogWaiterTimedOut(@this.renderedFragment.ComponentId); - @this.checkPassedCompletionSource.TrySetException( - new WaitForFailedException( - @this.TimeoutErrorMessage ?? string.Empty, - @this.checkCount, - @this.renderedFragment.RenderCount, - @this.renderer.RenderCount, - @this.capturedException)); - }, - this, - GetRuntimeTimeout(timeout), - Timeout.InfiniteTimeSpan); - - InitializeWaiting(); + CheckAndInitializeWaiting(); + + // If the initial check did not complete successfully, + // start the timer and recheck after every render until the timer expires. + if (!WaitTask.IsCompleted) + { + timer = new Timer( + static (state) => + { + var @this = (WaitForHelper)state!; + @this.logger.LogWaiterTimedOut(@this.renderedFragment.ComponentId); + @this.checkPassedCompletionSource.TrySetException( + new WaitForFailedException( + @this.TimeoutErrorMessage ?? string.Empty, + @this.checkCount, + @this.renderedFragment.RenderCount, + @this.renderer.RenderCount, + @this.capturedException)); + }, + this, + GetRuntimeTimeout(timeout), + Timeout.InfiniteTimeSpan); + } } /// @@ -105,13 +117,13 @@ protected virtual void Dispose(bool disposing) return; isDisposed = true; - timer.Dispose(); + timer?.Dispose(); checkPassedCompletionSource.TrySetCanceled(); renderedFragment.OnAfterRender -= OnAfterRender; logger.LogWaiterDisposed(renderedFragment.ComponentId); } - private void InitializeWaiting() + private void CheckAndInitializeWaiting() { if (!WaitTask.IsCompleted) { From f709c887e99222d6aacf84895898c188dcb7fb26 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 16:12:07 +0000 Subject: [PATCH 29/73] ci: remove NU5128 warning --- .github/workflows/ci.yml | 2 +- src/bunit/bunit.csproj | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f239925d8..48b330829 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,7 +158,7 @@ jobs: - name: 📛 Upload hang- and crash-dumps on test failure if: success() || failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: if-no-files-found: ignore name: test-dumps diff --git a/src/bunit/bunit.csproj b/src/bunit/bunit.csproj index ff44fca70..4580417ef 100644 --- a/src/bunit/bunit.csproj +++ b/src/bunit/bunit.csproj @@ -4,6 +4,7 @@ true false false + $(NoWarn);NU5128 From 07e171c99b27c5a0d05f88f87a1967978aecb2ac Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 16:23:11 +0000 Subject: [PATCH 30/73] ci: remove test report as it fails on PRs --- .github/workflows/ci.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48b330829..55859e1d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -143,18 +143,7 @@ jobs: dotnet tool restore - name: 🧪 Run unit tests - run: dotnet test -c release --no-restore -p:VSTestUseMSBuildOutput=false --logger "trx" - - - name: 🛒 Test Report - uses: dorny/test-reporter@v1 - if: success() || failure() - with: - name: 'CI Test Results ${{ matrix.os }}' - reporter: 'dotnet-trx' - list-tests: 'failed' - list-suites: 'failed' - path: '**/*.trx' - fail-on-error: false + run: dotnet test -c release --no-restore - name: 📛 Upload hang- and crash-dumps on test failure if: success() || failure() From 4a44381d82c4b65e455901aa7b1b39e19be941e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:29:27 +0000 Subject: [PATCH 31/73] build(deps): Bump xunit from 2.9.1 to 2.9.2 Bumps [xunit](https://github.com/xunit/xunit) from 2.9.1 to 2.9.2. - [Commits](https://github.com/xunit/xunit/compare/2.9.1...2.9.2) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Packages.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index d00dd8b91..8becf4c5c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -143,10 +143,10 @@ - + - - + + From 959d3718adddf0cc64ff8c1cd25223e65ae180af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:27:42 +0000 Subject: [PATCH 32/73] build(deps): Bump Serilog from 4.0.1 to 4.0.2 Bumps [Serilog](https://github.com/serilog/serilog) from 4.0.1 to 4.0.2. - [Release notes](https://github.com/serilog/serilog/releases) - [Commits](https://github.com/serilog/serilog/compare/v4.0.1...v4.0.2) --- updated-dependencies: - dependency-name: Serilog dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 8becf4c5c..3726679b1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - + From d2a9ddb1a79e9a02e736b3fbaf28af41b44758fc Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 4 Oct 2024 16:57:55 +0000 Subject: [PATCH 33/73] docs: include wait for change in changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3fd8f659..a29213f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Fixed + +- Ensure that a check in `WaitForAssertion` and related methods is always performed at once before the wait timer is started. If not, the timeout could occure before a wait-for check-condition had been attempted, causing tests to fail without reason. Fixed by [@egil](https://github.com/egil). + ## [1.31.3] - 2024-08-16 ### Fixed From 1fb99ac462b5c5a96bffebca2bec62823143ae8c Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 4 Oct 2024 17:00:40 +0000 Subject: [PATCH 34/73] Set version to '1.32' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 259e66b43..556cfe4ec 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.32-preview", + "version": "1.32", "assemblyVersion": { "precision": "revision" }, From f7a5b0aef5654171133b77991f516f1383566ddf Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 4 Oct 2024 17:00:41 +0000 Subject: [PATCH 35/73] Set version to '1.33-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 259e66b43..ae194883c 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.32-preview", + "version": "1.33-preview", "assemblyVersion": { "precision": "revision" }, From e095b07a069b4626cfefe36f7f26df8de87ee814 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 4 Oct 2024 17:32:29 +0000 Subject: [PATCH 36/73] Updated CHANGELOG.md for 1.32.7 release --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29213f62..6e77d2e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.32.7] - 2024-10-04 + ### Fixed - Ensure that a check in `WaitForAssertion` and related methods is always performed at once before the wait timer is started. If not, the timeout could occure before a wait-for check-condition had been attempted, causing tests to fail without reason. Fixed by [@egil](https://github.com/egil). @@ -1392,7 +1394,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...HEAD +[1.32.7]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...v1.32.7 [1.31.3]: https://github.com/bUnit-dev/bUnit/compare/v1.30.3...1.31.3 [1.30.3]: https://github.com/bUnit-dev/bUnit/compare/v1.29.5...v1.30.3 [1.29.5]: https://github.com/bUnit-dev/bUnit/compare/v1.28.9...1.29.5 From 0f76e56b87b5e11860e08803f2df24ac340855de Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 7 Oct 2024 17:49:41 +0200 Subject: [PATCH 37/73] feat: Respect base properties (#1572) * feat: Respect base properties * Update src/bunit.generators/Web.Stubs/MemberRetriever.cs Co-authored-by: Egil Hansen --------- Co-authored-by: Egil Hansen --- .../AddStubGenerator.cs | 5 +-- .../ComponentStubAttributeGenerator.cs | 2 +- .../Web.Stubs/MemberRetriever.cs | 19 ++++++++++ .../Web.Stub/AddStubGeneratorTests.cs | 37 ++++++++++++++++++- .../Web.Stub/Components/ContainerComponent.cs | 14 +++++++ 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 src/bunit.generators/Web.Stubs/MemberRetriever.cs create mode 100644 tests/bunit.generators.tests/Web.Stub/Components/ContainerComponent.cs diff --git a/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs b/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs index 6c7933786..c7fadff33 100644 --- a/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs +++ b/src/bunit.generators/Web.Stubs/AddStubMethodStubGenerator/AddStubGenerator.cs @@ -31,8 +31,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) private static AddStubClassInfo? GetStubClassInfo(GeneratorSyntaxContext context) { - var invocation = context.Node as InvocationExpressionSyntax; - if (invocation is null || !IsComponentFactoryStubMethod(invocation, context.SemanticModel)) + if (context.Node is not InvocationExpressionSyntax invocation || !IsComponentFactoryStubMethod(invocation, context.SemanticModel)) { return null; } @@ -56,7 +55,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var line = lineSpan.StartLinePosition.Line + 1; var column = lineSpan.Span.Start.Character + context.Node.ToString().IndexOf("AddStub", StringComparison.Ordinal) + 1; - var properties = symbol.GetMembers() + var properties = symbol.GetAllMembersRecursively() .OfType() .Where(IsParameterOrCascadingParameter) .Select(CreateFromProperty) diff --git a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs index d36fcf184..ee778bb1f 100644 --- a/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs +++ b/src/bunit.generators/Web.Stubs/AttributeStubGenerator/ComponentStubAttributeGenerator.cs @@ -62,7 +62,7 @@ private static bool IsClassWithComponentStubAttribute(SyntaxNode s) => } var parameter = attribute.AttributeClass!.TypeArguments - .SelectMany(s => s.GetMembers()) + .SelectMany(s => s.GetAllMembersRecursively()) .OfType() .Where(IsParameterOrCascadingParameter) .Select(CreateFromProperty) diff --git a/src/bunit.generators/Web.Stubs/MemberRetriever.cs b/src/bunit.generators/Web.Stubs/MemberRetriever.cs new file mode 100644 index 000000000..00ce8950f --- /dev/null +++ b/src/bunit.generators/Web.Stubs/MemberRetriever.cs @@ -0,0 +1,19 @@ +using Microsoft.CodeAnalysis; + +namespace Bunit.Web.Stubs; + +internal static class MemberRetriever +{ + public static IEnumerable GetAllMembersRecursively(this ITypeSymbol type) + { + var currentType = type; + while (currentType is not null) + { + foreach (var member in currentType.GetMembers()) + { + yield return member; + } + currentType = currentType.BaseType; + } + } +} diff --git a/tests/bunit.generators.tests/Web.Stub/AddStubGeneratorTests.cs b/tests/bunit.generators.tests/Web.Stub/AddStubGeneratorTests.cs index df54ed6f2..17c3dc44c 100644 --- a/tests/bunit.generators.tests/Web.Stub/AddStubGeneratorTests.cs +++ b/tests/bunit.generators.tests/Web.Stub/AddStubGeneratorTests.cs @@ -61,7 +61,42 @@ public void Generated_stub_via_attribute_has_same_parameters() var stub = cut.FindComponent(); Assert.Equal("test", stub.Instance.Text); } + + [Fact] + public void Generated_Stub_respects_base_class_parameters() + { + ComponentFactories.AddStub(); + + var cut = RenderComponent(c => c.AddChildContent()); + + var stub = cut.FindComponent(); + Assert.Equal(0, stub.Instance.BaseCount); + } + + [Fact] + public void Generated_stub_via_attribute_respects_base_class_parameters() + { + ComponentFactories.Add(); + + var cut = RenderComponent(c => c.AddChildContent()); + + var stub = cut.FindComponent(); + Assert.Equal(0, stub.Instance.BaseCount); + } } [ComponentStub] -public partial class ButtonComponentStub; \ No newline at end of file +public partial class ButtonComponentStub; + +public abstract class BaseComponent : ComponentBase +{ + [Parameter] public int BaseCount { get; set; } +} + +public class DerivedComponent : BaseComponent +{ + [Parameter] public int DerivedCount { get; set; } +} + +[ComponentStub] +public partial class DerivedComponentStubViaAttributeAnnotation; \ No newline at end of file diff --git a/tests/bunit.generators.tests/Web.Stub/Components/ContainerComponent.cs b/tests/bunit.generators.tests/Web.Stub/Components/ContainerComponent.cs new file mode 100644 index 000000000..5cbbbb298 --- /dev/null +++ b/tests/bunit.generators.tests/Web.Stub/Components/ContainerComponent.cs @@ -0,0 +1,14 @@ +namespace Bunit.Web.Stub.Components; + +public class ContainerComponent : ComponentBase +{ + [Parameter] + public RenderFragment ChildContent { get; set; } + + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "div"); + builder.AddContent(1, ChildContent); + builder.CloseElement(); + } +} From 8ff1bf3d38ca2ca9a95ef5ae21be88d63dddeb59 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 7 Oct 2024 21:04:32 +0200 Subject: [PATCH 38/73] chore: Bump packages --- .config/dotnet-tools.json | 4 ++-- Directory.Packages.props | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 7b94efa69..ebcf504c5 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -17,11 +17,11 @@ "rollForward": false }, "dotnet-dump": { - "version": "8.0.532401", + "version": "8.0.547301", "commands": [ "dotnet-dump" ], "rollForward": false } } -} \ No newline at end of file +} diff --git a/Directory.Packages.props b/Directory.Packages.props index 3726679b1..7a4deb521 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,7 +7,7 @@ - + @@ -20,7 +20,7 @@ - + From dd25f77bbaf90ad7570f798663f32136702ddd9f Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 10 Oct 2024 20:09:18 +0200 Subject: [PATCH 39/73] feat: Enable constructor injection (#1581) * feat: Enable constructor injection * fix: CVE in System.Text.Json --- Directory.Packages.props | 14 +++++++------- .../Rendering/BunitComponentActivator.cs | 18 +++++++++++++----- src/bunit.core/Rendering/TestRenderer.cs | 4 ++-- .../ConstructorInjectionComponent.cs | 13 +++++++++++++ .../Rendering/RenderedComponentTest.cs | 10 ++++++++++ 5 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 tests/bunit.testassets/SampleComponents/ConstructorInjectionComponent.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 7a4deb521..870c8c3a1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -122,7 +122,7 @@ - + diff --git a/src/bunit.core/Rendering/BunitComponentActivator.cs b/src/bunit.core/Rendering/BunitComponentActivator.cs index e7afdd5c8..3d1e9c1de 100644 --- a/src/bunit.core/Rendering/BunitComponentActivator.cs +++ b/src/bunit.core/Rendering/BunitComponentActivator.cs @@ -7,10 +7,13 @@ internal class BunitComponentActivator : IComponentActivator private readonly ComponentFactoryCollection factories; private readonly IComponentActivator componentActivator; - public BunitComponentActivator(ComponentFactoryCollection factories, IComponentActivator? externalComponentActivator) + public BunitComponentActivator( + IServiceProvider serviceProvider, + ComponentFactoryCollection factories, + IComponentActivator? externalComponentActivator) { this.factories = factories ?? throw new ArgumentNullException(nameof(factories)); - this.componentActivator = externalComponentActivator ?? DefaultComponentActivator.Instance; + this.componentActivator = externalComponentActivator ?? new DefaultComponentActivator(serviceProvider); } public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType) @@ -43,12 +46,17 @@ public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessed private sealed class DefaultComponentActivator : IComponentActivator { - public static IComponentActivator Instance { get; } = new DefaultComponentActivator(); + private readonly IServiceProvider serviceProvider; + + public DefaultComponentActivator(IServiceProvider serviceProvider) + { + this.serviceProvider = serviceProvider; + } /// public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType) - { - return (IComponent)Activator.CreateInstance(componentType)!; + { + return (IComponent)ActivatorUtilities.CreateInstance(serviceProvider, componentType); } } } diff --git a/src/bunit.core/Rendering/TestRenderer.cs b/src/bunit.core/Rendering/TestRenderer.cs index bf7449b4e..61d4deecf 100644 --- a/src/bunit.core/Rendering/TestRenderer.cs +++ b/src/bunit.core/Rendering/TestRenderer.cs @@ -79,7 +79,7 @@ public TestRenderer(IRenderedComponentActivator renderedComponentActivator, Test /// Initializes a new instance of the class. /// public TestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory) - : base(services, loggerFactory, new BunitComponentActivator(services.GetRequiredService(), null)) + : base(services, loggerFactory, new BunitComponentActivator(services, services.GetRequiredService(), null)) { logger = loggerFactory.CreateLogger(); this.activator = renderedComponentActivator; @@ -89,7 +89,7 @@ public TestRenderer(IRenderedComponentActivator renderedComponentActivator, Test /// Initializes a new instance of the class. /// public TestRenderer(IRenderedComponentActivator renderedComponentActivator, TestServiceProvider services, ILoggerFactory loggerFactory, IComponentActivator componentActivator) - : base(services, loggerFactory, new BunitComponentActivator(services.GetRequiredService(), componentActivator)) + : base(services, loggerFactory, new BunitComponentActivator(services, services.GetRequiredService(), componentActivator)) { logger = loggerFactory.CreateLogger(); this.activator = renderedComponentActivator; diff --git a/tests/bunit.testassets/SampleComponents/ConstructorInjectionComponent.cs b/tests/bunit.testassets/SampleComponents/ConstructorInjectionComponent.cs new file mode 100644 index 000000000..7b99ac4b1 --- /dev/null +++ b/tests/bunit.testassets/SampleComponents/ConstructorInjectionComponent.cs @@ -0,0 +1,13 @@ +using Microsoft.JSInterop; + +namespace Bunit.TestAssets.SampleComponents; + +public class ConstructorInjectionComponent : ComponentBase +{ + public IJSRuntime JSRuntime { get; } + + public ConstructorInjectionComponent(IJSRuntime jsRuntime) + { + JSRuntime = jsRuntime; + } +} diff --git a/tests/bunit.web.tests/Rendering/RenderedComponentTest.cs b/tests/bunit.web.tests/Rendering/RenderedComponentTest.cs index a4dd4a0d9..412779aad 100644 --- a/tests/bunit.web.tests/Rendering/RenderedComponentTest.cs +++ b/tests/bunit.web.tests/Rendering/RenderedComponentTest.cs @@ -57,4 +57,14 @@ public void Test020() Should.Throw(() => target.Instance); } + #if NET9_0_OR_GREATER + + [Fact(DisplayName = "Component with constructor dependencies is resolved when rendered")] + public void Test021() + { + var cut = RenderComponent(); + + cut.Instance.JSRuntime.ShouldNotBeNull(); + } + #endif } From 2b1e0976752702350d22a54be2f2c72aac60d7a5 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 11 Oct 2024 09:04:10 +0200 Subject: [PATCH 40/73] fix: Use one central version for System.Text.Json --- Directory.Packages.props | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 870c8c3a1..9ea352b21 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,6 +28,11 @@ + + + + + @@ -40,9 +45,6 @@ - - - @@ -57,9 +59,6 @@ - - - @@ -73,9 +72,6 @@ - - - @@ -89,9 +85,6 @@ - - - @@ -105,9 +98,6 @@ - - - @@ -121,8 +111,6 @@ - - From 464bb0a609c8719ef1c6f90a96bc7b18be85c222 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 11 Oct 2024 16:04:57 +0200 Subject: [PATCH 41/73] docs: Added changelog entry --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e77d2e6e..8a852770f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Added + +- `bunit.generators` respect parameters from the base class. +- Supports components using constructor injection in `net9.0`. + +### Fixed + +- Use latest `System.Text.Json` due to CVE in `8.0.4`. + ## [1.32.7] - 2024-10-04 ### Fixed From 932c8ac1e447eb73dbcc5419dfc15af9a318ab60 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 11 Oct 2024 14:05:42 +0000 Subject: [PATCH 42/73] Set version to '1.33' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ae194883c..fc864ecdf 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.33-preview", + "version": "1.33", "assemblyVersion": { "precision": "revision" }, From 7e62b73da21e6263f9f0d4cc8bbd3ce9b1f980cd Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 11 Oct 2024 14:05:43 +0000 Subject: [PATCH 43/73] Set version to '1.34-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ae194883c..1e437534b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.33-preview", + "version": "1.34-preview", "assemblyVersion": { "precision": "revision" }, From a95c4bea4c4a0b0b15c0e13df241e0a32e173796 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 11 Oct 2024 14:15:33 +0000 Subject: [PATCH 44/73] Updated CHANGELOG.md for 1.33.3 release --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a852770f..272a950da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.33.3] - 2024-10-11 + ### Added - `bunit.generators` respect parameters from the base class. @@ -1403,7 +1405,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...HEAD +[1.33.3]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...1.33.3 [1.32.7]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...v1.32.7 [1.31.3]: https://github.com/bUnit-dev/bUnit/compare/v1.30.3...1.31.3 [1.30.3]: https://github.com/bUnit-dev/bUnit/compare/v1.29.5...v1.30.3 From c0260b135330ba85c9a3499e0a2474d1ab7a27c4 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 14 Oct 2024 08:46:04 +0000 Subject: [PATCH 45/73] chore: upgrade anglesharp.diffing to 1.0.0 --- Directory.Packages.props | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 9ea352b21..2fc9727ba 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -17,8 +17,7 @@ - - + @@ -38,7 +37,6 @@ - @@ -52,7 +50,6 @@ - From ee3e229206eb66614657342beafcc9f39dc0a848 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 1 Nov 2024 09:23:14 +0100 Subject: [PATCH 46/73] chore: Upgrade packages to combat CVE in dependencies. Fixes #1593 --- CHANGELOG.md | 1 + Directory.Packages.props | 50 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 272a950da..954262f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad ### Fixed - Use latest `System.Text.Json` due to CVE in `8.0.4`. +- Fixed other packages that have a CVE like `Microsoft.Extensions.Caching.Memory`. Reported by [@polajenko](https://github.com/polajenko). Fixed by [@linkdotnet](https://github.com/linkdotnet). ## [1.32.7] - 2024-10-04 diff --git a/Directory.Packages.props b/Directory.Packages.props index 2fc9727ba..f54917fb8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,7 +15,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -85,29 +85,29 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + @@ -117,13 +117,13 @@ - + - + From 68b5bcf8b98bbc367f465ede69b1732182c4676a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 1 Nov 2024 10:14:49 +0100 Subject: [PATCH 47/73] docs: Fixed changelog.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 954262f77..05e273705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Fixed + +- Fixed other packages that have a CVE like `Microsoft.Extensions.Caching.Memory`. Reported by [@polajenko](https://github.com/polajenko). Fixed by [@linkdotnet](https://github.com/linkdotnet). + ## [1.33.3] - 2024-10-11 ### Added @@ -16,8 +20,6 @@ All notable changes to **bUnit** will be documented in this file. The project ad ### Fixed - Use latest `System.Text.Json` due to CVE in `8.0.4`. -- Fixed other packages that have a CVE like `Microsoft.Extensions.Caching.Memory`. Reported by [@polajenko](https://github.com/polajenko). Fixed by [@linkdotnet](https://github.com/linkdotnet). - ## [1.32.7] - 2024-10-04 ### Fixed From 0cff4c5ec5e45acb4444c3ddc175ac2ef2b1c58e Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 1 Nov 2024 09:16:28 +0000 Subject: [PATCH 48/73] Set version to '1.34' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 1e437534b..d1b1c399a 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.34-preview", + "version": "1.34", "assemblyVersion": { "precision": "revision" }, From 92fb643c6927bdbdae2b2b1282f88ca41c24460a Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 1 Nov 2024 09:16:29 +0000 Subject: [PATCH 49/73] Set version to '1.35-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 1e437534b..ada8bc084 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.34-preview", + "version": "1.35-preview", "assemblyVersion": { "precision": "revision" }, From a0cfdc80e99a20983288fc16d5156d77ef61c1a5 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 1 Nov 2024 09:33:08 +0000 Subject: [PATCH 50/73] Updated CHANGELOG.md for 1.34.0 release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05e273705..8730a3dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.34.0] - 2024-11-01 + ### Fixed - Fixed other packages that have a CVE like `Microsoft.Extensions.Caching.Memory`. Reported by [@polajenko](https://github.com/polajenko). Fixed by [@linkdotnet](https://github.com/linkdotnet). @@ -20,6 +22,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad ### Fixed - Use latest `System.Text.Json` due to CVE in `8.0.4`. + ## [1.32.7] - 2024-10-04 ### Fixed @@ -1408,7 +1411,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.34.0...HEAD +[1.34.0]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...v1.34.0 [1.33.3]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...1.33.3 [1.32.7]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...v1.32.7 [1.31.3]: https://github.com/bUnit-dev/bUnit/compare/v1.30.3...1.31.3 From 52a009b5980ff18ee7d9951b83e5a4ffc95082f3 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Sat, 2 Nov 2024 19:25:43 +0100 Subject: [PATCH 51/73] chore: Update templates for .net9 and make .net9 default (#1598) * chore: Update templates for .net9 and make .net9 default * chore: Update package versions * Use net9.0 for templates --- .github/workflows/ci.yml | 5 ++++- .../template/.template.config/template.json | 7 ++++++- .../template/Company.BlazorTests1.csproj | 12 ++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55859e1d7..6e106dd43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,8 +163,11 @@ jobs: with: fetch-depth: 0 # Get all history to allow automatic versioning using MinVer - - name: Setup .NET + - name: ⚙️ Setup dotnet uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 9.0.x - uses: actions/download-artifact@v4 with: diff --git a/src/bunit.template/template/.template.config/template.json b/src/bunit.template/template/.template.config/template.json index f926c5c55..646e9a8ef 100644 --- a/src/bunit.template/template/.template.config/template.json +++ b/src/bunit.template/template/.template.config/template.json @@ -82,7 +82,7 @@ "description": "The target framework sdk for the project.", "displayName": "Target framework sdk", "datatype": "choice", - "defaultValue": "net7.0", + "defaultValue": "net9.0", "replaces": "targetSdk", "choices": [ { @@ -99,6 +99,11 @@ "choice": "net8.0", "description": ".net 8.0", "displayName": ".net 8.0" + }, + { + "choice": "net9.0", + "description": ".net 9.0", + "displayName": ".net 9.0" } ] } diff --git a/src/bunit.template/template/Company.BlazorTests1.csproj b/src/bunit.template/template/Company.BlazorTests1.csproj index 2801d2147..35e5fe7d5 100644 --- a/src/bunit.template/template/Company.BlazorTests1.csproj +++ b/src/bunit.template/template/Company.BlazorTests1.csproj @@ -25,21 +25,21 @@ - - + + all runtime; build; native; contentfiles; analyzers - - + + - - + + From 760383cc9f59121c9f4b75479b014ade9c0592f6 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 1 Nov 2024 21:14:14 +0000 Subject: [PATCH 52/73] feat: Flag extensions as stable --- .github/workflows/release.yml | 3 ++- CHANGELOG.md | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b93f5fbca..9447b5192 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,7 +102,8 @@ jobs: dotnet pack src/bunit/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true dotnet pack src/bunit.core/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true dotnet pack src/bunit.web/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - dotnet pack src/bunit.template/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true + dotnet pack src/bunit.generators/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true + dotnet pack src/bunit.web.query/ -c Release --property:PackageOutputPath=${GITHUB_WORKSPACE}/packages -p:ContinuousIntegrationBuild=true -p:publicrelease=true - name: 🛠️ Upload library to NuGet.org repository run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 8730a3dfc..b92a5588e 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 +- Extension packages (`bunit.generators` and `bunit.web.query`) are flagged as stable. + ## [1.34.0] - 2024-11-01 ### Fixed From 2e45d1dd9428d0ea16b0b4e452c80dc316cfaf90 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Wed, 6 Nov 2024 18:19:57 +0800 Subject: [PATCH 53/73] remove source link package reference not necessary --- Directory.Packages.props | 1 - src/Directory.Build.props | 4 ---- 2 files changed, 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f54917fb8..7e21294b6 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -23,7 +23,6 @@ - diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 9bfb6c0e8..89a13faaa 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -60,10 +60,6 @@ See the full changelog at https://github.com/bUnit-dev/bUnit/releases - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive From bc8e41c0e5b5647d3b944fc4569aecba5fd088bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:54:19 +0000 Subject: [PATCH 54/73] build(deps): Bump dotnet-dump from 8.0.547301 to 9.0.553101 Bumps [dotnet-dump](https://github.com/dotnet/diagnostics) from 8.0.547301 to 9.0.553101. - [Release notes](https://github.com/dotnet/diagnostics/releases) - [Commits](https://github.com/dotnet/diagnostics/compare/v8.0.547301...v9.0.553101) --- updated-dependencies: - dependency-name: dotnet-dump dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .config/dotnet-tools.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index ebcf504c5..b2c7d1536 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -17,11 +17,11 @@ "rollForward": false }, "dotnet-dump": { - "version": "8.0.547301", + "version": "9.0.553101", "commands": [ "dotnet-dump" ], "rollForward": false } } -} +} \ No newline at end of file From 7c633cb0a572b6a2f9e35e97a4b0235310b8ac1f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:00:50 +0000 Subject: [PATCH 55/73] build(deps): Bump docfx from 2.76.0 to 2.77.0 Bumps [docfx](https://github.com/dotnet/docfx) from 2.76.0 to 2.77.0. - [Release notes](https://github.com/dotnet/docfx/releases) - [Changelog](https://github.com/dotnet/docfx/blob/main/RELEASENOTE.md) - [Commits](https://github.com/dotnet/docfx/compare/v2.76.0...v2.77.0) --- updated-dependencies: - dependency-name: docfx dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index b2c7d1536..10bd8b7a3 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -10,7 +10,7 @@ "rollForward": false }, "docfx": { - "version": "2.76.0", + "version": "2.77.0", "commands": [ "docfx" ], From b4879d2b380d6882701dd86ff962e400f6fcfa62 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:09:54 +0000 Subject: [PATCH 56/73] Set version to '1.35' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ada8bc084..336d90668 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.35-preview", + "version": "1.35", "assemblyVersion": { "precision": "revision" }, From 605363ad499ca11da5ce74919cb93767239e8eb9 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:09:55 +0000 Subject: [PATCH 57/73] Set version to '1.36-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index ada8bc084..2aa22fb3e 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.35-preview", + "version": "1.36-preview", "assemblyVersion": { "precision": "revision" }, From 45e2bb0ac2799d388f530d2c845675de41234bab Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:19:34 +0000 Subject: [PATCH 58/73] Updated CHANGELOG.md for 1.35.3 release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b92a5588e..5e7ea6ede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.35.3] - 2024-11-12 + ### Added + - Extension packages (`bunit.generators` and `bunit.web.query`) are flagged as stable. ## [1.34.0] - 2024-11-01 @@ -1414,7 +1417,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.34.0...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...HEAD +[1.35.3]: https://github.com/bUnit-dev/bUnit/compare/v1.34.0...1.35.3 [1.34.0]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...v1.34.0 [1.33.3]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...1.33.3 [1.32.7]: https://github.com/bUnit-dev/bUnit/compare/v1.31.3...v1.32.7 From 25146a431891af1ebf79202e351320ab1fba9c61 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Tue, 12 Nov 2024 20:30:18 +0000 Subject: [PATCH 59/73] chore: upgrade all packages to dotnet 9 --- .devcontainer/devcontainer.json | 4 ++-- .devcontainer/post-install.sh | 2 +- CHANGELOG.md | 4 ++++ Directory.Packages.props | 16 ++++++++-------- global.json | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 90c45b483..9ec00c266 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,11 +3,11 @@ { "name": "Full", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/dotnet/sdk:9.0-preview", + "image": "mcr.microsoft.com/dotnet/sdk:9.0", "features": { "ghcr.io/devcontainers/features/dotnet:2": { "version": "latest", - "additionalVersions": "7.0,6.0,5.0,3.1" + "additionalVersions": "8.0,7.0,6.0,5.0,3.1" } }, diff --git a/.devcontainer/post-install.sh b/.devcontainer/post-install.sh index 34cef2fcd..0c990f19e 100644 --- a/.devcontainer/post-install.sh +++ b/.devcontainer/post-install.sh @@ -1,7 +1,7 @@ #/bin/bash # Install docfx (should be aligned with docs-deploy.yml) -dotnet tool install --global docfx --version 2.74.1 +dotnet tool restore # Trust dotnet developer certs dotnet dev-certs https --check --trust diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e7ea6ede..2b29eaf80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Added + +- Bumped .NET 9 version dependencies to stable packages. + ## [1.35.3] - 2024-11-12 ### Added diff --git a/Directory.Packages.props b/Directory.Packages.props index 7e21294b6..c25fef9bc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -97,16 +97,16 @@ - - - + + + - - + + - - - + + + diff --git a/global.json b/global.json index 83105ca8e..18562b58c 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestMajor", - "allowPrerelease": true + "allowPrerelease": false } } From 78ae15b8f0e7093d006714fc1487f672147d35bc Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:34:17 +0000 Subject: [PATCH 60/73] Set version to '1.36' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 2aa22fb3e..1b260cc7a 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.36-preview", + "version": "1.36", "assemblyVersion": { "precision": "revision" }, From 8e222e2a0d68873208a4e8b018fcef209407d463 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:34:18 +0000 Subject: [PATCH 61/73] Set version to '1.37-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 2aa22fb3e..4b460b45b 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.36-preview", + "version": "1.37-preview", "assemblyVersion": { "precision": "revision" }, From a8f6182de047926a9a2391f46e7160ee3b47e7cf Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Tue, 12 Nov 2024 20:35:49 +0000 Subject: [PATCH 62/73] Updated CHANGELOG.md for 1.36.0 release --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b29eaf80..1e9ab3753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.36.0] - 2024-11-12 + ### Added - Bumped .NET 9 version dependencies to stable packages. @@ -1421,7 +1423,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.36.0...HEAD +[1.36.0]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...v1.36.0 [1.35.3]: https://github.com/bUnit-dev/bUnit/compare/v1.34.0...1.35.3 [1.34.0]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...v1.34.0 [1.33.3]: https://github.com/bUnit-dev/bUnit/compare/v1.32.7...1.33.3 From 653f5750a40cd11e82fa4593eb3fd7d3cfb1c0b5 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 12 Dec 2024 15:00:36 +0000 Subject: [PATCH 63/73] docs: update sponsor messages --- README.md | 21 +++++++------------ docs/site/index.md | 7 +------ docs/site/templates/bunit/layout/_master.tmpl | 12 ----------- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a923f6597..691daaa00 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,6 @@ # bUnit - a testing library for Blazor components - - - - - - - **bUnit** is a testing library for Blazor Components. Its goal is to make it easy to write _comprehensive, stable_ unit tests. With bUnit, you can: - Setup and define components under tests using C# or Razor syntax @@ -40,22 +33,22 @@ To get started, head to the [getting started documentation](https://bunit.dev/do ## Sponsors -A huge thank you to the [sponsors of my work with bUnit](https://github.com/sponsors/egil). The higher tier sponsors are: +A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). The higher tier sponsors are: diff --git a/docs/site/index.md b/docs/site/index.md index aa7eef8bf..9d0242daa 100644 --- a/docs/site/index.md +++ b/docs/site/index.md @@ -50,14 +50,9 @@ bUnit is available on NuGet in various incarnations. Most users should just pick ## Sponsors -A huge thank you to the [sponsors of my work with bUnit](https://github.com/sponsors/egil). The higher tier sponsors are: +A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). The higher tier sponsors are:
- - @Progress-Telerik -
- Progress Telerik -
@syncfusion
diff --git a/docs/site/templates/bunit/layout/_master.tmpl b/docs/site/templates/bunit/layout/_master.tmpl index 8446a5ad0..c046a765d 100644 --- a/docs/site/templates/bunit/layout/_master.tmpl +++ b/docs/site/templates/bunit/layout/_master.tmpl @@ -138,18 +138,6 @@
-
- - Progress Telerik - -

Premium sponsor: Progress Telerik.

-
-
- - Packt - -

Editorial support provided by Packt.

-
.NET Foundation From 9197071a2ea65094a58e7d780b874b76550a41d2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 14 Dec 2024 02:33:40 +1100 Subject: [PATCH 64/73] refactor: remove static uses of PrettyMarkupFormatter (#1609) PrettyMarkupFormatter is not thread safe https://github.com/VerifyTests/Verify.Bunit/issues/60 --- src/bunit.web/Diffing/DiffMarkupFormatter.cs | 1 + src/bunit.web/Extensions/NodePrintExtensions.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bunit.web/Diffing/DiffMarkupFormatter.cs b/src/bunit.web/Diffing/DiffMarkupFormatter.cs index ccb033627..4feffd455 100644 --- a/src/bunit.web/Diffing/DiffMarkupFormatter.cs +++ b/src/bunit.web/Diffing/DiffMarkupFormatter.cs @@ -16,6 +16,7 @@ public class DiffMarkupFormatter : PrettyMarkupFormatter, IMarkupFormatter /// The is not thread safe, so using this singleton /// instance to format elements may not result in the desired effect. /// + [Obsolete("This instance is not thread safe, use a new instance instead.")] public static new readonly DiffMarkupFormatter Instance = new(); /// diff --git a/src/bunit.web/Extensions/NodePrintExtensions.cs b/src/bunit.web/Extensions/NodePrintExtensions.cs index c54924824..d113d2642 100644 --- a/src/bunit.web/Extensions/NodePrintExtensions.cs +++ b/src/bunit.web/Extensions/NodePrintExtensions.cs @@ -109,6 +109,7 @@ public static string ToMarkupElementOnly(this IElement element) if (element is null) throw new ArgumentNullException(nameof(element)); + var diffMarkupFormatter = new DiffMarkupFormatter(); var result = new StringBuilder(); result.Append(Symbols.LessThan); @@ -120,7 +121,7 @@ public static string ToMarkupElementOnly(this IElement element) foreach (var attribute in element.Attributes) { - result.Append(' ').Append(DiffMarkupFormatter.Instance.ConvertToString(attribute)); + result.Append(' ').Append(diffMarkupFormatter.ConvertToString(attribute)); } if (element.HasChildNodes) From 3111b1de24637c4647f7984c45899efdd7cf338d Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 1 Nov 2024 16:18:26 +0100 Subject: [PATCH 65/73] feat: Add RendererInfo support for .net9 --- CHANGELOG.md | 3 ++ src/bunit.core/Rendering/ITestRenderer.cs | 7 ++++ .../Rendering/MissingRendererInfoException.cs | 33 +++++++++++++++++++ src/bunit.core/Rendering/TestRenderer.cs | 15 +++++++++ .../Rendering/RendererInfoTests.cs | 28 ++++++++++++++++ .../RenderModes/RendererInfoComponent.cs | 20 +++++++++++ 6 files changed, 106 insertions(+) create mode 100644 src/bunit.core/Rendering/MissingRendererInfoException.cs create mode 100644 tests/bunit.core.tests/Rendering/RendererInfoTests.cs create mode 100644 tests/bunit.testassets/RenderModes/RendererInfoComponent.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e9ab3753..ecf041582 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 support for `RendererInfo` (`.net9.0`). + ## [1.36.0] - 2024-11-12 ### Added diff --git a/src/bunit.core/Rendering/ITestRenderer.cs b/src/bunit.core/Rendering/ITestRenderer.cs index 50f8d3e72..cfd855d33 100644 --- a/src/bunit.core/Rendering/ITestRenderer.cs +++ b/src/bunit.core/Rendering/ITestRenderer.cs @@ -78,4 +78,11 @@ IReadOnlyList> FindComponents(IRe /// Disposes all components rendered by the . /// void DisposeComponents(); + +#if NET9_0_OR_GREATER + /// + /// Sets the for the renderer. + /// + void SetRendererInfo(RendererInfo? rendererInfo); +#endif } diff --git a/src/bunit.core/Rendering/MissingRendererInfoException.cs b/src/bunit.core/Rendering/MissingRendererInfoException.cs new file mode 100644 index 000000000..147a254fe --- /dev/null +++ b/src/bunit.core/Rendering/MissingRendererInfoException.cs @@ -0,0 +1,33 @@ +#if NET9_0_OR_GREATER +namespace Bunit.Rendering; + +/// +/// Represents an exception that is thrown when a component under test is trying to access the 'RendererInfo' property, which has not been specified. +/// +public sealed class MissingRendererInfoException : Exception +{ + /// + /// Initializes a new instance of the class. + /// + public MissingRendererInfoException() + : base(""" + A component under test is trying to access the 'RendererInfo' property, which has not been specified. Set it via TestContext.Renderer.SetRendererInfo. + + For example: + + public class SomeTestClass : TestContext + { + [Fact] + public void SomeTestCase() + { + Renderer.SetRendererInfo(new RendererInfo("Server", true)); + ... + } + } + + The four built in render names are 'Static', 'Server', 'WebAssembly', and 'WebView'. + """) + { + } +} +#endif diff --git a/src/bunit.core/Rendering/TestRenderer.cs b/src/bunit.core/Rendering/TestRenderer.cs index 61d4deecf..34d2377f7 100644 --- a/src/bunit.core/Rendering/TestRenderer.cs +++ b/src/bunit.core/Rendering/TestRenderer.cs @@ -64,6 +64,21 @@ private bool IsBatchInProgress /// internal int RenderCount { get; private set; } +#if NET9_0_OR_GREATER + private RendererInfo? rendererInfo; + + /// + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = "The exception is raised to guide users.")] + protected override RendererInfo RendererInfo => rendererInfo ?? throw new MissingRendererInfoException(); + + /// + public void SetRendererInfo(RendererInfo? rendererInfo) + { + this.rendererInfo = rendererInfo; + } + +#endif + #if NETSTANDARD /// /// Initializes a new instance of the class. diff --git a/tests/bunit.core.tests/Rendering/RendererInfoTests.cs b/tests/bunit.core.tests/Rendering/RendererInfoTests.cs new file mode 100644 index 000000000..cdccb3b58 --- /dev/null +++ b/tests/bunit.core.tests/Rendering/RendererInfoTests.cs @@ -0,0 +1,28 @@ +#if NET9_0_OR_GREATER +using Bunit.TestAssets.RenderModes; + +namespace Bunit.Rendering; + +public class RendererInfoTests : TestContext +{ + [Fact(DisplayName = "TestRenderer provides RendererInfo")] + public void Test001() + { + Renderer.SetRendererInfo(new RendererInfo("Server", true)); + var cut = RenderComponent(); + + cut.MarkupMatches(""" +

Is interactive: True

+

Rendermode: Server

+ """); + } + + [Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] + public void Test002() + { + Action act = () => RenderComponent(); + + act.ShouldThrow(); + } +} +#endif \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs b/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs new file mode 100644 index 000000000..9393ab3eb --- /dev/null +++ b/tests/bunit.testassets/RenderModes/RendererInfoComponent.cs @@ -0,0 +1,20 @@ +#if NET9_0_OR_GREATER + +namespace Bunit.TestAssets.RenderModes; + +public class RendererInfoComponent : ComponentBase +{ + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "p"); + builder.AddContent(1, "Is interactive: "); + builder.AddContent(2, RendererInfo.IsInteractive); + builder.CloseElement(); + + builder.OpenElement(3, "p"); + builder.AddContent(4, "Rendermode: "); + builder.AddContent(5, RendererInfo.Name); + builder.CloseElement(); + } +} +#endif \ No newline at end of file From b5bcbd28e1c10e961bec606d4777498fecead815 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 1 Nov 2024 17:06:07 +0100 Subject: [PATCH 66/73] feat: Enable RenderMode cascading to the Component --- CHANGELOG.md | 2 +- src/bunit.core/Rendering/TestRenderer.cs | 21 ++++++ .../Rendering/RenderModeTests.cs | 73 +++++++++++++++++++ .../Rendering/RendererInfoTests.cs | 28 ------- .../ComponentWithServerRenderMode.razor | 15 ++++ .../ComponentWithWebAssemblyRenderMode.razor | 15 ++++ .../ComponentWithoutRenderMode.razor | 14 ++++ 7 files changed, 139 insertions(+), 29 deletions(-) create mode 100644 tests/bunit.core.tests/Rendering/RenderModeTests.cs delete mode 100644 tests/bunit.core.tests/Rendering/RendererInfoTests.cs create mode 100644 tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor create mode 100644 tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor create mode 100644 tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor diff --git a/CHANGELOG.md b/CHANGELOG.md index ecf041582..b55950017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] ### Added -- Added support for `RendererInfo` (`.net9.0`). +- Added support for `RendererInfo` and `AssignedRenderMode` (`.net9.0`). ## [1.36.0] - 2024-11-12 diff --git a/src/bunit.core/Rendering/TestRenderer.cs b/src/bunit.core/Rendering/TestRenderer.cs index 34d2377f7..df41b817a 100644 --- a/src/bunit.core/Rendering/TestRenderer.cs +++ b/src/bunit.core/Rendering/TestRenderer.cs @@ -241,6 +241,27 @@ protected override IComponent ResolveComponentForRenderMode(Type componentType, } #endif +#if NET9_0_OR_GREATER + /// + protected override IComponentRenderMode? GetComponentRenderMode(IComponent component) + { + ArgumentNullException.ThrowIfNull(component); + + var renderModeAttribute = component.GetType() + .GetCustomAttribute(); + + if (renderModeAttribute is not null) + { + return renderModeAttribute.Mode; + } + + var parentComponentState = GetComponentState(component).ParentComponentState; + return parentComponentState is not null + ? GetComponentRenderMode(parentComponentState.Component) + : null; + } +#endif + /// internal Task SetDirectParametersAsync(IRenderedFragmentBase renderedComponent, ParameterView parameters) { diff --git a/tests/bunit.core.tests/Rendering/RenderModeTests.cs b/tests/bunit.core.tests/Rendering/RenderModeTests.cs new file mode 100644 index 000000000..352da9dec --- /dev/null +++ b/tests/bunit.core.tests/Rendering/RenderModeTests.cs @@ -0,0 +1,73 @@ +#if NET9_0_OR_GREATER +using Bunit.TestAssets.RenderModes; + +namespace Bunit.Rendering; + +public class RenderModeTests : TestContext +{ + [Fact(DisplayName = "TestRenderer provides RendererInfo")] + public void Test001() + { + Renderer.SetRendererInfo(new RendererInfo("Server", true)); + var cut = RenderComponent(); + + cut.MarkupMatches(""" +

Is interactive: True

+

Rendermode: Server

+ """); + } + + [Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] + public void Test002() + { + Action act = () => RenderComponent(); + + act.ShouldThrow(); + } + + [Fact(DisplayName = "Renderer should set the RenderModeAttribute on the component")] + public void Test003() + { + var cut = RenderComponent(); + + cut.MarkupMatches("
Assigned render mode: InteractiveServerRenderMode
"); + } + + [Fact(DisplayName = "The AssignedRenderMode is based on the RenderModeAttribute in the component hierarchy where parent component has no RenderMode")] + public void Test004() + { + var cut = RenderComponent( + c => c.AddChildContent()); + + cut.MarkupMatches(""" +
Parent assigned render mode:
+
Assigned render mode: InteractiveWebAssemblyRenderMode
+ """); + } + + [Fact(DisplayName = "Parent and child render mode is specified")] + public void Test005() + { + var cut = RenderComponent( + c => c.AddChildContent()); + + cut.MarkupMatches(""" +
Parent assigned render mode: InteractiveWebAssemblyRenderMode
+
Assigned render mode: InteractiveServerRenderMode
+ """); + } + + [Fact(DisplayName = "Parent and child render mode is not specified")] + public void Test006() + { + var cut = RenderComponent( + c => c.AddChildContent()); + + cut.MarkupMatches(""" +
Parent assigned render mode:
+
Assigned render mode:
+ """); + + } +} +#endif \ No newline at end of file diff --git a/tests/bunit.core.tests/Rendering/RendererInfoTests.cs b/tests/bunit.core.tests/Rendering/RendererInfoTests.cs deleted file mode 100644 index cdccb3b58..000000000 --- a/tests/bunit.core.tests/Rendering/RendererInfoTests.cs +++ /dev/null @@ -1,28 +0,0 @@ -#if NET9_0_OR_GREATER -using Bunit.TestAssets.RenderModes; - -namespace Bunit.Rendering; - -public class RendererInfoTests : TestContext -{ - [Fact(DisplayName = "TestRenderer provides RendererInfo")] - public void Test001() - { - Renderer.SetRendererInfo(new RendererInfo("Server", true)); - var cut = RenderComponent(); - - cut.MarkupMatches(""" -

Is interactive: True

-

Rendermode: Server

- """); - } - - [Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] - public void Test002() - { - Action act = () => RenderComponent(); - - act.ShouldThrow(); - } -} -#endif \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor new file mode 100644 index 000000000..3ce1d35a0 --- /dev/null +++ b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor @@ -0,0 +1,15 @@ +@{ +#if NET9_0_OR_GREATER +} + +@rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer +
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
+@ChildContent + +@code { + [Parameter] public RenderFragment? ChildContent { get; set; } +} + +@{ +#endif +} \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor new file mode 100644 index 000000000..af0888317 --- /dev/null +++ b/tests/bunit.testassets/RenderModes/ComponentWithWebAssemblyRenderMode.razor @@ -0,0 +1,15 @@ +@{ +#if NET9_0_OR_GREATER +} + +@rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveWebAssembly +
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
+@ChildContent + +@code { + [Parameter] public RenderFragment? ChildContent { get; set; } +} + +@{ +#endif +} \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor new file mode 100644 index 000000000..6d5f7f9b7 --- /dev/null +++ b/tests/bunit.testassets/RenderModes/ComponentWithoutRenderMode.razor @@ -0,0 +1,14 @@ +@{ +#if NET9_0_OR_GREATER +} + +
@(ChildContent is not null ? "Parent assigned" : "Assigned") render mode: @AssignedRenderMode?.GetType().Name
+@ChildContent + +@code { + [Parameter] public RenderFragment? ChildContent { get; set; } +} + +@{ +#endif +} \ No newline at end of file From 244680cd96318ab8b71e8dc369917ec3f88e567e Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 15 Nov 2024 16:29:35 +0000 Subject: [PATCH 67/73] fix: support finding render modes specified via @rendermode directive --- .../Rendering/RenderModeMisMatchException.cs | 22 +++ src/bunit.core/Rendering/TestRenderer.cs | 55 +++++-- .../Rendering/RenderModeTests.cs | 73 --------- .../Rendering/RenderModeTests.razor | 142 ++++++++++++++++++ ...omponentThatPrintsAssignedRenderMode.razor | 9 ++ .../ComponentWithChildContent.razor | 6 + .../ComponentWithServerRenderMode.razor | 2 +- .../RenderModes/SectionOutletComponent.razor | 12 ++ 8 files changed, 238 insertions(+), 83 deletions(-) create mode 100644 src/bunit.core/Rendering/RenderModeMisMatchException.cs delete mode 100644 tests/bunit.core.tests/Rendering/RenderModeTests.cs create mode 100644 tests/bunit.core.tests/Rendering/RenderModeTests.razor create mode 100644 tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor create mode 100644 tests/bunit.testassets/RenderModes/ComponentWithChildContent.razor create mode 100644 tests/bunit.testassets/RenderModes/SectionOutletComponent.razor diff --git a/src/bunit.core/Rendering/RenderModeMisMatchException.cs b/src/bunit.core/Rendering/RenderModeMisMatchException.cs new file mode 100644 index 000000000..8187988e3 --- /dev/null +++ b/src/bunit.core/Rendering/RenderModeMisMatchException.cs @@ -0,0 +1,22 @@ +#if NET9_0_OR_GREATER +namespace Bunit.Rendering; + +/// +/// Represents an exception that is thrown when a component under test has mismatching render modes assigned between parent and child components. +/// +public sealed class RenderModeMisMatchException : Exception +{ + /// + /// Initializes a new instance of the class. + /// + public RenderModeMisMatchException() + : base(""" + A component under test has mismatching render modes assigned between parent and child components. + Ensure that the render mode of the parent component matches the render mode of the child component. + Learn more about render modes at https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#render-mode-propagation. + """) + { + HelpLink = "https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#render-mode-propagation"; + } +} +#endif diff --git a/src/bunit.core/Rendering/TestRenderer.cs b/src/bunit.core/Rendering/TestRenderer.cs index df41b817a..f26e77fd0 100644 --- a/src/bunit.core/Rendering/TestRenderer.cs +++ b/src/bunit.core/Rendering/TestRenderer.cs @@ -1,7 +1,7 @@ -using Microsoft.Extensions.Logging; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ExceptionServices; +using Microsoft.Extensions.Logging; namespace Bunit.Rendering; @@ -247,18 +247,55 @@ protected override IComponent ResolveComponentForRenderMode(Type componentType, { ArgumentNullException.ThrowIfNull(component); - var renderModeAttribute = component.GetType() - .GetCustomAttribute(); + // Search from the current component all the way up the render tree. + // All components must have the same render mode specified (or none at all). + // Return the render mode that is found after checking the full tree. + return GetAndValidateRenderMode(component, childRenderMode: null); - if (renderModeAttribute is not null) + IComponentRenderMode? GetAndValidateRenderMode(IComponent component, IComponentRenderMode? childRenderMode) { - return renderModeAttribute.Mode; + var componentState = GetComponentState(component); + var renderMode = GetRenderModeForComponent(componentState); + + if (childRenderMode is not null && renderMode is not null && childRenderMode != renderMode) + { + throw new RenderModeMisMatchException(); + } + + return componentState.ParentComponentState is null + ? renderMode ?? childRenderMode + : GetAndValidateRenderMode(componentState.ParentComponentState.Component, renderMode ?? childRenderMode); } - var parentComponentState = GetComponentState(component).ParentComponentState; - return parentComponentState is not null - ? GetComponentRenderMode(parentComponentState.Component) - : null; + IComponentRenderMode? GetRenderModeForComponent(ComponentState componentState) + { + var renderModeAttribute = componentState.Component.GetType().GetCustomAttribute(); + if (renderModeAttribute is { Mode: not null }) + { + return renderModeAttribute.Mode; + } + + if (componentState.ParentComponentState is not null) + { + var parentFrames = GetCurrentRenderTreeFrames(componentState.ParentComponentState.ComponentId); + var foundComponentStart = false; + for (var i = 0; i < parentFrames.Count; i++) + { + ref var frame = ref parentFrames.Array[i]; + + if (frame.FrameType is RenderTreeFrameType.Component) + { + foundComponentStart = frame.ComponentId == componentState.ComponentId; + } + else if (foundComponentStart && frame.FrameType is RenderTreeFrameType.ComponentRenderMode) + { + return frame.ComponentRenderMode; + } + } + } + + return null; + } } #endif diff --git a/tests/bunit.core.tests/Rendering/RenderModeTests.cs b/tests/bunit.core.tests/Rendering/RenderModeTests.cs deleted file mode 100644 index 352da9dec..000000000 --- a/tests/bunit.core.tests/Rendering/RenderModeTests.cs +++ /dev/null @@ -1,73 +0,0 @@ -#if NET9_0_OR_GREATER -using Bunit.TestAssets.RenderModes; - -namespace Bunit.Rendering; - -public class RenderModeTests : TestContext -{ - [Fact(DisplayName = "TestRenderer provides RendererInfo")] - public void Test001() - { - Renderer.SetRendererInfo(new RendererInfo("Server", true)); - var cut = RenderComponent(); - - cut.MarkupMatches(""" -

Is interactive: True

-

Rendermode: Server

- """); - } - - [Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] - public void Test002() - { - Action act = () => RenderComponent(); - - act.ShouldThrow(); - } - - [Fact(DisplayName = "Renderer should set the RenderModeAttribute on the component")] - public void Test003() - { - var cut = RenderComponent(); - - cut.MarkupMatches("
Assigned render mode: InteractiveServerRenderMode
"); - } - - [Fact(DisplayName = "The AssignedRenderMode is based on the RenderModeAttribute in the component hierarchy where parent component has no RenderMode")] - public void Test004() - { - var cut = RenderComponent( - c => c.AddChildContent()); - - cut.MarkupMatches(""" -
Parent assigned render mode:
-
Assigned render mode: InteractiveWebAssemblyRenderMode
- """); - } - - [Fact(DisplayName = "Parent and child render mode is specified")] - public void Test005() - { - var cut = RenderComponent( - c => c.AddChildContent()); - - cut.MarkupMatches(""" -
Parent assigned render mode: InteractiveWebAssemblyRenderMode
-
Assigned render mode: InteractiveServerRenderMode
- """); - } - - [Fact(DisplayName = "Parent and child render mode is not specified")] - public void Test006() - { - var cut = RenderComponent( - c => c.AddChildContent()); - - cut.MarkupMatches(""" -
Parent assigned render mode:
-
Assigned render mode:
- """); - - } -} -#endif \ No newline at end of file diff --git a/tests/bunit.core.tests/Rendering/RenderModeTests.razor b/tests/bunit.core.tests/Rendering/RenderModeTests.razor new file mode 100644 index 000000000..d9a0fb514 --- /dev/null +++ b/tests/bunit.core.tests/Rendering/RenderModeTests.razor @@ -0,0 +1,142 @@ +@using Bunit.TestAssets.RenderModes; +@inherits TestContext +@code { +#if NET9_0_OR_GREATER + [Fact(DisplayName = "TestRenderer provides RendererInfo")] + public void Test001() + { + Renderer.SetRendererInfo(new RendererInfo("Server", true)); + var cut = RenderComponent(); + + cut.MarkupMatches( + @ +

Is interactive: True

+

Rendermode: Server

+
); + } + + [Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")] + public void Test002() + { + Action act = () => RenderComponent(); + + act.ShouldThrow(); + } + + [Fact(DisplayName = "Renderer should set the RenderModeAttribute on the component")] + public void Test003() + { + var cut = RenderComponent(); + + cut.MarkupMatches(@
Assigned render mode: InteractiveServerRenderMode
); + } + + [Fact(DisplayName = "The AssignedRenderMode is based on the RenderModeAttribute in the component hierarchy where parent component has no RenderMode")] + public void Test004() + { + var cut = Render( + @ + + ); + + cut.MarkupMatches( + @ +
Parent assigned render mode:
+
Assigned render mode: InteractiveWebAssemblyRenderMode
+
); + } + + [Fact(DisplayName = "Parent and child render mode is specified")] + public void Test005() + { + var cut = Render( + @ + + ); + + cut.MarkupMatches( + @ +
Parent assigned render mode: InteractiveServerRenderMode
+
Assigned render mode: InteractiveServerRenderMode
+
); + } + + [Fact(DisplayName = "Parent and child render mode is not specified")] + public void Test006() + { + var cut = Render( + @ + + ); + + cut.MarkupMatches( + @ +
Parent assigned render mode:
+
Assigned render mode:
+
); + } + + [Fact(DisplayName = "Rendermode specified on child")] + public void Test007() + { + var cut = Render( + @ + + ); + + cut.MarkupMatches(@

Assigned Render Mode: InteractiveServerRenderMode

); + } + + [Fact(DisplayName = "Assigned Render Mode is inherited all the way down the component hierarchy")] + public void Test008() + { + var cut = Render( + @ + + + + ); + + cut.MarkupMatches(@

Assigned Render Mode: InteractiveServerRenderMode

); + } + + [Fact(DisplayName = "Having a component with section outlet and RenderMode is specifying for child component")] + public void Test009() + { + // See: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/sections?view=aspnetcore-8.0#section-interaction-with-other-blazor-features + var cut = Render(@); + + cut.MarkupMatches(@

Assigned Render Mode: InteractiveWebAssemblyRenderMode

); + } + + [Fact(DisplayName = "Assigned Render Mode on siblings")] + public void Test010() + { + var cut = Render( + @ + + + ); + + cut.MarkupMatches( + @ +

Assigned Render Mode: InteractiveServerRenderMode

+

Assigned Render Mode: InteractiveWebAssemblyRenderMode

+
); + } + + + [Fact(DisplayName = "Different assigned RenderMode between child and parent throws")] + public void Test020() + { + var act = () => Render( + @ + + + + ); + + act.ShouldThrow(); // todo: figure out good exception to use + } +#endif +} diff --git a/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor new file mode 100644 index 000000000..effe0ff2c --- /dev/null +++ b/tests/bunit.testassets/RenderModes/ComponentThatPrintsAssignedRenderMode.razor @@ -0,0 +1,9 @@ +@{ +#if NET9_0_OR_GREATER +} + +

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

+ +@{ +#endif +} diff --git a/tests/bunit.testassets/RenderModes/ComponentWithChildContent.razor b/tests/bunit.testassets/RenderModes/ComponentWithChildContent.razor new file mode 100644 index 000000000..c8b0cd4e1 --- /dev/null +++ b/tests/bunit.testassets/RenderModes/ComponentWithChildContent.razor @@ -0,0 +1,6 @@ +@ChildContent +@code { + + [Parameter] public RenderFragment ChildContent { get; set; } = default!; + +} \ No newline at end of file diff --git a/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor index 3ce1d35a0..dd008df6c 100644 --- a/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor +++ b/tests/bunit.testassets/RenderModes/ComponentWithServerRenderMode.razor @@ -12,4 +12,4 @@ @{ #endif -} \ No newline at end of file +} diff --git a/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor b/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor new file mode 100644 index 000000000..7e860e07d --- /dev/null +++ b/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor @@ -0,0 +1,12 @@ +@{ +#if NET9_0_OR_GREATER +} + + + + + + +@{ +#endif +} From 1e032b941c6d3a950869c4424de6515c2fca6075 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Fri, 15 Nov 2024 16:29:59 +0000 Subject: [PATCH 68/73] fix: support passing assigned render mode via parameter builder --- Directory.Build.props | 1 + .../ComponentParameterCollection.cs | 11 +++++ .../ComponentParameterCollectionBuilder.cs | 29 ++++++++++---- .../Rendering/RenderModeTests.razor | 40 +++++++++++++++++-- .../RenderModes/SectionOutletComponent.cs | 30 ++++++++++++++ .../RenderModes/SectionOutletComponent.razor | 12 ------ .../bunit.testassets/bunit.testassets.csproj | 1 + 7 files changed, 101 insertions(+), 23 deletions(-) create mode 100644 tests/bunit.testassets/RenderModes/SectionOutletComponent.cs delete mode 100644 tests/bunit.testassets/RenderModes/SectionOutletComponent.razor diff --git a/Directory.Build.props b/Directory.Build.props index a3c2a053a..b2194a03c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -16,6 +16,7 @@ enable CA1014,NU5104,NETSDK1138,SYSLIB0051 false + true full diff --git a/src/bunit.core/ComponentParameterCollection.cs b/src/bunit.core/ComponentParameterCollection.cs index 7b248b096..9f179bc94 100644 --- a/src/bunit.core/ComponentParameterCollection.cs +++ b/src/bunit.core/ComponentParameterCollection.cs @@ -19,6 +19,14 @@ public class ComponentParameterCollection : ICollection, IRe /// public bool IsReadOnly { get; } +#if NET9_0_OR_GREATER + /// + /// Gets or sets the that will be specified in + /// the render tree for component the parameters are being passed to. + /// + public IComponentRenderMode? RenderMode { get; set; } +#endif + /// /// Adds a to the collection. /// @@ -104,6 +112,9 @@ void AddComponent(RenderTreeBuilder builder) { builder.OpenComponent(0); AddAttributes(builder); +#if NET9_0_OR_GREATER + builder.AddComponentRenderMode(RenderMode); +#endif builder.CloseComponent(); } diff --git a/src/bunit.core/ComponentParameterCollectionBuilder.cs b/src/bunit.core/ComponentParameterCollectionBuilder.cs index f4c1fa04e..492b035a5 100644 --- a/src/bunit.core/ComponentParameterCollectionBuilder.cs +++ b/src/bunit.core/ComponentParameterCollectionBuilder.cs @@ -78,7 +78,7 @@ public ComponentParameterCollectionBuilder Add(Expr /// A lambda function that selects the parameter. /// The markup string to pass to the . /// This . - public ComponentParameterCollectionBuilder Add(Expression> parameterSelector, [StringSyntax("Html")]string markup) + public ComponentParameterCollectionBuilder Add(Expression> parameterSelector, [StringSyntax("Html")] string markup) => Add(parameterSelector, markup.ToMarkupRenderFragment()); /// @@ -266,7 +266,7 @@ public ComponentParameterCollectionBuilder AddChildContent(RenderFra /// /// The markup string to pass the ChildContent parameter wrapped in a . /// This . - public ComponentParameterCollectionBuilder AddChildContent([StringSyntax("Html")]string markup) + public ComponentParameterCollectionBuilder AddChildContent([StringSyntax("Html")] string markup) => AddChildContent(markup.ToMarkupRenderFragment()); /// @@ -344,11 +344,11 @@ public ComponentParameterCollectionBuilder Bind( Action changedAction, Expression>? valueExpression = null) { - #if !NET8_0_OR_GREATER +#if !NET8_0_OR_GREATER var (parameterName, _, isCascading) = GetParameterInfo(parameterSelector); - #else +#else var (parameterName, _, isCascading) = GetParameterInfo(parameterSelector, initialValue); - #endif +#endif if (isCascading) throw new ArgumentException("Using Bind with a cascading parameter is not allowed.", parameterName); @@ -397,6 +397,19 @@ static string TrimEnd(string source, string value) : source; } +#if NET9_0_OR_GREATER + /// + /// Sets (or unsets) the for the component and child components. + /// + /// The render mode to assign to the component, e.g. RenderMode.InteractiveServer, or , to not assign a specific render mode. + /// This . + public ComponentParameterCollectionBuilder SetAssignedRenderMode(IComponentRenderMode? renderMode) + { + parameters.RenderMode = renderMode; + return this; + } +#endif + /// /// Try to add a for a parameter with the , if /// has a property with that name, AND that property has a @@ -454,14 +467,14 @@ Expression> parameterSelector : propInfoCandidate; var paramAttr = propertyInfo?.GetCustomAttribute(inherit: true); - #if !NET8_0_OR_GREATER +#if !NET8_0_OR_GREATER var cascadingParamAttr = propertyInfo?.GetCustomAttribute(inherit: true); if (propertyInfo is null || (paramAttr is null && cascadingParamAttr is null)) throw new ArgumentException($"The parameter selector '{parameterSelector}' does not resolve to a public property on the component '{typeof(TComponent)}' with a [Parameter] or [CascadingParameter] attribute.", nameof(parameterSelector)); return (propertyInfo.Name, CascadingValueName: cascadingParamAttr?.Name, IsCascading: cascadingParamAttr is not null); - #else +#else var cascadingParamAttrBase = propertyInfo?.GetCustomAttribute(inherit: true); if (propertyInfo is null || (paramAttr is null && cascadingParamAttrBase is null)) @@ -494,7 +507,7 @@ static ArgumentException CreateErrorMessageForSupplyFromQuery( NavigationManager.NavigateTo(uri); """); } - #endif +#endif } private static bool HasChildContentParameter() diff --git a/tests/bunit.core.tests/Rendering/RenderModeTests.razor b/tests/bunit.core.tests/Rendering/RenderModeTests.razor index d9a0fb514..e389650f3 100644 --- a/tests/bunit.core.tests/Rendering/RenderModeTests.razor +++ b/tests/bunit.core.tests/Rendering/RenderModeTests.razor @@ -1,7 +1,9 @@ +@code{ + #if NET9_0_OR_GREATER +} @using Bunit.TestAssets.RenderModes; @inherits TestContext @code { -#if NET9_0_OR_GREATER [Fact(DisplayName = "TestRenderer provides RendererInfo")] public void Test001() { @@ -104,7 +106,7 @@ public void Test009() { // See: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/sections?view=aspnetcore-8.0#section-interaction-with-other-blazor-features - var cut = Render(@); + var cut = Render(@); cut.MarkupMatches(@

Assigned Render Mode: InteractiveWebAssemblyRenderMode

); } @@ -125,6 +127,36 @@ ); } + [Fact(DisplayName = "SetAssignedRenderMode on root component")] + public void Test011() + { + var cut = RenderComponent(ps => ps.SetAssignedRenderMode(RenderMode.InteractiveServer)); + cut.MarkupMatches(@

Assigned Render Mode: InteractiveServerRenderMode

); + } + + [Fact(DisplayName = "SetAssignedRenderMode on parent component cascades to children")] + public void Test012() + { + var cut = RenderComponent(ps => ps + .SetAssignedRenderMode(RenderMode.InteractiveWebAssembly) + .AddChildContent()); + + cut.MarkupMatches(@

Assigned Render Mode: InteractiveWebAssemblyRenderMode

); + } + + [Fact(DisplayName = "SetAssignedRenderMode child components")] + public void Test013() + { + var cut = RenderComponent(ps => ps + .AddChildContent(pps => pps.SetAssignedRenderMode(RenderMode.InteractiveServer)) + .AddChildContent(pps => pps.SetAssignedRenderMode(RenderMode.InteractiveWebAssembly))); + + cut.MarkupMatches( + @ +

Assigned Render Mode: InteractiveServerRenderMode

+

Assigned Render Mode: InteractiveWebAssemblyRenderMode

+
); + } [Fact(DisplayName = "Different assigned RenderMode between child and parent throws")] public void Test020() @@ -138,5 +170,7 @@ act.ShouldThrow(); // todo: figure out good exception to use } -#endif +} +@code{ + #endif } diff --git a/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs b/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs new file mode 100644 index 000000000..70dd7d9a1 --- /dev/null +++ b/tests/bunit.testassets/RenderModes/SectionOutletComponent.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Components.Web; + +#if NET8_0_OR_GREATER +using Microsoft.AspNetCore.Components.Sections; +#endif + +namespace Bunit.TestAssets.RenderModes; + +public class SectionOutletComponent : ComponentBase +{ +#if NET8_0_OR_GREATER + private static readonly Guid SectionId = Guid.NewGuid(); +#endif + + [Parameter] public RenderFragment ChildContent { get; set; } + + protected override void BuildRenderTree(RenderTreeBuilder builder) + { +#if NET8_0_OR_GREATER + builder.OpenComponent(0); + builder.AddComponentParameter(1, nameof(SectionOutlet.SectionId), SectionId); + builder.AddComponentRenderMode(RenderMode.InteractiveWebAssembly); + builder.CloseComponent(); + builder.OpenComponent(10); + builder.AddComponentParameter(11, nameof(SectionContent.SectionId), SectionId); + builder.AddAttribute(12, nameof(SectionContent.ChildContent), ChildContent); + builder.CloseComponent(); +#endif + } +} diff --git a/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor b/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor deleted file mode 100644 index 7e860e07d..000000000 --- a/tests/bunit.testassets/RenderModes/SectionOutletComponent.razor +++ /dev/null @@ -1,12 +0,0 @@ -@{ -#if NET9_0_OR_GREATER -} - - - - - - -@{ -#endif -} diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj index 424468974..183551378 100644 --- a/tests/bunit.testassets/bunit.testassets.csproj +++ b/tests/bunit.testassets/bunit.testassets.csproj @@ -20,6 +20,7 @@ + From a4c5161cfa7277a1509ae838baf0bfec4f86aa3a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 27 Nov 2024 15:59:35 +0100 Subject: [PATCH 69/73] docs: Added docs and exposes via TestContext --- .vscode/tasks.json | 4 +- docs/site/docs/interaction/index.md | 1 + docs/site/docs/interaction/render-modes.md | 157 ++++++++++++++++++ docs/site/docs/toc.md | 1 + .../Rendering/MissingRendererInfoException.cs | 13 +- src/bunit.core/TestContextBase.cs | 10 ++ src/bunit.web/TestContextWrapper.cs | 7 + .../Rendering/RenderModeTests.razor | 2 +- 8 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 docs/site/docs/interaction/render-modes.md diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9aebda5c8..458ec69a3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,12 +6,12 @@ { "label": "Serve Docs (Without Build)", "type": "shell", - "command": "docfx metadata docs/site/docfx.json && docfx docs/site/docfx.json --serve" + "command": "dotnet docfx metadata docs/site/docfx.json && dotnet docfx docs/site/docfx.json --serve" }, { "label": "Serve Docs (With Build for API Documentation)", "type": "shell", - "command": "dotnet build -c Release && docfx metadata docs/site/docfx.json && docfx docs/site/docfx.json --serve" + "command": "dotnet build -c Release && dotnet docfx metadata docs/site/docfx.json && docfx docs/site/docfx.json --serve" }, { "label": "Run all tests (Release Mode)", diff --git a/docs/site/docs/interaction/index.md b/docs/site/docs/interaction/index.md index 96e06fdde..9967c90ea 100644 --- a/docs/site/docs/interaction/index.md +++ b/docs/site/docs/interaction/index.md @@ -11,3 +11,4 @@ This section covers the various ways to interact with a component under test, e. - **:** 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. +- **:** This covers the different render modes and their interaction with bUnit. diff --git a/docs/site/docs/interaction/render-modes.md b/docs/site/docs/interaction/render-modes.md new file mode 100644 index 000000000..fc40eee6d --- /dev/null +++ b/docs/site/docs/interaction/render-modes.md @@ -0,0 +1,157 @@ +--- +uid: render-modes +title: Render modes and RendererInfo +--- + +# Support for render modes and `RendererInfo` +This article explains how to emulate different render modes and `RendererInfo` in bUnit tests. + +Render modes in Blazor Web Apps determine the hosting model and interactivity of components. A render mode can be applied to a component using the `@rendermode` directive. The [`RendererInfo`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.rendererinfo?view=aspnetcore-9.0) allows the application to determine the interactivity and location of the component. For more details, see the [Blazor render modes](https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0) documentation. + +## Setting the render mode for a component under test +Setting the render mode can be done via the method when writing in a C# file. In a razor file use the `@rendermode` directive. Both take an [`IComponentRenderMode`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.icomponentrendermode?view=aspnetcore-9.0) object as a parameter. Normally this is one of the following types: + * [`InteractiveAutoRenderMode`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.web.interactiveautorendermode?view=aspnetcore-9.0) + * [`InteractiveServerRendeMode`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.web.interactiveserverrendermode?view=aspnetcore-9.0) + * [`InteractiveWebAssemblyRenderMode`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.web.interactivewebassemblyrendermode?view=aspnetcore-9.0) + +For ease of use the [`RenderMode`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.web.rendermode?view=aspnetcore-9.0) class defines all three of them. + +For example `MovieComponent.razor`: +```razor +@if (AssignedRenderMode is null) +{ + // The render mode is Static Server +
+ + + +} +else +{ + // The render mode is Interactive Server, WebAssembly, or Auto + + +} +``` + +The following example shows how to test the above component to check both render modes: + +# [C# test code](#tab/csharp) + +```csharp +[Fact] +public void InteractiveServer() +{ + // Act + var cut = RenderComponent(ps => ps + .SetAssignedRenderMode(RenderMode.InteractiveServer)); + + // Assert + cut.MarkupMatches(""" + + + """); +} + +[Fact] +public void StaticRendering() +{ + // Act + var cut = RenderComponent(); + // This is the same behavior as: + // var cut = RenderComponent(ps => ps + // .SetAssignedRenderMode(null)); + + // Assert + cut.MarkupMatches(""" +
+ + + + """); +} +``` + +# [Razor test code](#tab/razor) + +```razor +@inherits TestContext +@code { + [Fact] + public void InteractiveServer() + { + // Act + var cut = Render(@); + + // Assert + cut.MarkupMatches(@ + + + ); + } + + [Fact] + public void StaticRendering() + { + // Act + var cut = Render(@); + + // Assert + cut.MarkupMatches(@
+ + + ); + } +} +``` + +*** + +## Setting the `RendererInfo` during testing +To control the `ComponentBase.RendererInfo` property during testing, use the method on the `TestContext` class. The `SetRendererInfo` method takes an nullable `RendererInfo` object as a parameter. Passing `null` will set the `ComponentBase.RendererInfo` to `null`. + +A component (`AssistentComponent.razor`) might check if interactivity is given to enable a button: + +```razor +@if (RendererInfo.IsInteractive) +{ +

Hey I am your assistant

+} +else +{ +

Loading...

+} +``` + +In the test, you can set the `RendererInfo` to enable or disable the button: + +```csharp +[Fact] +public void SimulatingPreRenderingOnBlazorServer() +{ + // Arrange + SetRendererInfo(new RendererInfo(rendererName: "Static", isInteractive: false)); + + // Act + var cut = RenderComponent(); + + // Assert + cut.MarkupMatches("

Loading...

"); +} + +[Fact] +public void SimulatingInteractiveServerRendering() +{ + // Arrange + SetRendererInfo(new RendererInfo(rendererMode: "Server", isInteractive: true)); + + // Act + var cut = RenderComponent(); + + // Assert + cut.MarkupMatches("

Hey I am your assistant

"); +} +``` + +> [!NOTE] +> If a component under test uses the `ComponentBase.RendererInfo` property and the `SetRendererInfo` on `TestContext` hasn't been passed in a `RendererInfo` object, the renderer will throw an exception. \ No newline at end of file diff --git a/docs/site/docs/toc.md b/docs/site/docs/toc.md index 327afde06..8d937b05c 100644 --- a/docs/site/docs/toc.md +++ b/docs/site/docs/toc.md @@ -14,6 +14,7 @@ ## [Trigger renders](xref:trigger-renders) ## [Awaiting an async state change](xref:awaiting-async-state) ## [Disposing components](xref:dispose-components) +## [Render modes and RendererInfo](xref:render-modes) # [Verifying output](xref:verification) ## [Verify markup](xref:verify-markup) diff --git a/src/bunit.core/Rendering/MissingRendererInfoException.cs b/src/bunit.core/Rendering/MissingRendererInfoException.cs index 147a254fe..a763a0d98 100644 --- a/src/bunit.core/Rendering/MissingRendererInfoException.cs +++ b/src/bunit.core/Rendering/MissingRendererInfoException.cs @@ -18,16 +18,19 @@ public MissingRendererInfoException() public class SomeTestClass : TestContext { [Fact] - public void SomeTestCase() - { - Renderer.SetRendererInfo(new RendererInfo("Server", true)); - ... + public void SomeTestCase() + { + SetRendererInfo(new RendererInfo("Server", true)); + ... } } - + The four built in render names are 'Static', 'Server', 'WebAssembly', and 'WebView'. + + Go to https://bunit.dev/docs/interaction/render-modes for more information. """) { + HelpLink = "https://bunit.dev/docs/interaction/render-modes"; } } #endif diff --git a/src/bunit.core/TestContextBase.cs b/src/bunit.core/TestContextBase.cs index 9c2fa1e8a..d9e3edce8 100644 --- a/src/bunit.core/TestContextBase.cs +++ b/src/bunit.core/TestContextBase.cs @@ -118,4 +118,14 @@ public void DisposeComponents() { Renderer.DisposeComponents(); } + +#if NET9_0_OR_GREATER + /// + /// Sets the for the renderer. + /// + public void SetRendererInfo(RendererInfo? rendererInfo) + { + Renderer.SetRendererInfo(rendererInfo); + } +#endif } diff --git a/src/bunit.web/TestContextWrapper.cs b/src/bunit.web/TestContextWrapper.cs index a6a9c57c0..1ddb194d5 100644 --- a/src/bunit.web/TestContextWrapper.cs +++ b/src/bunit.web/TestContextWrapper.cs @@ -83,6 +83,13 @@ public virtual IRenderedFragment Render(RenderFragment renderFragment) ///
public virtual void DisposeComponents() => TestContext?.DisposeComponents(); +#if NET9_0_OR_GREATER + /// + /// Sets the for the renderer. + /// + public virtual void SetRendererInfo(RendererInfo? rendererInfo) => TestContext?.SetRendererInfo(rendererInfo); +#endif + /// /// Dummy method required to allow Blazor's compiler to generate /// C# from .razor files. diff --git a/tests/bunit.core.tests/Rendering/RenderModeTests.razor b/tests/bunit.core.tests/Rendering/RenderModeTests.razor index e389650f3..0bded05f6 100644 --- a/tests/bunit.core.tests/Rendering/RenderModeTests.razor +++ b/tests/bunit.core.tests/Rendering/RenderModeTests.razor @@ -7,7 +7,7 @@ [Fact(DisplayName = "TestRenderer provides RendererInfo")] public void Test001() { - Renderer.SetRendererInfo(new RendererInfo("Server", true)); + SetRendererInfo(new RendererInfo("Server", true)); var cut = RenderComponent(); cut.MarkupMatches( From 46e416c8d52dc49778baa06a9278cb4c832fea1e Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 13 Dec 2024 16:50:33 +0100 Subject: [PATCH 70/73] chore: Update packages --- .config/dotnet-tools.json | 2 +- Directory.Packages.props | 46 +++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 10bd8b7a3..294e26e0b 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -10,7 +10,7 @@ "rollForward": false }, "docfx": { - "version": "2.77.0", + "version": "2.78.2", "commands": [ "docfx" ], diff --git a/Directory.Packages.props b/Directory.Packages.props index c25fef9bc..48d1d7ddb 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -58,16 +58,16 @@ - + - - - - - - - - + + + + + + + + @@ -86,14 +86,14 @@ - + - - + + - - - + + + @@ -103,7 +103,7 @@ - + @@ -122,7 +122,7 @@ - + @@ -140,10 +140,10 @@ - - - - + + + + From 5a2c0f47a14323846967a9608f5f9eb22c78fe17 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 13 Dec 2024 16:03:22 +0000 Subject: [PATCH 71/73] Set version to '1.37' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 4b460b45b..4c937cfb9 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.37-preview", + "version": "1.37", "assemblyVersion": { "precision": "revision" }, From 9f2586688eb3c2fa787a204897fc0fd118640998 Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 13 Dec 2024 16:03:23 +0000 Subject: [PATCH 72/73] Set version to '1.38-preview' --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 4b460b45b..2983632ed 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.37-preview", + "version": "1.38-preview", "assemblyVersion": { "precision": "revision" }, From 61cef65620b117aedde7ba1120b2ee0137e8e8dc Mon Sep 17 00:00:00 2001 From: bUnit bot Date: Fri, 13 Dec 2024 16:16:00 +0000 Subject: [PATCH 73/73] Updated CHANGELOG.md for 1.37.7 release --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b55950017..54d178487 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +## [1.37.7] - 2024-12-13 + ### Added + - Added support for `RendererInfo` and `AssignedRenderMode` (`.net9.0`). ## [1.36.0] - 2024-11-12 @@ -1426,7 +1429,8 @@ The latest version of the library is availble on NuGet: - **Wrong casing on keyboard event dispatch helpers.** The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`. -[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.36.0...HEAD +[unreleased]: https://github.com/bUnit-dev/bUnit/compare/v1.37.7...HEAD +[1.37.7]: https://github.com/bUnit-dev/bUnit/compare/v1.36.0...1.37.7 [1.36.0]: https://github.com/bUnit-dev/bUnit/compare/v1.35.3...v1.36.0 [1.35.3]: https://github.com/bUnit-dev/bUnit/compare/v1.34.0...1.35.3 [1.34.0]: https://github.com/bUnit-dev/bUnit/compare/v1.33.3...v1.34.0
- - @Progress-Telerik + + @syncfusion
- Progress Telerik + Syncfusion
- - @syncfusion + + @JetBrainsOfficial
- Syncfusion + JetBrains