通过第三方 DLL 公开的模拟 WCF 服务引用
Mock WCF service reference exposed through a third party DLL
我们的应用程序通过客户端应用程序 web.config 中的 dll 引用和 WCF 配置条目与 WCF 网络服务集成。当我尝试模拟 Web 服务时,我收到 "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..." 错误。
为了解决这个问题,我将 web.config 中的相应绑定添加到测试项目的 app.config 文件中,并将其设置为 "copy always",以便将其复制到 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);
}
生成该 dll 的项目的 web.config 应该具有绑定配置。如果您将 dll 引用为 vs 中的项目引用,那么它应该使用内置的任何设置,否则,最直接的解决方案是将绑定复制到测试应用程序的配置中。
我们的应用程序通过客户端应用程序 web.config 中的 dll 引用和 WCF 配置条目与 WCF 网络服务集成。当我尝试模拟 Web 服务时,我收到 "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..." 错误。 为了解决这个问题,我将 web.config 中的相应绑定添加到测试项目的 app.config 文件中,并将其设置为 "copy always",以便将其复制到 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);
}
生成该 dll 的项目的 web.config 应该具有绑定配置。如果您将 dll 引用为 vs 中的项目引用,那么它应该使用内置的任何设置,否则,最直接的解决方案是将绑定复制到测试应用程序的配置中。