Skip to content

TryConversionStep executing after Using statements #876

@mwasson74

Description

@mwasson74

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.

https://github.com/fluentassertions/fluentassertions/blob/41c5e9b8a13d53794a8efe47e903c66f0c13f53e/Src/FluentAssertions/Equivalency/SelfReferenceEquivalencyAssertionOptions.cs#L129

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions