Your problem is that you closely linked your business layer to your WCF service — you are actually creating a new instance of the service client in the business layer, which means that it is now impossible to call the SendData method without calling the service methods.
The best solution here is to inject dependency injection into your architecture.
In its simplest case, all you do is pass the instance of your service class to your business layer. This is often done when building a class using a constructor parameter.
public class BusinessClass { private ISomeServiceClient _svc; public BusinessClass(ISomeServiceClient svc) { _svc = svc; } public void SendData(DataUnit dataUnit) { _svc.SomeMethod(dataUnit); } }
Note that the code above is a design pattern that is completely independent of any structure, such as the Inversion of Control container.
If your company policy does not use such frameworks (crazy policy, by the way), you can still manually enter your layouts into the service inside your unit tests.
David hall
source share