Having the following COM interop class
[ClassInterface(ClassInterfaceType.None)]
[Guid("86332C4E-0BDE-46EC-94C5-0A946C33C682")]
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
public class MyComObjectClass : IMyComObject, MyComObject
{
public MyComObjectClass();
[DispId(1)]
public virtual string Echo(string message);
}
and the sample class that uses it:
public class MyComObjectClassProxy
{
public string Echo(string message)
{
IMyComObject itf = null;
try
{
itf = new MyComObjectClass();
return itf.Echo(message);
}
finally
{
if (itf != null)
{
Marshal.ReleaseComObject(itf);
}
}
}
}
When I try to call the arranged constructor I am getting an error "Cannot create instances of type requiring managed activation", the unit test code:
[TestMethod]
public void TestMethod1()
{
var mock = Mock.Create<MyComObjectClass>();
Mock.Arrange(() => new MyComObjectClass()).Returns(mock);
var sut = new MyComObjectClassProxy();
var actual = sut.Echo("Message");
Assert.AreEqual(string.Empty, actual);
}