Static Methods Unit test by MOQ

Today I got pulled into one of the existing project and it had data layer with all static methods and its tightly coupled with service layer. I had to write unit test by using Moq framework for one of service method call and it had 5 different db layer method dependencies. Unfortunately Moq doesn't support to mock static methods directly. Moq is meant to mock Interfaces not concrete methods. Fortunately explicit interface implementation helped to achieve to write unit tests. I have followed below article and helped to write some unit tests for service layer.

Ref - https://guptaashish.com/2012/10/17/unit-testing-a-static-method-which-calls-another-static-method/#comments


Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

How to get Client's Location using IPAddress