Hi
The problem here seems to be that MockManager.Mock mocks the next creation of an instance (in other words next time you call new MyClass())
so when you call:
factory.ExpectAndReturn("Create", sayer.MockedInstance as A);
sayer.MockedInstance is null. It will have a value once you The Factory.Create method will create an instace of Sayer.
The solution is to create MockObject of sayer.
MockManger.MockObject method will create an instance and mock it so you
can use the instance as a return value or pass it as a parameter for a method.
Try this:
MockObject sayer = MockManager.MockObject(typeof (Sayer));
Mock factory = MockManager.Mock(typeof(Factory));
factory.ExpectAndReturn("Create", sayer.MockedInstance);
sayer.ExpectCall("SayA");
ClassUnderTest cut = new ClassUnderTest();
cut.MethodUnderTest();
MockManager.Verify();
:arrow: You can read
this article for more in depth explenation about this issue.