Ajit Goel
Ajit Goel

Reputation: 4388

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

enter image description here

Upvotes: 0

Views: 595

Answers (1)

Ross Bush
Ross Bush

Reputation: 15175

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.

Upvotes: 1

Related Questions