这是要检查执行的MyMethod虚方法在抽象的MyAbstractClass:
It is necessary to check implementation of 'MyMethod' virtual method in the abstract 'MyAbstractClass':
public abstract MyAbstractClass
{
public void MyMethod()
{
Testpassed = true;
}
public abstract int StatusCode{get;internal set;} // **EDIT**: internal setter was added
public bool TestPassed{get;private set;}
}
我试着做到以下几点:
I've tried to do the following:
[TestMethod()]
{
Mock<MyAbstractClass> mockClass = new Mock<MyAbstractClass>();
mockClass.Object.MyMethod();
Assert.IsTrue(mockClass.Object.TestPassed);
}
在试图执行的MyMethod会生成以下错误:
on attempt to execute 'MyMethod' the following error is generated:
法类型'set_Status code' MyAbstractClass`2Proxy0434d60c0f4542fb9b4667ead4ca3a18 从程序集DynamicProxyGenAssembly2, 版本= 0.0.0.0,文化=中性公钥=空'不具有 实施..
Method 'set_StatusCode' in type 'MyAbstractClass`2Proxy0434d60c0f4542fb9b4667ead4ca3a18' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation..
请指教,我怎么能得到解决这个问题?
Please advise, how could I get the problem resolved?
非常感谢!
P.S。其实,我可以继承MyAbstractClass并提供实现'状态code'的属性,但我必须要实现的一堆属性...
P.S. Actually, I could inherit from MyAbstractClass and provide implementation for 'StatusCode' property, but I have a bunch of properties to be implemented...
推荐答案
请参阅this回答有关部分的嘲讽,我认为你必须提供一个具体的实现。
See this answer about partial mocking and I think you'll have to provide a concrete implementation.
相关推荐
最新文章