无法使用IntelliTest测试WCF端点

时间:2016-01-07 07:26:13

标签: c# wcf intellitest

我尝试使用IntelliTest测试我的WCF服务端点我在测试项目中创建了IntelliTest个单元,但我需要指定服务器地址和端口要求测试远程工作。

这是PexMethods

之一
public ICredentials CredentialsTest()
{
    ICredentials result = Service.Credentials();
    return result;
    // TODO: add assertions to method ServiceTest.CredentialsTest()
}

我已添加

Service.ServiceEndPointAddress = "net.tcp://localhost:51010/WCFService";

但是当我运行测试时,我得到InvalidProgramException

我想要做的是分配一次ServiceEndPointAddress,因为它是Service中的静态属性。有人可以提供一些指导吗?

1 个答案:

答案 0 :(得分:0)

这里有几个问题:

  1. 获取InvalidProgramException表示IntelliTest已对您的代码进行了检测,以致导致底层CLR引发异常。这将是IntelliTest中的一个错误。我请求您使用Visual Studio中的发送微笑来提交此文件。
  2. 您不应该使用IntelliTest直接浏览您的WCF代码。相反,您应该使用模拟隔离WCF相关的外部依赖项(就像您手动编写单元测试时那样),然后运行IntelliTest来探索生成的代码。对于模拟,你可以考虑使用Fakes。