We have "Domain" objects in our application that represent an object graph of information that is loaded from a DB. I have been trying to use reflective TypeMock.
For example, say I am trying to mock a Car. I might have the following reference in my code. There are separate classes for Car, Engine, Piston, and PistonHead.
Car.Engine.Pistons[0].PistonHead
IF I "load" a car from the DB, the object graph under it gets loaded. I want to avoid that in tests. So, I not only want to mock the Car, but also have its Engine property return a mockEngine, which then will present a mock Pistons list, etc.
Mock mockCar = MockManager.Mock(typeof(Car));
Mock mockEngine = MockManager.Mock(typeof(Engine));
mockCar.ExpectGetAlways("Engine", mockEngine);
I begain setting this up and immediately got an error:
TypeMock.TypeMockException:
*** No method get_Engine in type MyNamespace.Car returns TypeMock.MockObject`1
How do you mock an object graph if you cannot specify that a mocked object's properties should return other mock objects?
Also, I do not see from the documentation, or in the forums any
Expect... call that would handle an indexed property such as Car.Engine.Pistons[0]. How do you mock that case?