-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
It appears that the TryConversionStep is being executed after the Using statements.
Complete minimal example reproducing the issue
[TestMethod]
public void CompareStringToDate()
{
//Arrange
var classA = new ClassA { ThisIsMyDateTime = DateTime.Now };
var classB = new ClassB { ThisIsMyDateTime = classA.ThisIsMyDateTime.ToString() };
//Asserts
classB.Should().BeEquivalentTo(classA,
options => options.ExcludingMissingMembers()
.WithAutoConversion()
.Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1000))
.WhenTypeIs<DateTime>());
}
private class ClassA
{
public DateTime ThisIsMyDateTime { get; set; }
}
private class ClassB
{
public string ThisIsMyDateTime { get; set; }
}Expected behavior:
The conversion from string to DateTime happens before the Using statements.
Actual behavior:
Unit test fails with the following message:
Expected member ThisIsMyDateTime from subject to be a System.DateTime, but found a System.String.
Versions
- Which version of Fluent Assertions are you using?
5.4.1
- Which .NET runtime and version are you targeting?
.NET framework 4.5.2
Additional Information
It looks like the TryConversionStep is placed at the end of the steps collection.