我在这种情况下嘲笑:
class A
{
public IB B {get; set;}
}
interface IB
{
//methods
}
class B : IB
{
//IB methods
}
public SimpleMockTest()
{
var mockIB = new Mock<IB>();
var a = new A{B=mockIB.Object};
//do stuff with A, then verify methods on IB were called
}
public TheKindOfTestIWantToDo()
{
var actualB = new B();
var mockIB = new Mock<IB>();
var splitter = new Splitter<IB>(actualB, mockIB.Object); //I need something like this
var a = new A{B=splitter};
//do stuff with A, methods invoked on splitter IB get passed to both supplied instances
//of IB (actualB, and the mockIB). Allowing me to verify the calls as well as have the methods invoked on the actual B object.
//OR:
var mockIB2 = new Mock<IB>(actualB); //behaviour is dictated by the actual, but allows verification
var a2 = new A{B=mockIB2.Object};
}
所以我追求某种代理工厂,它通常支持一个接口并在多个接口上调用相同的方法。当然,当一个方法返回一个值时,每个方法都需要返回相同的值,或者可能需要先入为主。
我想在测试期间有效地窥探接口调用,但没有模拟是行尾。
如果有任何区别,我正在使用最小起订量。