Open jnyrup opened 4 years ago
The question is if we want to expose
IEquivalencyValidationContext
.
It already is exposed since it's part of the IEquivalencyStep
interface.
Action act = () => subject.Should().BeEquivalentTo(expectation, options => options .Using<int, string>(ctx => ctx.Subject.ToString().Should().Be(ctx.Expectation)) .WhenTypesAre<int, string>());
I think we should consider dropping the WhenTypeIs/Are
construct alltogether, so
Action act = () => subject.Should().BeEquivalentTo(expectation, options => options
.Using<int, string>(ctx => ctx.Subject.ToString().Should().Be(ctx.Expectation)));
It already is exposed since it's part of the
IEquivalencyStep
interface.
Ohh, I meant exposing the entire IEquivalencyValidationContext
interface in the When
method.
I think we should consider dropping the WhenTypeIs/Are construct alltogether
Hmm...
That would drop support for restricting the matching of properties via SelectedMemberPath
and SelectedMemberInfo
.
Ohh, I meant exposing the entire
IEquivalencyValidationContext
interface in theWhen
method.
I would not expose anything that we really need to expose. That keeps the maintainability focus in check.
That would drop support for restricting the matching of properties via SelectedMemberPath and SelectedMemberInfo.
Since the Using
call happens nested inside a Should().BeEquivalentTo()
call, calling Using<T>
or Using<TS, TE>
could apply an implicit When
restricting to the types involved. We can still support an additional chained When
that overrides/extends this expression.
Seems to work out quite well with an implicit conversion from Restriction
to TSelf
👍
One case I haven't figured out how we should handle:
When Expectation
is null, the RuntimeType
falls back to CompileTimeType
.
For Subject
we can't do the same, as we do not store its CompileTimeType
.
That has the implication that we cannot distinguish null
s, i.e. if the Subject
was a (string)null
or (int?)null
.
var subject = new
{
Property = (int?)null
};
var expectation = new
{
Property = ""
};
subject.Should().BeEquivalentTo(expectation, opt => opt
.Using<string, string>(ctx => ...));
That has the implication that we cannot distinguish
null
s, i.e. if theSubject
was a(string)null
or(int?)null
.
I don't get the problem.
When comparing two object graphs using
BeEquivalentTo
the equivalency of identically named and typed properties can be overridden using theUsing<T>
+WhenTypeIs<T>
combo.I'd like to propose a more generalized version,
WhenTypesAre<TSubject, TExpectation>
that can be applied when the subject and expectation are of different types. This is useful when e.g. a class and its DTO equivalent have differently typed properties.My current toy example is:
My current prototype has the following relevant API changes
It uses
IEquivalencyValidationContext
overIMemberInfo
to get access to get the runtime type ofIEquivalencyValidationContext.Expectation
.As
IEquivalencyValidationContext
implementsIMemberInfo
this change should not give any compile time breakage. The question is if we want to exposeIEquivalencyValidationContext
.