[Feature Request] Graph comparison to handle objects that expose their data through user-defined conversion instead of fields/properties
See original GitHub issueDescription
Currently, Should().BeEquivalentTo()
does not look at private members.
I happen to work in a codebase where most types have been encapsulated in the following fashion:
record PositiveInteger
{
readonly int _encapsulated;
PositiveInteger(int encapsulated)
{
if (encapsulated <0)
throw new ObjectIntegrityException("A PositiveInteger cannot encapsulate a negative number.");
_encapsulated = encapsulated;
}
public static PositiveInteger CreateFromInteger(int i)
{
return new PositiveInteger(i);
}
// how the data is "publicly exposed": passing a PositiveInteger where an int is expected, works!
public static implicit operator int(PositiveInteger positiveInteger)
{
return positiveInteger._encapsulated;
}
}
As you can see, the int
version of the data is “exposed” not through a field or property, but through a user-defined conversion.
However, because the graph does not look at any private member, it will find that PositiveInteger.CreateFromInteger(1)
is in fact equivalent to PositiveInteger.CreateFromInteger(2)
.
It would be cool to have a way to handle this use case.
Simple repository for reproduction : link
On top of my head, an option such as options => options.IncludePrivateFieldsForObjectsWhose[Namespace/FullName]Matches("regex")
may be a good candidate.
Versions
- fluentassertions v6.7.0
- dotnet 6
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Unable to update the specified properties for on-premises ...
Error executing request. An Azure Active Directory call was made to keep object in sync between Azure Active Directory and Exchange Online.
Read more >event resource type - Microsoft Graph v1.0
Identifies the version of the event object. Every time the event is changed, ChangeKey changes as well.
Read more >Exposing a parameter | Substance 3D Designer
Exposing is the process of making a parameter available for use outside of your current Graph View. When building a Graph, you usually...
Read more >Essential Chart Types for Data Visualization
In this article, we'll provide an overview of essential chart types that you'll see most frequently offered by visualization tools. With these charts,...
Read more >Query (Feature Service/Layer)—ArcGIS REST APIs
The query operation returns either a feature set, an array of feature IDs, and/or a result extent.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to make it work.
Leaving this for future readers: custom record collections for native deep equals when using
ComparingRecordsByValue
(with tests)I had to ask ^^
Thank you for your time and answer!
I will see with the other options left. Maybe some kind of custom collection such as