Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
7 changes: 5 additions & 2 deletions 7 Src/FluentAssertions/Specialized/AsyncFunctionAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ public async Task<ExceptionAssertions<TException>> ThrowExactlyAsync<TException>
{
Exception exception = await InvokeWithInterceptionAsync(Subject);

Execute.Assertion
success = Execute.Assertion
.ForCondition(exception is not null)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {0}{reason}, but no exception was thrown.", expectedType);

exception.Should().BeOfType(expectedType, because, becauseArgs);
if (success)
{
exception.Should().BeOfType(expectedType, because, becauseArgs);
}

return new ExceptionAssertions<TException>(new[] { exception as TException });
}
Expand Down
7 changes: 5 additions & 2 deletions 7 Src/FluentAssertions/Specialized/DelegateAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ public ExceptionAssertions<TException> ThrowExactly<TException>(string because =

Type expectedType = typeof(TException);

Execute.Assertion
success = Execute.Assertion
.ForCondition(exception is not null)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {0}{reason}, but no exception was thrown.", expectedType);

exception.Should().BeOfType(expectedType, because, becauseArgs);
if (success)
Comment thread
IT-VBFK marked this conversation as resolved.
{
exception.Should().BeOfType(expectedType, because, becauseArgs);
}

return new ExceptionAssertions<TException>(new[] { exception as TException });
}
Expand Down
20 changes: 20 additions & 0 deletions 20 Tests/FluentAssertions.Specs/Specialized/DelegateAssertionSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using FluentAssertions.Execution;
using FluentAssertions.Specialized;
using Xunit;

Expand Down Expand Up @@ -34,4 +36,22 @@ public void When_injecting_a_null_clock_it_should_throw()
act.Should().ThrowExactly<ArgumentNullException>()
.WithParameterName("clock");
}

public class ThrowExactly
{
[Fact]
public void Does_not_continue_assertion_on_exact_exception_type()
{
// Arrange
var a = () => { };

// Act
using var scope = new AssertionScope();
a.Should().ThrowExactly<InvalidOperationException>();

// Assert
scope.Discard().Should().ContainSingle()
.Which.Should().Match("*InvalidOperationException*no exception*");
}
}
}
19 changes: 19 additions & 0 deletions 19 Tests/FluentAssertions.Specs/Specialized/TaskAssertionSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using FluentAssertions.Execution;
using FluentAssertions.Extensions;
using FluentAssertions.Specialized;
using Xunit;
using Xunit.Sdk;
using static FluentAssertions.FluentActions;
Expand Down Expand Up @@ -505,6 +506,24 @@ await action.Should().ThrowAsync<XunitException>().WithMessage(
}
}

public class ThrowExactlyAsync
{
[Fact]
public async Task Does_not_continue_assertion_on_exact_exception_type()
{
// Arrange
var a = () => Task.Delay(1);

// Act
using var scope = new AssertionScope();
await a.Should().ThrowExactlyAsync<InvalidOperationException>();

// Assert
scope.Discard().Should().ContainSingle()
.Which.Should().Match("*InvalidOperationException*no exception*");
}
}

[Collection("UIFacts")]
public class CompleteWithinAsyncUIFacts
{
Expand Down
2 changes: 2 additions & 0 deletions 2 docs/_pages/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ sidebar:
* Capitalize `true` and `false` in failure messages and make them formattable to a custom `BooleanFormatter` - [#2390](https://github.com/fluentassertions/fluentassertions/pull/2390), [#2393](https://github.com/fluentassertions/fluentassertions/pull/2393)
* Improved the failure message for `NotBeOfType` when wrapped in an `AssertionScope` and the subject is null - [#2399](https://github.com/fluentassertions/fluentassertions/pull/2399)
* Improved the failure message for `BeWritable`/`BeReadable` when wrapped in an `AssertionScope` and the subject is read-only/write-only - [#2399](https://github.com/fluentassertions/fluentassertions/pull/2399)
* Improved the failure message for `ThrowExactly[Async]` when wrapped in an `AssertionScope` and no exception is thrown - [#2398](https://github.com/fluentassertions/fluentassertions/pull/2398)


### Breaking Changes (for users)
* Moved support for `DataSet`, `DataTable`, `DataRow` and `DataColumn` into a new package `FluentAssertions.DataSet` - [#2267](https://github.com/fluentassertions/fluentassertions/pull/2267)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.