Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<Pending>")]
[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();
Expand All @@ -49,5 +49,23 @@ 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<OverflowException>(LocalTestFunction)
).Throws<AssertionException>();
return;

Task LocalTestFunction()
{
ThrowsArgumentException();
return Task.CompletedTask;
}
}
}
}
4 changes: 2 additions & 2 deletions TUnit.Assertions/Assertions/Throws/ThrowsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class ThrowsExtensions
public static ThrowsException<object?, Exception> Throws(this IDelegateSource delegateSource, Type type, [CallerArgumentExpression("type")] string? doNotPopulateThisValue = null)
{
return new ThrowsException<object?, Exception>(
delegateSource.RegisterAssertion(new ThrowsOfTypeAssertCondition<object?, Exception>(), [doNotPopulateThisValue]),
delegateSource.RegisterAssertion(new ThrowsOfTypeAssertCondition(type), [doNotPopulateThisValue]),
delegateSource,
e => e);
}
Expand Down Expand Up @@ -82,4 +82,4 @@ public static ThrowsException<TActual, TException> WithParameterName<TActual, TE
throwsException.RegisterAssertion((selector) => new ThrowsWithParamNameAssertCondition<TActual, TException>(expected, StringComparison.Ordinal, ex => selector(ex) as ArgumentException), [doNotPopulateThisValue]);
return throwsException;
}
}
}
Loading