![]() |
VOOZH | about |
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" />Directory.Packages.props
<PackageReference Include="pengdows.crud.fakeDb" />Project file
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.5Install as a Cake Addin
#tool nuget:?package=pengdows.crud.fakeDb&version=2.0.5Install as a Cake Tool
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.
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.
The enhanced fakeDbConnection supports sophisticated connection breaking functionality for testing error scenarios and
connection failures.
The fakeDbConnection can be configured to fail in various ways:
Open() or OpenAsync() is called// 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 */ }
var connection = (fakeDbConnection)factory.CreateConnection();
var timeoutException = new TimeoutException("Connection timed out");
connection.SetCustomFailureException(timeoutException);
connection.SetFailOnOpen();
connection.Open(); // throws TimeoutException with custom message
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)
// 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
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
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
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"
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.5 | 114 | 4/17/2026 |
| 2.0.4 | 151 | 3/31/2026 |
| 2.0.3 | 135 | 3/27/2026 |
| 2.0.2 | 108 | 3/24/2026 |
| 2.0.1 | 115 | 3/22/2026 |
| 2.0.0 | 170 | 2/28/2026 |
| 1.0.1769867481 | 172 | 1/31/2026 |
| 1.0.1769543242 | 122 | 1/27/2026 |
| 1.0.1769395132 | 111 | 1/26/2026 |
| 1.0.1769360331 | 113 | 1/25/2026 |
| 1.0.1767194225 | 125 | 12/31/2025 |
| 1.0.1759683344 | 194 | 10/5/2025 |
| 1.0.1759623120 | 192 | 10/5/2025 |
| 1.0.1756777911 | 779 | 9/2/2025 |
| 1.0.1756431873 | 236 | 8/29/2025 |
| 1.0.1756401895 | 248 | 8/28/2025 |
| 1.0.1756206653 | 259 | 8/26/2025 |
| 1.0.1756088498 | 261 | 8/25/2025 |
| 1.0.1755050805 | 194 | 8/13/2025 |
| 1.0.1754686097 | 192 | 8/8/2025 |