如何測試利用由Web服務引用生成的代理客戶端的類?如何使用Rhino Mocks模擬WCF Web服務
我想模擬客戶端,但生成的客戶端界面不包含close方法,這是正確終止代理所需的。如果我不使用接口,而是使用具體的引用,我可以訪問close方法,但是無法模擬代理。
我想測試一個類似的類:
public class ServiceAdapter : IServiceAdapter, IDisposable
{
// ILoggingServiceClient is generated via a Web Service reference
private readonly ILoggingServiceClient _loggingServiceClient;
public ServiceAdapter() : this(new LoggingServiceClient()) {}
internal ServiceAdapter(ILoggingServiceClient loggingServiceClient)
{
_loggingServiceClient = loggingServiceClient;
}
public void LogSomething(string msg)
{
_loggingServiceClient.LogSomething(msg);
}
public void Dispose()
{
// this doesn't compile, because ILoggingServiceClient doesn't contain Close(),
// yet Close is required to properly terminate the WCF client
_loggingServiceClient.Close();
}
}