SUMMARY

WCF services are becoming more widespread in .NET applications. As the users' needs change and new form factors such as mobile devices become popular, the need for services will only increase. It's important to have a testing strategy for WCF services in your application development practice.

Well-designed WCF services contain no business logic. Instead, they rely on the business logic in the application domain layer, which the WCF service consumes. The WCF service itself should concern itself only with processing specific to itself, such as validation and type translation. This results in WCF services that are short and simple. But these services are still code and still need to be tested.

With dependency injection frameworks such as Ninject, you can eliminate statically bound dependencies from your WCF services. The ability to inject dependencies opens the door to WCF services that are testable. Once the WCF service application can support dependency injection, it becomes a simple matter to test your WCF services as you would any other class: Supply the test implementation with mocked dependencies, and verify their functionality.

Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.