【发布时间】:2014-05-22 18:32:31
【问题描述】:
我是整个 MOQ 运动的新手......顺便说一句,这很酷......我现在正在嘲笑各种东西......
无论如何,我遇到了这种情况,想知道如何模拟它。
我有一个类实现了我想模拟的接口:
public interface ImyInterface
{
void doit();
}
public abstract class myBase<TChannel> : ICommunicationObject, IDisposable where TChannel : class
{
protected TChannel Channel { get; private set; }
// ICommunicationObject implementation not shown
}
public class myIIntClass : myBase<ImyInterface>, ImyInterface
{
public myIIntClass()
{
}
public void doit()
{
Channel.doit();
}
}
我认为我的最小起订量测试并没有模拟任何东西......但我不确定并希望对如何正确编写它或重构我的课程有所了解:
这是我目前的最小起订量测试:
MyClass myClass = null;
Mock<ImyInterface> moq = new Mock<ImyInterface>();
moq.Setup(x => x.doit());
myClass = (MyClass)moq.Object;
myClass.doit();
moq.VerifyAll();
感谢一位 moqer 到另一位... :-)
【问题讨论】: