module Expect
let equalStructural subject expected message =
let rec inner (refCounter: ObjectIdGenerator from System Serialization) (name, subjectProperty, expectedProperty) =
match refCounter.getIdOf item with
| false, newId when isPrimitive subjectProperty ->
equal subjectProperty expectedProperty (sprintf "Property '%s' is has value '%A' but was '%A'" name subjectProperty actualProperty)
| false, _ ->
inner refCounter (name, ...)
| true, _ ->
// cyclic ref
()
let idGen = ObjectIdGenerator()
propsOf subject
|> sort
|> zipWith (propsOf actual)
// Also check for difference of structure
|> iter (fun (ps, pa) -> inner idGen (ps.Name, ps.Value, pa.Value)
Feature; support structural equality for C# objects. On the wish-list from
https://twitter.com/ursenzler/status/1277354370229850113
Implementation, something like:
Or even better https://github.com/eiriktsarpalis/TypeShape/blob/master/samples/TypeShape.Samples/equality-comparer.fs — internalised