title: How can I create unit tests involving collections in c#?
body: <p>I have a number of methods in C# which return various collections which I wish to test. I would like to use as few test APIs as possible - performance is not important. A typical example is:</p>
  
  <pre><code>HashSet&lt;string&gt; actualSet = MyCreateSet();
  string[] expectedArray = new string[]{"a", "c", "b"};
  MyAssertAreEqual(expectedArray, actualSet);
  </code></pre>
  
  <p>//...</p>
  
  <pre><code>void MyAssertAreEqual(string[] expected, HashSet&lt;string&gt; actual)
  {
      HashSet&lt;string&gt; expectedSet = new HashSet&lt;string&gt;();
      foreach {string e in expected)
      {
          expectedSet.Add(e);
      }
      Assert.IsTrue(expectedSet.Equals(actualSet));
  }
  </code></pre>
  
  <p>I am having to write a number of signatures according to whether the collections are arrays, Lists, ICollections, etc. Are there transformations which simplify this (e.g. for converting an array to a Set?).</p>
  
  <p>I also need to do this for my own classes. I have implemented HashCode and Equals for them. They are (mainly) subclassed from (say) MySuperClass. Is it possible to implement the functionality:</p>
  
  <pre><code>void MyAssertAreEqual(IEnumerable&lt;MySuperClass&gt; expected, 
                        IEnumerable&lt;MySuperClass&gt; actual); 
  </code></pre>
  
  <p>such that I can call:</p>
  
  <pre><code>IEnumerable&lt;MyClassA&gt; expected = ...;
  IEnumerable&lt;MyClassA&gt; actual = ...; 
  MyAssertAreEqual(expected, actual); 
  </code></pre>
  
  <p>rather than writing this for every class</p>