我有一个WCF服务,我在其中一个应用程序中使用。一切正常,但我试图创建一些具有相同API的测试类,但是避免到服务器去获取他们的信息。例如:覆盖WCF客户端方法
// Goes to the server to get a list of names. It might be a while.
MyClient client = new MyClient();
string[] theNames = client.GetSpitefulUsers();
...
// This is what I would use in a test case...
public FakeClient : MyClient
{
...
public override string[] GetSpitefulUsers()
{
// This returns almost immediately, but I can't just override it because the
// 'MyClient' definition is generated code.
return new string[] {"Aldo", "Barry", "Cassie"};
}
}
那么,什么是提供这种类型的功能,而不必求助于聪明的黑客,嘲讽图书馆等最简单的方法?
查找依赖注入/控制 – Dave
的反转?这正是他们想要的。学习使用库比在每个测试用例中手工编写假对象更容易。 –
@Dave非常感谢您的模糊评论。 –