Skip to content

Quick Start

Denis Voituron edited this page Oct 5, 2025 · 4 revisions
  1. Add the NuGet package DbMocker .

  2. Instanciate a MockDbConnection. This object implements all features of DbConnection with only one extra property called Mocks to define your conditions (see step 3).

    [TestMethod]
    public void MyUnitTest()
    {
        var conn = new MockDbConnection();
    }
  3. Intercept you SQL queries executions, using a condition and return a DataTable. For example, when the SQL query containing SELECT COUNT is 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));
  4. Don't change your app source code. Call your methods using this MockDbConnection reference, and validate your results.


👉 Find extra samples on the next Sample page

Clone this wiki locally