-
Notifications
You must be signed in to change notification settings - Fork 728
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationfeature
Description
Background and motivation
When comparing a subject to its expectation via .BeEquivalentTo, the comparion may fail because two properties might have a different representation of the same value; for instance a Guid and a string. To allow the comparison to proceed, passing a pair of lambdas that would perform a round trip conversion would be a possible solution, as in what follows:
[Fact]
public void MessagesAreEquivalent()
{
var poco = new PocoContract { Id = Guid.NewGuid(), Amount = 123.45M, Currency = "EUR" };
var proto = new ProtobufContract { Id = poco.Id.ToString(), Amount = 123.45f, Currency = "EUR" };
poco.Should().BeEquivalentTo(proto, static options => options
.WithAutoConversion<Guid, string>(g => g.ToString(), s => Guid.Parse(s)));
proto.Should().BeEquivalentTo(poco, static options => options
.WithAutoConversion<string, Guid>(s => Guid.Parse(s) , g => g.ToString()));
}See #2672 for a comprehensive discussion.
Alternative Concerns
Instead of overloading .WithAutoConversion offering a .WithConversion might even be more explicit.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationfeature