1

Given a class, and a class I want to map to:

public class A
{
    public string Prop1 { get; set; }
    public string Prop2 { get; set; }
}
public class B
{
    public string Prop1 { get; set; }
    public string Prop2 { get; set; }
    public string Prop3 { get; set; }
}

When I assert the result of the mapping, I'd want FluentAssertions to fail and warn me that 'Prop3' exists on B (the result), but not A.

But this won't happen if I use what seems to be the standard approach of using the result first:

b.Should().BeEquivalentTo(a); //passes because Prop3 is null, which doesn't exist on A

However if I flip the result and expectation around, I get the exact failure I'm after:

a.Should().BeEquivalentTo(b); //fails because of Prop3

I can't find any docs which use this ordering though. Is it an expected approach for those who have similar requirements, or is it hacking the library to get it to work how I want it?

FBryant87
  • 4,273
  • 2
  • 44
  • 72
  • 1
    The expectation is that all the public properties of the right-hand side of the `Should()` match ones in the left-hand side of the `Should()`. In your example, `b.Should().BeEquivalentTo(a)` says that you could use `b` to fulfil the required properties in `a`. So from that point of view, this is correct. The requirements are on the right of the `Should()` and the actual value is on the left. – Matthew Watson Oct 13 '22 at 15:02
  • 1
    I suppose a better name would have been something like `BeAbleToSupplyTheDataFor()` but that's a bit long :) – Matthew Watson Oct 13 '22 at 15:20

0 Answers0