From b956283f6fe9e7dcb473e8f212fdc9e58fd34a5f Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 14 Aug 2024 20:57:26 +0200 Subject: [PATCH 1/4] fix: Only throw bUnit created exceptions to the user --- CHANGELOG.md | 4 ++++ src/bunit.web/Extensions/InputFile/InputFileExtensions.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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/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(); } } } From 82fe219d7f4493bb7b3d9fea98f8fb829ff64455 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 14 Aug 2024 21:19:15 +0200 Subject: [PATCH 2/4] fix: .NET 9 p7 issues --- .../Implementation/VirtualizeJSRuntimeInvocationHandler.cs | 6 ++++++ src/bunit.web/Rendering/BunitHtmlParser.cs | 4 ++++ 2 files changed, 10 insertions(+) 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; From 7d8071ab47f76d70200ce594f7689e2b23709d31 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 14 Aug 2024 21:22:52 +0200 Subject: [PATCH 3/4] chore: Bump packages --- .github/workflows/release.yml | 2 +- Directory.Build.props | 2 +- benchmark/bunit.benchmarks/bunit.benchmarks.csproj | 2 +- src/Directory.Build.props | 2 +- tests/bunit.generators.tests/bunit.generators.tests.csproj | 4 ++-- tests/bunit.testassets/bunit.testassets.csproj | 4 ++-- 6 files changed, 8 insertions(+), 8 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/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/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/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 @@ - - + + From b51e5dd23c51a477c24f3896316c461a2d672dc0 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 14 Aug 2024 21:27:23 +0200 Subject: [PATCH 4/4] fix: S3993 --- .../TestDoubles/Localization/PlaceholderStringLocalization.cs | 2 ++ tests/bunit.testassets/XunitExtensions/RepeatAttribute.cs | 1 + .../TestDoubles/NavigationManager/FakeNavigationManagerTest.cs | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) 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.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.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"); }