Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from nunit:main #269

Merged
merged 1 commit into from
Dec 24, 2024
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
@@ -1,6 +1,7 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Threading.Tasks;
using NUnit.Framework.Internal;

namespace NUnit.Framework.Constraints
Expand Down Expand Up @@ -42,6 +43,14 @@ public override ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> d
return ApplyTo((Delegate)del);
}

/// <inheritdoc/>
public override async Task<ConstraintResult> ApplyToAsync<TActual>(Func<Task<TActual>> actual)
{
var exception = await ExceptionHelper.RecordExceptionAsync(actual, nameof(actual));

return new ThrowsExceptionConstraintResult(this, exception);
}

#region Nested Result Class

private class ThrowsExceptionConstraintResult : ConstraintResult
Expand Down
12 changes: 12 additions & 0 deletions src/NUnitFramework/tests/Assertions/AssertThatAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ await Assert.ThatAsync(() => Task.FromCanceled(cancel.Token),
.With.Property(nameof(TaskCanceledException.CancellationToken)).EqualTo(cancel.Token));
}

[Test]
public async Task AssertionPasses_FaultedDelegate_ThrowsAnyException()
{
await Assert.ThatAsync(() => throw new Exception("Ugh"), Throws.Exception);
}

[Test]
public async Task AssertionPasses_FaultedTask_ThrowsAnyException()
{
await Assert.ThatAsync(() => Task.FromException(new Exception("Ugh")), Throws.Exception);
}

[Test]
public async Task AssertionPasses_FaultedTask_ThrowsMatchingException()
{
Expand Down
Loading