Variable name is not displayed after await assertion
See original GitHub issueDescription
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. 😅
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (8 by maintainers)
Top GitHub Comments
@jnyrup I’d love to create a PR for it! Also, thanks for the suggestions.
No, it should be compiled in debug mode. So that confirms it’s an actual bug in FA.