Friday, June 5, 2015

Mocking SQL Server database layer in Unit tests with C# and Moq

In this post I will describe how to mock database layer in Unit Tests with C# and Moq.

Why it is needed? Well, good question.
Tests that verify that DB communications works are no longer just unit tests, they are integration tests. But quite often integration tests require more complex setup, they take longer time to execute, there should be some initialization & deployment process done to make them reliable.  Also it is hard to test all of the corner cases like connectivity issues, invalid schemas or backward compatibility.