I'm testing an application that interacts with Microsoft Excel. When using WhenCalled on a mock object that I'm returning an Excel Range from, the calls fails. The exact failure depends upon whether I use WillReturn (TypeMockException: Can not fake methods defined in mscorlib, try faking the defining type) or DoInstead (TypeMockException: Cannot return System.__ComObject value from method that returns Microsoft.Office.Interop.Excel.Range). I'm currently using TypeMock 22.214.171.124. This test previously worked in 6.0.8.
Essentially, I have an interface like:
public interface ISomeInterface
And my test code does:
var mockObject = Isolate.Fake.Instance<ISomeInterface>();
Microsoft.Office.Interop.Excel.Range range = excelWorksheet.UsedRange;
Isolate.WhenCalled(() => mockObject.GetRange()).WillReturn(range);
Isolate.WhenCalled(() => mockObject.GetRange()).DoInstead(context => range);
When using WillReturn, the TypeMockException is thrown when executing the mocking statement. When using DoInstead, the TypeMockException is thrown when the test code actually executes the GetRange method.
Is there some way to actually return the COM object (the Excel Range)?