Allow Comparing only a subset of properties.#4925
Conversation
3048943 to
21ba375
Compare
|
Thanks for your patience on this PR too @manfred-brands . I hope to catch up on reviewing this too in the next few days |
750a6bf to
1b96afd
Compare
|
@stevenaw I have converted this back to draft to allow me ironing out the updated syntax/functionality. |
|
This PR adds the following syntax: public XXXConstraint UsingPropertiesComparer(Func<PropertiesComparerConfigurationUntyped, PropertiesComparerConfigurationUntyped> configure)
public XXXConstraint<T> UsingPropertiesComparer(Func<PropertiesComparerConfiguration<T>, PropertiesComparerConfiguration<T>> configure)Where
I'm open to changes in syntax or if more functionality is needed. |
1b96afd to
3bdec8c
Compare
|
Thanks @manfred-brands A few thoughts on naming and other things:
No strong feelings either way on this. I think this naming is clear as a function used to configure the comparer. Another option I'm not sure if we've considered here is to use generics to allow the user to declaratively say the types. // Compares two objects of the same type
UsingPropertiesComparer()
// Compares two objects of different types
UsingPropertiesComparer<T1, T2>()This might also pair more nicely if we ever get type-safety for different generic typing at the assert level (ex:
Would this mean moving away from the user providing a list of prop names they'd want to compare? I like the idea of it "just working" in that we either compare all props or a predefined list without the framework having to decide what the user may or may not intend to compare as "common" properties.
I think we already have a
I'm having a hard time understanding how this would work from the API itself, as well as the need for it. Would one prop get mapped to another only to then use the default comparer for that type? I'm wondering if these functions opens a bit of a slippery slope into effectively making our own AutoMapper. I'm wondering if a first draft here might be simpler if we approach it as "two objects, with the option to do all or a predefined subset of properties" while still allowing NUnit equality rules to take effect. |
A long as NUnit has no coupling between the
At the moment this means The alternative is to explicitly exclude the ID property with
See my comments in #4687 why
For each property, the NUnit rules are in effect. The mapping of value is my own. It seems to fit with my example in the nunit test where a |
|
Ah, you are right, I had missed the mapping request in the original issue. It still rubs me the wrong way a bit not to have
I think cases like this are the core of my questions. I haven't used FluentAssertions and so I'm unfamiliar with how they approached this. Having thought about it a bit more from a few different ways, I think I'd find |
There was a problem hiding this comment.
All tests works. Code looks good.
The new added syntax should also be documented (in the docs).
Using using makes it equal to the other similar usages we have, so I don't mind that.
CompareOnlyCommonProperties or CommonPropertiesOnly makes more sense to me than AllowExtraProperties.
What are the default for the properties?
Converted specific methods to one with a configure func. Add more configuration parameters * Allow comparing different types * Allow comparing only common properties. * Allow mapping property names
3bdec8c to
e15702e
Compare
I will create a PR shortly.
Renamed into
Defaults are as before:
|
|
Thanks for having taken a look at this @OsirisTerje I'll unassign myself as reviewer for now but will still try to review this later when time allows to catch myself up |
|
@OsirisTerje Why is the WIP check hanging? |
|
@manfred-brands No idea. I'll force merge it. |
Fixes #4687
Fixes #4935
Fixes #4244