Skip to content
Denis Voituron edited this page Oct 5, 2025 · 3 revisions

This .NET library simplifies data mocking for UnitTests, to avoid a connection to a relational database. DbMocker use the standard Microsoft .NET DbConnection object. So, you can mock any toolkit, including EntityFramework, Dapper or ADO.NET; And for all database servers (SQL Server, Oracle, SQLite).

DbMocker is an Open Source project. Go to https://github.com/Apps72/DbMocker to fork or improve the source code.

Example

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.

var conn = new MockDbConnection();

conn.Mocks
    .When(cmd => cmd.CommandText.Contains("SELECT COUNT"))
    .ReturnsTable(MockTable.WithColumns("Count")
                           .AddRow(14));

👉 Select a documentation page from the right sidebar.

Clone this wiki locally