我嘲笑在這種情況:接口分流
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};
}
所以我某種代理工廠,將genericly支持的接口,並調用相同的方法在多個接口上之後。當然,如果一個方法返回一個值,每個方法都需要返回相同的值,或者可能需要精確。
我想在測試過程中有效地偵聽接口調用,但沒有模擬結束行。
我使用Moq如果它有任何區別。
請詳細解釋一下嗎? 「我想在測試過程中有效地監聽接口調用,但沒有模擬線路的終結。」 –
@MicahArmantrout對象A通過接口IB調用B上的方法。我想驗證那些電話,同時仍然讓他們在B上登記。 – weston