私はこの種の状況で嘲笑しています:
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};
}
したがって、私は、一般的にインターフェイスをサポートし、複数のインターフェイスで同じメソッドを呼び出す、ある種のプロキシ ファクトリを求めています。もちろん、メソッドが値を返す場合、それぞれが同じ値を返す必要があるか、どちらかが優先されます。
テスト中にインターフェイス呼び出しを効果的にスヌープしたいのですが、モックが行末になることはありません。
違いがあればMoqを使用しています。