-
Hi I want to test the correct mapping from a DTO to the "real" object. Now I have following situation: As I read, this behavior is expected from AutoMapper. But unfortunatley I can not override the config. Is it possible somehow to treat this expected.Should().BeEquivalentTo(actual, options => options
.ExcludingMissingMembers()
.WithAutoConversion()
); The fail message: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Have you tried https://fluentassertions.com/objectgraphs/#equivalency-comparison-behavior? |
Beta Was this translation helpful? Give feedback.
-
Here's an example using the linked documentation, which considers null and empty var subject = new { Value = (byte)null };
var expected = new { Value = new byte[0] };
subject.Should().BeEquivalentTo(expected, opt => opt
.Using<byte[]>(ctx =>
{
if (ctx.Subject is null or { Length: 0 } && ctx.Expectation is null or { Length: 0 })
{
return;
}
ctx.Subject.Should().BeEquivalentTo(ctx.Expectation);
})
.WhenTypeIs<byte[]>()
); |
Beta Was this translation helpful? Give feedback.
-
This was very helpful 👍 Thank you both for your great support! Just realized you could not have multiple answers as accepted answer. Please feel like I have marked both :) |
Beta Was this translation helpful? Give feedback.
Here's an example using the linked documentation, which considers null and empty
byte[]
to be equivalent.