title: How to unit test a private list/how to cast an object to a list
body: <pre><code>public class Class1
  { 
      private List&lt;string&gt; list;
      public Class1()
      { 
          list = new List&lt;string&gt;();
      }
      private addSomethingToList(string something)
      {
           // add something to the list
      }
  }
  
  [TestClass]
  public class DoSomethingToListTests
  {
      [TestMethod]
      public void DoSomethingToList_Something()
      {
          string string1 = "something";
          PrivateObject prob = new PrivateObject(new Class1());
          object[] arg = { string1 };
          prob.Invoke("addSomethingToList", string1);
          List&lt;string&gt; expected = new List&lt;string&gt;();
          expected.Add("something");
          object actual = prob.GetField("list");
          CollectionAssert.AreEqual(expected, actual);
      }
  }
  </code></pre>
  
  <p>this gives me</p>
  
  <blockquote>
    <p>Argument 2: cannot convert from 'object' to System.Collections.ICollection'</p>
  </blockquote>
  
  <p>Argument 2 being actual</p>
  
  <p>and</p>
  
  <blockquote>
    <p>The best overloaded method match for 'Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.AreEqual(System.Collections.ICollection, System.Collections.ICollection)' has some invalid arguments</p>
  </blockquote>
  
  <p>The problem is that it is evaluating expected as a List and actual as an object. </p>
  
  <p>Is there a way to make it so actual is a list?</p>
  
  <p>I have tried </p>
  
  <pre><code>List&lt;string/object&gt; actual = prob.GetField("list");
  </code></pre>
  
  <p>But that gives me the error</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'object' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?) </p>
  </blockquote>