-
Notifications
You must be signed in to change notification settings - Fork 731
Description
Description
It is found that the variable names will not be included in the assertion message when the assertion comes after the await assertion such as NotThrowAsync() and CompleteWithinAsync().
Complete minimal example reproducing the issue
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Extensions;
namespace MyUnitTests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task RunAsyncAssertion()
{
// Arrange and Act
string someText = "Hello";
Func<Task> myTask = () => Task.Delay(1.Seconds());
// Assert
await myTask.Should().CompleteWithinAsync(2.Seconds());
someText.Should().Be("Hi");
}
}
}Expected behavior:
Assertion failure should be something like Expected someText to be "Hi" with a length of 2, but "Hello" has a length of 5, differs near "ell" (index 1).
Actual behavior:
Expected string to be "Hi" with a length of 2, but "Hello" has a length of 5, differs near "ell" (index 1).
Note that string is displayed instead of the variable name someText.
This is not caused by the await keyword used. If the Fluent async assertion is not used, the variable name can be displayed correctly. Example:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Extensions;
namespace MyUnitTests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task RunAsyncAssertion()
{
// Arrange and Act
string someText = "Hello";
Func<Task> myTask = () => Task.Delay(1.Seconds());
// Assert
await myTask.Invoke();
someText.Should().Be("Hi");
}
}
}Result:
Expected someText to be "Hi" with a length of 2, but "Hello" has a length of 5, differs near "ell" (index 1).
Versions
- Fluent Assertions 6.2.0
- .NET framework 4.7.2
Additional Information
This is my first time submitting an issue on GitHub. Hope it's alright. 😅