Hi Vagif,
In both tests, you are using expectations on a future mock. That means that the expectation will be on the next generated object.
In the first case, you set the expectation on an already created object. That's the object you created prior to the recording block. The call is made on that object, hence the test passes.
In the second test, you set an expectation on that same object, but the actually happens on the object created in the static method. Hence the difference. By adding the constructor line into the recording block, you make sure that you mock the next created object, which is in the static method.
Here's the final test code that works:
[TestMethod]
[VerifyMocks]
public void MyType_Parsed()
{
using (RecordExpectations recorder = new RecordExpectations())
{
MyType mockedType = new MyType();
recorder.ExpectAndReturn(mockedType.MyField, "abc").RepeatAlways();
}
MyType ReturnedType = MyType.Parse("xyz");
Assert.AreEqual("abc", ReturnedType.MyField);
}
Also, there's a short tutorial on this very subject here (lesson 4):
https://www.typemock.com/Multimedia.html