You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a minor issue but tasks being called synchronously with .Wait() will throw AggregateExceptions. This means that certain FluentAssertions methods are throwing AggregateExceptions, when they should only be throwing the inner exception.
I would expect this test to fail, given that the task doesn't throw an AggregateException and instead explicitly just throws an InvalidOperationException.
Actual behavior:
The test passes, because currently certain methods are executing the task synchronously using .Wait(), so if it throws an exception it will wrap it in an AggregateException,
The methods which do this are:
public ExceptionAssertions<TException> Throw<TException>(string because = "", params object[] becauseArgs) where TException : Exception
public void NotThrowAfter(TimeSpan waitTime, TimeSpan pollInterval, string because = "", params object[] becauseArgs)
public void NotThrow(string because = "", params object[] becauseArgs)
public void NotThrow<TException>(string because = "", params object[] becauseArgs) where TException : Exception
Proposal
What I propose is replacing all calls to .Wait(), with .GetAwaiter().GetResult().
This should make sure only the top exception is thrown. If the given task does in fact throw an AggregateException, it will still work in the same way. The only difference is that Fluent Assertions itself does not throw AggregateExceptions internally, unnecessarily.
This would require changing 2 tests which, like the one shown above, expect an AggregateException to be thrown with an inner exception. The tests would be modified so the given tasks explicitly throws an AggregateException.
The text was updated successfully, but these errors were encountered:
Resolved in PR #1038
Description
This is a minor issue but tasks being called synchronously with .Wait() will throw AggregateExceptions. This means that certain FluentAssertions methods are throwing AggregateExceptions, when they should only be throwing the inner exception.
Example
Take the following test case:
E.g.
Expected behavior:
I would expect this test to fail, given that the task doesn't throw an AggregateException and instead explicitly just throws an InvalidOperationException.
Actual behavior:
The test passes, because currently certain methods are executing the task synchronously using .Wait(), so if it throws an exception it will wrap it in an AggregateException,
The methods which do this are:
public ExceptionAssertions<TException> Throw<TException>(string because = "", params object[] becauseArgs) where TException : Exception
public void NotThrowAfter(TimeSpan waitTime, TimeSpan pollInterval, string because = "", params object[] becauseArgs)
public void NotThrow(string because = "", params object[] becauseArgs)
public void NotThrow<TException>(string because = "", params object[] becauseArgs) where TException : Exception
Proposal
What I propose is replacing all calls to .Wait(), with .GetAwaiter().GetResult().
This should make sure only the top exception is thrown. If the given task does in fact throw an AggregateException, it will still work in the same way. The only difference is that Fluent Assertions itself does not throw AggregateExceptions internally, unnecessarily.
This would require changing 2 tests which, like the one shown above, expect an AggregateException to be thrown with an inner exception. The tests would be modified so the given tasks explicitly throws an AggregateException.
The text was updated successfully, but these errors were encountered: