Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying [AutoFixture] SemanticComparison OfLikeness to sequences / collections / arrays / IEnumerable
    primarykey
    data
    text
    <p>We have written a test which looks like the following. This test requires that we have created en <code>Equal</code>-overload for the <code>CodeTableItem</code>-class:</p> <pre><code>ICollection&lt;CodeTableItem&gt; expectedValutaList = new List&lt;CodeTableItem&gt;(); expectedValutaList.Add(new CodeTableItem("DKK", "DKK")); expectedValutaList.Add(new CodeTableItem("EUR", "EUR")); RepoDac target = new RepoDac(); var actual = target.GetValutaKd(); CollectionAssert.AreEqual(expectedValutaList.ToList(),actual.ToList()); </code></pre> <p>The test works fine, but has the unfortunate dependency to the <code>Equality</code>-function, meaning if I extend the <code>CodeTableItem</code>-class with one more field, and forgets to extend the <code>Equals</code>-function, the unit test still runs green, although we do not test for all fields. We want to avoid this <code>Equality</code> pollution (see <a href="http://xunitpatterns.com/test-specific%20equality.html" rel="noreferrer">Test Specific Equality</a>), which has been written only to conform to the test.</p> <p>We have tried using <code>OfLikeness</code>, and have rewritten the test in this way:</p> <pre><code>ICollection&lt;CodeTableItem&gt; expectedValutaList = new List&lt;CodeTableItem&gt;(); expectedValutaList.Add(new CodeTableItem("DKK", "DKK")); expectedValutaList.Add(new CodeTableItem("EUR", "EUR")); var expectedValutaListWithLikeness = expectedValutaList.AsSource().OfLikeness&lt;List&lt;CodeTableItem&gt;&gt;(); RepoDac target = new RepoDac(); ICollection&lt;CodeTableItem&gt; actual; actual = target.GetValutaKd(); expectedValutaListWithLikeness.ShouldEqual(actual.ToList()); </code></pre> <p>But the test fails because the <code>Capacity</code> is not equal. I have written code that runs through reflection many times, and typically ended up implementing overloads for ignoring fields. Is there a way to ignore certain fields with the <code>OfLikeness</code> or <code>ShouldEqual</code>? Or is there some other way of solving this issue?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload