pengdows.crud.fakeDb
2.0.5
dotnet add package pengdows.crud.fakeDb --version 2.0.5
NuGet\Install-Package pengdows.crud.fakeDb -Version 2.0.5
<PackageReference Include="pengdows.crud.fakeDb" Version="2.0.5" />
<PackageVersion Include="pengdows.crud.fakeDb" Version="2.0.5" />
<PackageReference Include="pengdows.crud.fakeDb" />
paket add pengdows.crud.fakeDb --version 2.0.5
#r "nuget: pengdows.crud.fakeDb, 2.0.5"
#:package pengdows.crud.fakeDb@2.0.5
#addin nuget:?package=pengdows.crud.fakeDb&version=2.0.5
#tool nuget:?package=pengdows.crud.fakeDb&version=2.0.5
pengdows.crud.fakeDb
pengdows.crud.fakeDb provides a fake ADO.NET provider that you can use to mock low-level database calls. It lets
pengdows.crud execute SQL without a real database connection, which is handy for integration or unit tests. The
package ships with schema files to emulate different products so tests remain provider agnostic.
Usage
In the pengdows.crud.Tests project the fake provider is used to spin up a DatabaseContext without touching a real
database. The key pieces are fakeDbFactory and an EmulatedProduct value in the connection string:
using pengdows.crud;
using pengdows.crud.fakeDb;
var factory = new fakeDbFactory(SupportedDatabase.Sqlite.ToString());
var context = new DatabaseContext(
"Data Source=test;EmulatedProduct=Sqlite",
factory);
You can also use the fake provider without DatabaseContext. Create a fakeDbConnection
directly and work with it using normal ADO.NET APIs:
using pengdows.crud.fakeDb;
using var connection = new fakeDbConnection("Data Source=ignored;EmulatedProduct=Sqlite");
await connection.OpenAsync();
using var command = connection.CreateCommand();
command.CommandText = "SELECT 1";
using var reader = await command.ExecuteReaderAsync();
This makes pengdows.crud.fakeDb handy for testing any code that relies on
DbConnection or DbDataReader without spinning up a real database.
Connection Breaking for Testing
The enhanced fakeDbConnection supports sophisticated connection breaking functionality for testing error scenarios and
connection failures.
Connection Failure Modes
The fakeDbConnection can be configured to fail in various ways:
- FailOnOpen: Connection fails when
Open()orOpenAsync()is called - FailOnCommand: Connection fails when creating commands
- FailOnTransaction: Connection fails when beginning transactions
- FailAfterCount: Connection works for N operations then fails
- Broken: Connection is permanently broken
Basic Failure Testing
// Create a connection that fails on open
var factory = new fakeDbFactory(SupportedDatabase.Sqlite);
var connection = (fakeDbConnection)factory.CreateConnection();
connection.SetFailOnOpen();
// This will throw InvalidOperationException
try { connection.Open(); }
catch (InvalidOperationException) { /* Handle connection failure */ }
Custom Exceptions
var connection = (fakeDbConnection)factory.CreateConnection();
var timeoutException = new TimeoutException("Connection timed out");
connection.SetCustomFailureException(timeoutException);
connection.SetFailOnOpen();
connection.Open(); // throws TimeoutException with custom message
Fail After Count
var connection = (fakeDbConnection)factory.CreateConnection();
connection.SetFailAfterOpenCount(2);
connection.Open(); connection.Close(); // Works (1st)
connection.Open(); connection.Close(); // Works (2nd)
connection.Open(); // Throws! (3rd attempt fails)
Factory-Level Configuration
// Create factory that produces failing connections
var factory = fakeDbFactory.CreateFailingFactory(
SupportedDatabase.PostgreSql,
ConnectionFailureMode.FailOnOpen,
new TimeoutException("Custom timeout"));
var connection = factory.CreateConnection();
connection.Open(); // Throws TimeoutException
Command Execution Failures
var connection = (fakeDbConnection)factory.CreateConnection();
connection.Open();
var command = (fakeDbCommand)connection.CreateCommand();
command.SetFailOnExecute(true, new TimeoutException("Query timeout"));
command.ExecuteNonQuery(); // Throws TimeoutException
command.ExecuteScalar(); // Throws TimeoutException
command.ExecuteReader(); // Throws TimeoutException
Resetting Failure Conditions
var connection = (fakeDbConnection)factory.CreateConnection();
// Set multiple failure modes
connection.SetFailOnOpen();
connection.SetFailOnCommand();
// Reset everything back to normal
connection.ResetFailureConditions();
// Now connection works normally
connection.Open(); // Succeeds
Preloading Results
fakeDbConnection can queue up results that will be returned the next time a
command is executed. This allows tests to simulate query responses:
var conn = new fakeDbConnection("Data Source=:memory:;EmulatedProduct=Sqlite");
conn.EnqueueScalarResult(5);
conn.EnqueueReaderResult(new[] { new Dictionary<string, object>{{"Name", "Jane"}} });
conn.Open();
using var cmd = conn.CreateCommand();
var value = (int)cmd.ExecuteScalar(); // returns 5
using var reader = cmd.ExecuteReader();
reader.Read();
var name = reader.GetString(0); // "Jane"
Support
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- pengdows.crud.abstractions (>= 2.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.5 | 99 | 4/17/2026 |
| 2.0.4 | 136 | 3/31/2026 |
| 2.0.3 | 124 | 3/27/2026 |
| 2.0.2 | 100 | 3/24/2026 |
| 2.0.1 | 103 | 3/22/2026 |
| 2.0.0 | 162 | 2/28/2026 |
| 1.0.1769867481 | 162 | 1/31/2026 |
| 1.0.1769543242 | 112 | 1/27/2026 |
| 1.0.1769395132 | 105 | 1/26/2026 |
| 1.0.1769360331 | 107 | 1/25/2026 |
| 1.0.1767194225 | 116 | 12/31/2025 |
| 1.0.1759683344 | 186 | 10/5/2025 |
| 1.0.1759623120 | 185 | 10/5/2025 |
| 1.0.1756777911 | 667 | 9/2/2025 |
| 1.0.1756431873 | 228 | 8/29/2025 |
| 1.0.1756401895 | 240 | 8/28/2025 |
| 1.0.1756206653 | 249 | 8/26/2025 |
| 1.0.1756088498 | 255 | 8/25/2025 |
| 1.0.1755050805 | 186 | 8/13/2025 |
| 1.0.1754686097 | 184 | 8/8/2025 |