简体   繁体   中英

Mock WCF service reference exposed through a third party DLL

Our application integrates with a WCF webservice through a dll reference and WCF configuration entries in the client application's web.config. When I try to mock the webservice I receive an "Could not find default endpoint element that references contract in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this co..." error. To resolve the issue, I have added the corresponding bindings from the web.config into the test project's app.config file and set it to "copy always" so it is copied to the bin\\debug folder but I still get the error. How should I resolve this issue?

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);
}

在此处输入图片说明

The web.config for the project that generated that dll should have the binding configuration. If you reference the dll as a project reference in vs then it should use whatever setting was built in, otherwise, the most straight forward solution would be to copy the binding to your test application's configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM