1

I am wondering if there is a way to modify asserting value in the config.

For example, I have the following assertion

customer.Should().Be(c, config => config.Excluding(c => c.Updated));
customer.Updated.Should().Be(c.Updated.ToString());

Is there any way to have conversion to string as part of the assertion instead of a separate assertion.

Something like this

customer.Should().Be(c, config => config.SomeFunction(c => c.Updated.ToString()))
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Alex
  • 53
  • 4

1 Answers1

1

According to the documentation here

Object graph comparison: Auto-Conversion

You should be able to instruct the assertion to

attempt to convert the value of a property of the subject-under-test to the type of the corresponding property on the expectation

customer.Should().BeEquivalentTo(c, options => options
    .WithAutoConversionFor(x => x.Path.Contains("Updated")));

or

customer.Should().BeEquivalentTo(c, options => options.WithAutoConversion());
Nkosi
  • 235,767
  • 35
  • 427
  • 472