I have two classes like this (in the actual project):
namespace app {
internal class A {
}
internal class B {
private List<A> list;
private void SomeMethodToTest() {
list = new List<A>() { new A() };
}
}
The I have my Unit test looking something like
[TestClass()]
public class ATest {
[TestMethod()]
public void TestSomeMethod() {
B_Accessor b = new B_Accessor();
b.SomeMethodToTest();
Assert.AreEqual(1, b.list.Count); // ERROR ON THIS LINE
}
}
On the marked line I get an InvalidCastException saying something like "unable to cast object of type System.Collections.Generic.List'1[app.A] to type System.Collections.Generic.List'1[app.A_Accessor]
The problem is that, because A is internal, the auto-generated class B_Accessor looks like
[Shadowing("app.B")]
public class B_Accessor : BaseShadow {
... stuff ...
[Shadowing("list")]
public List<A_Accessor> list { get; set; }
... stuff ...
}
Note that, in the Accessor class, the list is of type List<A_Accessor> and not List<A>. I have specified the InternalsVisibleTo attribute on the application, so the test project can access the type A, but for some reason VS replaces it with the accessor type, which makes the type incompatible with the wrapped type.
How can I work around this other than making A public?