如何在 FitNesse 测试中调用 WCF 服务

本文关键字:调用 WCF 服务 测试 FitNesse | 更新日期: 2023-09-27 18:33:47

我正在尝试在 FitNesse 测试中调用 WCF 服务。当我尝试使用以下代码初始化客户端时:

    using (var client = new Status.StatusSoapClient())
    {
        client.Endpoint.Address = new EndpointAddress(url);
        response = client.GetProductionTicketStatus(dealerId, orderId, orderLineId);
    }

我收到一个错误:

系统无效操作异常:找不到默认端点 元素引用协定 'Status.StatusSoap' 在 服务模型客户端配置部分。

这是有道理的,因为.NET Framework不支持DLL的配置。

MSDN 库说:"您必须将配置代码移动到宿主环境识别的配置文件中"。但我不确定这是否可以为FitNesse完成。

所以我尝试自己创建绑定,而不尝试从配置中读取它

    var binding = new BasicHttpBinding();
    binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.OpenTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.MaxReceivedMessageSize = 10000;
    binding.ReaderQuotas.MaxStringContentLength = 10000;
    binding.ReaderQuotas.MaxDepth = 10000;
    binding.ReaderQuotas.MaxArrayLength = 10000;
    var endpoint = new EndpointAddress(url);
    var myClient = new Status.StatusSoapClient(binding, endpoint);
    response = myClient.GetProductionTicketStatus(dealerId, orderId, orderLineId);

但是当我尝试使用此代码运行测试时,我在 FitNesse 上收到"测试中断并且结果不完整"错误。

这个答案 https://stackoverflow.com/a/646177/2211481 建议为测试运行程序制作 app.config 的副本。当我将我的 app.config 复制到 Runner.exe.config,将其放入 Runner 文件夹并再次运行初始代码时,我再次在 FitNesse 上收到"测试中断且结果不完整"错误。

有没有办法解决这个问题?

如何在 FitNesse 测试中调用 WCF 服务

通过定义COMMAND_PATTERN使其工作,如下所述:http://twenty6-jc.blogspot.nl/2010/07/wcf-and-fitnesse-how-to-load-clients.html

!define COMMAND_PATTERN {%m -a C:''projects''someapplication''acceptancetests''acceptancetests.dll.config -r fitSharp.Slim.Service.Runner,c:''tools'slim''fitsharp.dll %p}

为测试运行程序制作 app.config 的副本最终也奏效了。

我收到"测试中断,结果不完整"错误,因为我的代码中有错误,我在调试后解决了。

请参阅此帖子: FitNesse App.Config

NetRunner 对列表中的第一个 dll 使用配置文件。

对于

示例,对于行:

!path C:'Probjects'HelloWorld'bin'Debug'FitNesseHelloWorld1.dll, C:'Probjects'HelloWorld'bin'Debug'FitNesseHelloWorld2.dll

NetRunner 将使用配置文件 "C:''Probjects''HelloWorld''bin''Debug''FitNesseHelloWorld1.dll.config">