VOOZH about

URL: https://www.nuget.org/packages/Net4x.DapperLibrary.MockSqlServer/

⇱ NuGet Gallery | Net4x.DapperLibrary.MockSqlServer 1.9.9.8




Net4x.DapperLibrary.MockSqlServer 1.9.9.8

dotnet add package Net4x.DapperLibrary.MockSqlServer --version 1.9.9.8
 
 
NuGet\Install-Package Net4x.DapperLibrary.MockSqlServer -Version 1.9.9.8
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net4x.DapperLibrary.MockSqlServer" Version="1.9.9.8" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.DapperLibrary.MockSqlServer" Version="1.9.9.8" />
 
Directory.Packages.props
<PackageReference Include="Net4x.DapperLibrary.MockSqlServer" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net4x.DapperLibrary.MockSqlServer --version 1.9.9.8
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Net4x.DapperLibrary.MockSqlServer, 1.9.9.8"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Net4x.DapperLibrary.MockSqlServer@1.9.9.8
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net4x.DapperLibrary.MockSqlServer&version=1.9.9.8
 
Install as a Cake Addin
#tool nuget:?package=Net4x.DapperLibrary.MockSqlServer&version=1.9.9.8
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DapperLibrary.MockSqlServer

Lightweight helpers to create and use a mocked SQL Server IDapperContext for tests and local development. This project provides a small framework around LocalDB (and optional Docker-based SQL Server containers on modern runtimes) to obtain IDapperContext instances backed by a file-based or ephemeral SQL Server instance.

Purpose

Make it easy to spin up a disposable or reusable SQL Server instance for unit and integration tests and to obtain a corresponding IDapperContext preconfigured with SQL Server defaults used by the DapperLibraries.

Features

  • Create or attach a LocalDB .mdf database and return a configured IDapperContext.
  • Optionally reuse a single database file across tests via the ReuseDb flag to speed test runs.
  • Support for using Docker-based SQL Server containers on modern runtimes (Testcontainers) � enabled under NET6_0_OR_GREATER compilation.
  • Automatic configuration of DatabaseModel defaults for SQL Server (identity initializer and datetime literal formatting).
  • Helpers to create/drop/attach/detach databases programmatically.

Key types

  • MockedSqlDapperContext / MockedSqlDapperContext<TSqlDapperContext>

    • Primary entry point for consumers. Provides convenience static methods and properties that wrap an internal MockedSqlUseDapperContext instance.
    • Exposes GetInstance() overloads to obtain a ready-to-use IDapperContext (optionally accepting a logger and a custom path).
    • Exposes Use() and UseOnce() methods that populate the global DapperContextFactory ContextCreator so application code can request contexts via factory APIs.
    • Runtime-specific behavior: on modern runtimes it implements IDisposable / IAsyncDisposable to release Docker containers.
  • MockedSqlUseDapperContext

    • Internal helper that encapsulates the logic used by MockedSqlDapperContext to provision LocalDB instances or to fall back to Docker containers when requested.
    • Tracks flags such as ReuseDb, UseMaster and UseDocker to modify provisioning behavior.
  • LocalDbEnsurerInternal<T> and LocalDbInternal<T>

    • Responsible for creating and ensuring LocalDB instances exist, creating .mdf files, attaching/detaching databases, and returning an opened SqlConnection or IDapperContext rooted at the LocalDB instance.
    • LocalDbInternal contains helpers to create, drop and detach databases, and to map file paths used for created databases.

Usage examples

Obtain a context for tests:

// Simple: get an IDapperContext backed by LocalDB
using var context = MockedSqlDapperContext.GetInstance();

// Get instance with a logger
var ctx = MockedSqlDapperContext.GetInstance(myLogger);

// Get instance using a specific file path
var ctx2 = MockedSqlDapperContext.GetInstance(myLogger, "C:\\temp\\testdb.mdf");

Control reuse and lifecycle:

// When true, the same .mdf file may be reused across calls to speed up tests
MockedSqlDapperContext.ReuseDb = true;

// When false, each call will dispose any reused context and create a fresh database
MockedSqlDapperContext.ReuseDb = false;

// When false, a non-master database file will be used per GetInstance() call
MockedSqlDapperContext.UseMaster = false;

Register context creation for code that consumes the DapperContextFactory:

// Register the context creator so code calling DapperContextFactory.Instance.CreateContext() gets a mocked context
MockedSqlDapperContext.Use();

// Register once (adds a disposal handler)
MockedSqlDapperContext.UseOnce();

Docker support (modern runtimes only):

// On .NET 6+ you can opt into using Testcontainers if LocalDB is not available
MockedSqlDapperContext.UseDapperContext.UseDocker = true;
var ctx = MockedSqlDapperContext.GetInstance();

Multi-targeting notes

  • The project includes conditional compilation to support multiple frameworks. LocalDB-based helpers target .NET Framework and older runtimes; Docker-based Testcontainers support is compiled under NET6_0_OR_GREATER.
  • The repository contains different build outputs for net40/net45/net461 and modern targets; pick the appropriate compiled asset for your application runtime.

Behavior & best practices

  • The code aims to avoid leaving dangling LocalDB files: when ReuseDb is disabled, the helper will attempt to clean up created .mdf and .ldf files when appropriate.
  • Use UseMaster to control whether created databases are attached to the LocalDB master or created as separate files.
  • For reliable integration tests in CI (where LocalDB may not be present), enable UseDocker on supported runtimes to provision a SQL Server container instead.
  • Be mindful of permissions and available disk space when creating .mdf files.

Where to look in the codebase

  • DbContexts/MockedSqlDapperContext.* � the high-level context wrappers used by tests.
  • Internals/SqlServer/LocalDbEnsurerInternal.cs and LocalDbInternal.cs � LocalDB provisioning, creation, attach/detach and helper functions.
  • Internals/MockedSqlUseDapperContext.cs � the glue between high-level APIs and the LocalDB/Docker provisioning logic.

This README summarizes usage and integration points. Inspect the source code and XML docs for detailed implementation and further customization.

Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  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 is compatible.  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. 
.NET Framework net40 net40 is compatible.  net403 net403 was computed.  net45 net45 is compatible.  net451 net451 was computed.  net452 net452 was computed.  net46 net46 was computed.  net461 net461 is compatible.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Net4x.DapperLibrary.MockSqlServer:

Package Downloads
Net4x.Xsd2Db.Base

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.9.8 138 2/2/2026
1.9.9.7 136 1/13/2026
1.9.9.6 135 1/6/2026
1.9.9.5 142 1/6/2026
1.9.9.4 135 1/6/2026
1.9.9.3 139 1/5/2026
1.9.9.2 149 12/30/2025
1.9.9.1 132 12/30/2025
1.9.9 227 12/22/2025
1.6.0.12 189 12/12/2025
1.6.0.11 182 12/12/2025
1.6.0.10 490 12/9/2025
1.6.0.9 269 12/4/2025
1.6.0.8 250 12/4/2025
1.6.0.7 314 11/30/2025
1.6.0.6 241 11/27/2025
1.6.0.5 312 11/22/2025
1.6.0.4 203 11/16/2025
1.6.0.3 230 11/15/2025
1.6.0.2 327 11/14/2025
Loading failed