Hi
The problem here is that you are using RecorderManager.CreateMockedObject.
The call creates an instance of class A and mock the instance in one call.
Than in your code outside the recording block you create another instace
which is not mocked.
What you want to do here is mock a future instance.
try:
using (RecordExpectations rec = RecorderManager.StartRecording())
{
A a = new A(); //This will mock future instance
string temp = a.B;
rec.FailWhenCalled();
}
:idea: Usually you will use RecorderManager.CreateMockedObject outside
the recording block. This usfull when you have interfaces or abstract classes you need to mock.
:idea: The difference between Mocking future instance (as in the code above) and mocking current instance (as in the code you posted) confuses many.
I think that
this post in our blog should clear things up.
Hope it helps. Please tell me if you have more questions.