Hi
Unfortunately you can not mock private inner class directly. :(
There is however workaround by using reflection.
Here is how you can do it:
[TestMethod()]
public void StartTest()
{
MockManager.Init();
Car target = new Car();
new ReflectionPermission(PermissionState.Unrestricted).Demand();
Type t = typeof(Car).Assembly.GetType("Car+Engine", true);
Mock mock = MockManager.MockAll(t);
mock.ExpectAndReturn("Start", false);
bool expected = false;
bool actual;
actual = target.Start();
Assert.AreEqual(expected, actual, "Test Failed");
MockManager.Verify();
}
Note the strange line
Type t = typeof(Car).Assembly.GetType("Car+Engine", true);
This is the way you can reach your inner class using reflection
Another thing to notice is that if the Car class is inside a namespace
the code should be:
Type t = typeof(YourNameSpace.Car).Assembly.GetType("YourNameSpace.Car+Engine", true);
One last thing.
To see the types names inside the assembly use:
Type t = typeof(Car).Assembly.GetType("Car+Engine", true);
Type []tArr = t.Assembly.GetTypes();
You Then can look in the debugger at tArr for the names inside the assembly.
Hope it helps.