From 4d86205a4ef3777ff22d61d3abaabc3e8c44d31d Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 10 Jun 2025 09:39:17 +0100 Subject: [PATCH 1/3] Fix Assert.Throws Type Check --- TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs b/TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs index 16ffc02ffc..0313e9906d 100644 --- a/TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs +++ b/TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs @@ -21,7 +21,7 @@ public static class ThrowsExtensions public static ThrowsException Throws(this IDelegateSource delegateSource, Type type, [CallerArgumentExpression("type")] string? doNotPopulateThisValue = null) { return new ThrowsException( - delegateSource.RegisterAssertion(new ThrowsOfTypeAssertCondition(), [doNotPopulateThisValue]), + delegateSource.RegisterAssertion(new ThrowsOfTypeAssertCondition(type), [doNotPopulateThisValue]), delegateSource, e => e); } @@ -82,4 +82,4 @@ public static ThrowsException WithParameterName new ThrowsWithParamNameAssertCondition(expected, StringComparison.Ordinal, ex => selector(ex) as ArgumentException), [doNotPopulateThisValue]); return throwsException; } -} \ No newline at end of file +} From f1dfd74f05311857ac63214f002d1cbdd7d8b234 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 10 Jun 2025 09:44:15 +0100 Subject: [PATCH 2/3] Update Throws.ExceptionTests.cs --- .../Delegates/Throws.ExceptionTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs b/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs index f75819ba22..23fe86c493 100644 --- a/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs +++ b/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs @@ -49,5 +49,22 @@ public async Task Succeeds_For_Code_With_Exceptions() await Assert.That(sut).ThrowsNothing(); } + + private void ThrowsArgumentException() => throw new ArgumentException("Just for testing"); + + [Test] + public async Task ThrowsAsync_DoesNotCheckType() + { + await Assert.That(async () => + await Assert.ThrowsAsync(LocalTestFunction) + ).Throws(); + return; + + Task LocalTestFunction() + { + ThrowsArgumentException(); + return Task.CompletedTask; + } + } } } From f0d6a29f38e09449926ec406144965919a531893 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Tue, 10 Jun 2025 09:46:25 +0100 Subject: [PATCH 3/3] Update Throws.ExceptionTests.cs --- .../Delegates/Throws.ExceptionTests.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs b/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs index 23fe86c493..85894deef6 100644 --- a/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs +++ b/TUnit.Assertions.Tests/Assertions/Delegates/Throws.ExceptionTests.cs @@ -27,7 +27,7 @@ await Assert.That(sut).ThrowsException() } [Test] - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "")] + [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application assemblies.", Justification = "Test method.")] public async Task Returns_Exception_When_Awaited() { Exception exception = CreateCustomException(); @@ -50,21 +50,22 @@ public async Task Succeeds_For_Code_With_Exceptions() await Assert.That(sut).ThrowsNothing(); } - private void ThrowsArgumentException() => throw new ArgumentException("Just for testing"); + private void ThrowsArgumentException() + => throw new ArgumentException("Just for testing"); - [Test] - public async Task ThrowsAsync_DoesNotCheckType() - { - await Assert.That(async () => - await Assert.ThrowsAsync(LocalTestFunction) - ).Throws(); - return; + [Test] + public async Task ThrowsAsync_DoesNotCheckType() + { + await Assert.That(async () => + await Assert.ThrowsAsync(LocalTestFunction) + ).Throws(); + return; - Task LocalTestFunction() - { - ThrowsArgumentException(); - return Task.CompletedTask; - } - } + Task LocalTestFunction() + { + ThrowsArgumentException(); + return Task.CompletedTask; + } + } } }