通过第三方DLL公开的模拟WCF服务引用

时间:2016-05-23 20:15:11

标签: c# .net wcf unit-testing moq

我们的应用程序通过客户端应用程序的web.config中的dll引用和WCF配置条目与WCF Web服务集成。当我尝试模拟Web服务时,我收到了一个"找不到引用ServiceModel客户端配置部分中的契约的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为没有匹配此组合的端点元素..."错误。 为解决此问题,我已将web.config中的相应绑定添加到测试项目的app.config文件中,并将其设置为"始终复制"所以它被复制到bin \ debug文件夹但我仍然得到错误。 我该如何解决这个问题?

using Payments.ServiceReferences.PaymentServiceProxy;
public interface IPaymentsAPIClientGenerator
{
    PaymentServiceClient PaymentServiceClient { get; }
}

using Payments.ServiceReferences.PaymentServiceProxy;
public class PaymentsAPIClientGenerator : IPaymentsAPIClientGenerator
{
    public PaymentsAPIClientGenerator()
    {
    }
    public PaymentServiceClient PaymentServiceClient
    {
        get
        {
            var paymentServiceClient = PaymentVaultProxyFactory.GeneratePaymentServiceClient();
            return paymentServiceClient;
        }
    }
}

[TestMethod]
public void IfTheSecondPaymentFailsThenTheFirstPaymentShouldBeVoided()
{
    //Arrange
    var iPaymentsAPIClientGeneratorMock = new Mock<IPaymentsAPIClientGenerator>();
    var paymentServiceClient = new Mock<PaymentServiceClient>();
    iPaymentsAPIClientGeneratorMock.SetupGet(counter => counter.PaymentServiceClient).Returns(paymentServiceClient.Object);
}

enter image description here

1 个答案:

答案 0 :(得分:1)

生成该dll的项目的web.config应该具有绑定配置。如果你在DLL中引用dll作为项目引用,那么它应该使用内置的任何设置,否则,最直接的解决方案是将绑定复制到测试应用程序的配置。

相关问题