Try the code below all in the same .cs source file. By having all the code in the test assembly we eliminate from the equation the "internal members" not being visible in the test assembly for the purpose of this code example:
namespace TestProject1
{
internal class MyItem
{
public MyItem(){}
}
internal class ClassToMock
{
public IList<MyItem> TheMyItemList { get; private set; }
public IList<string> TheStringList { get; private set; }
}
internal class ClassUnderTest
{
public bool DoSomethingWithMyItemList(ClassToMock param)
{
return param.TheMyItemList.Count > 0;
}
public bool DoSomethingWithStringList(ClassToMock param)
{
return param.TheStringList.Count > 0;
}
}
[TestClass]
public class GenericsRecursiveFakeTest
{
[TestMethod]
[Isolated]
public void TestRecursiveFakeOnMyItemList()
{
ClassToMock fake = Isolate.Fake.Instance<ClassToMock>();
ClassUnderTest target = new ClassUnderTest();
Assert.IsFalse(target.DoSomethingWithMyItemList(fake));
}
[TestMethod]
[Isolated]
public void TestRecursiveFakeOnStringList()
{
ClassToMock fake = Isolate.Fake.Instance<ClassToMock>();
ClassUnderTest target = new ClassUnderTest();
Assert.IsFalse(target.DoSomethingWithStringList(fake));
}
}
}
In theory both tests should pass but
TestRecursiveFakeOnMyItemList() fails because
TheMyItemList returns null in
return param.TheMyItemList.Count > 0;.
Now if I make MyItem
public instead of
internal, the test that was failing will pass!
I fail to see the logic of this... is it a bug in Typemock?