Microsoft Shims with WCF

I am trying to run this example and use a padding to remove an external dependency on a WCF service call that is being called from a method; I do unit test on. Unlike the example, I generate my WCF client on the fly using code similar to this:

ChannelFactory<IReportBroker> factory = new ChannelFactory<IReportBroker>("ReportBrokerBasicHttpStreamed", new EndpointAddress(this.CurrentSecurityZoneConfigurationManager.ConfigurationSettings[Constants.ConfigurationKeys.ReportBrokerServiceUrl])); IReportBroker proxy = factory.CreateChannel(); proxy.Execute(requestMessage)) 

How can I adapt this example to lay the proxy returned by the CreateChannel method? I assume that in the ShimWCFService class I need to add something like ....

 ShimChannelFactory<TService>.AllInstances.CreateChannel = (var1) => { return [instance of a mock object]}; 

However, I'm not sure how to associate the layout of the <TService> object with this pad as a return value.

+4
source share
1 answer

You need to pin a factory for each type parameter. Suppose you have three service contracts IService0 'IService1' and 'IService2'.

Then you need to configure the gaskets as follows:

 ShimChannelFactory<IService0>.AllInstances.CreateChannel = (_) => { return new Service0Mock(); } ShimChannelFactory<IService1>.AllInstances.CreateChannel = (_) => { return new Service1Mock(); } ShimChannelFactory<IService2>.AllInstances.CreateChannel = (_) => { return new Service2Mock(); } 
+3
source

Source: https://habr.com/ru/post/1490599/


All Articles