English 中文(简体)
• 如何利用Rhino Mocks为WCF网络服务
原标题:How to mock WCF Web Services with Rhino Mocks

我如何测试一个利用网络服务参考资料产生的代理客户的班子?

我愿对客户进行模拟,但所生成的客户界面没有包含近距离方法,必须妥善终止代理。 如果我不使用接口,而是具体提及,那么我就能够接触近距离方法,但无法篡改代理。

I m 试图测试一个类似类别:

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(); 
    }
}
问题回答

d 我创建了另一个接口,继承你的Ilogging ServiceClient,但增加了近距离方法。 然后,创立一个总结伐木服务公司情况的总结班。 类似:

public interface IDisposableLoggingServiceClient : ILoggingServiceClient
{
    void Close();
}

public class LoggingServiceClientWrapper : IDisposableLoggingServiceClient
{
    private readonly LoggingServiceClient client;

    public LoggingServiceClientWrapper(LoggingServiceClient client)
    {
        this.client = client;
    }

    public void LogSomething(string msg)
    {
        client.LogSomething(msg);
    }

    public void Close()
    {
        client.Close();
    }
}

现在,你的服务适应者可以使用可视的计票服务公司。

在我的经验中,检验像这样的东西所需要的时间确实值得。 您的适应者如果做得当,主要目的就是为呼吁守则提供试航海。 此时此刻,它具有类似特性和观点。 你不需要测试,因为你可以直观地检查法典,而且你非常简单地知道它正确。

这是很晚的,但我只是研究如何解决这一问题。 由于自动生成的客户类别是作为部分内容生成的,因此可以扩大:

public interface ICloseableLoggingServiceClient : ILoggingServiceClient
{
    void Close();
}

public partial class LoggingServiceClient : ICloseableLoggingServiceClient
{

}

如今,您的<代码> 近方法,见<代码>ClientBase<>,以及无论您的服务合同有具体规定,而且您应能模拟。 履历表 你们都需要做的是,确保你对新接口而不是具体客户类别进行再注入和测试。





相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...