-
Notifications
You must be signed in to change notification settings - Fork 13
Quick Start
Denis Voituron edited this page Oct 5, 2025
·
4 revisions
-
Add the NuGet package DbMocker .
-
Instanciate a
MockDbConnection. This object implements all features ofDbConnectionwith only one extra property calledMocksto define your conditions (see step 3).[TestMethod] public void MyUnitTest() { var conn = new MockDbConnection(); }
-
Intercept you SQL queries executions, using a condition and return a DataTable. For example, when the SQL query containing
SELECT COUNTis executed in your app, it will be intercepted by DbMocker which will return a table containing the value 14.conn.Mocks .When(cmd => cmd.CommandText.Contains("SELECT COUNT")) .ReturnsTable(MockTable.WithColumns("Count") .AddRow(14));
-
Don't change your app source code. Call your methods using this
MockDbConnectionreference, and validate your results.
👉 Find extra samples on the next Sample page
Contact me at Denis[at]Voituron.net