IsStructurallyEqualTo
Hi,
I'm converting CsCheck over to use TUnit. Good so far and looking forward to the AOT.
I have one issue with assrting arrays have the same values (but can be different collections like the framework generated ones). IsEquivalentTo doesn't check the order by default and is also giving me an error when trying to publish AOT.
error IL2026: Using member 'TUnit.Assertions.Extensions.IsEquivalentToAssertionExtensions.IsEquivalentTo<TCollection, TItem>(IAssertionSource<TCollection>, IEnumerable<TItem>, CollectionOrdering, String, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Collection equivalency uses structural comparison for complex objects, which requires reflection and is not compatible with AOT.
I think I need IsStructurallyEqualTo but I don't think it's implemented. Any other hints for an extension method that can check all the element are the same.
Thanks
For checking collections with ordering, you can use:
await TUnitAssert.That(listA).IsEquivalentTo(listB, CollectionOrdering.Matching);
For AOT structural equivalency, you'll need to supply for own custom comparer. As TUnit doesn't know what it'll be comparing, it has to use reflection. So await TUnitAssert.That(objA).IsEqualTo(objB, CustomComparer);
There's also this for easily creating your own assertions too: https://tunit.dev/docs/assertions/extensibility/source-generator-assertions/#method-level-generation-generateassertion
Thanks. Creating assertions looks good.