DbSqlLikeMem

April 17, 2026 · View on GitHub

EN: In-memory C# database engine for unit tests that emulates SQL dialects and ADO.NET behavior for MySQL, MariaDB, Firebird, SQL Server, SQL Azure, Oracle, PostgreSQL (Npgsql), SQLite, and DB2.

PT-BR: Mecanismo de banco de dados em memória para testes unitários em C# que emula dialetos SQL e o comportamento de ADO.NET para MySQL, MariaDB, Firebird, SQL Server, SQL Azure, Oracle, PostgreSQL (Npgsql), SQLite e DB2.

Logo DbSqlLikeMem

📚 Documentation by context | Documentação por contexto

EN: To keep maintenance and reading easier, the main documentation is split by topic:

PT-BR: Para facilitar a manutenção e a leitura, a documentação principal foi separada por tema:

EN: Use this root README.md as your entry point and go deeper through the links above.
PT-BR: Use este README.md da raiz como porta de entrada e aprofunde pelos links acima.


Features (summary) | Funcionalidades (resumo)

  • EN: Support for 9 providers: MySQL, MariaDB, Firebird, SQL Server, SQL Azure, Oracle, PostgreSQL (Npgsql), SQLite, and DB2. PT-BR: Suporte a 9 provedores: MySQL, MariaDB, Firebird, SQL Server, SQL Azure, Oracle, PostgreSQL (Npgsql), SQLite e DB2.
  • EN: Provider-specific ADO.NET mocks.
    PT-BR: Mocks ADO.NET específicos por provedor.
  • EN: SQL parser + executor for common DDL/DML operations.
    PT-BR: Parser + executor SQL para operações DDL/DML comuns.
  • EN: Fluent API for schema definition and data seeding.
    PT-BR: API fluente para definição de schema e seed de dados.
  • EN: Schema-level sequences plus optional identity override for deterministic setup and dialect-aware sequence flows.
    PT-BR: Sequences em nível de schema e sobrescrita opcional de identity para setup determinístico e fluxos de sequence sensíveis ao dialeto.
  • EN: Friendly execution flow for Dapper-based tests.
    PT-BR: Fluxo de execução amigável para testes com Dapper.
  • EN: Dialect/version-specific behavior.
    PT-BR: Comportamento específico por dialeto/versão.
  • EN: Mock execution plans with runtime metrics (EstimatedCost, InputTables, EstimatedRowsRead, ActualRows, SelectivityPct, RowsPerMs, ElapsedMs) and per-connection history (LastExecutionPlan, LastExecutionPlans).
    PT-BR: Planos de execução mock com métricas de runtime (EstimatedCost, InputTables, EstimatedRowsRead, ActualRows, SelectivityPct, RowsPerMs, ElapsedMs) e histórico por conexão (LastExecutionPlan, LastExecutionPlans).

EN: Full compatibility details are available here:
PT-BR: Os detalhes completos de compatibilidade estão aqui:

When to use | Quando usar

  • EN: Unit and integration tests that require SQL behavior without running a real database server.
    PT-BR: Testes unitários e de integração que exigem comportamento SQL sem executar um servidor de banco real.
  • EN: Fast feedback scenarios in CI/CD pipelines where deterministic setup matters.
    PT-BR: Cenários de feedback rápido em pipelines CI/CD onde setup determinístico é importante.
  • EN: Vibe coding workflows that benefit from shorter test cycles and faster iteration.
    PT-BR: Fluxos de vibe coding que se beneficiam de ciclos de teste mais curtos e iteração mais rápida.
  • EN: Multi-dialect test suites where the same repository/service logic is validated against different providers.
    PT-BR: Suítes de teste multi-dialeto onde a mesma lógica de repositório/serviço é validada em provedores diferentes.

Scope and expectations | Escopo e expectativas

  • EN: This project emulates major ADO.NET and SQL behaviors for tests; it is not intended to replace production databases.
    PT-BR: Este projeto emula comportamentos principais de ADO.NET e SQL para testes; não substitui bancos de produção.
  • EN: SQL support is intentionally incremental and dialect-aware; unsupported constructs throw clear exceptions.
    PT-BR: O suporte SQL é incremental e sensível ao dialeto; construções não suportadas geram exceções claras.
  • EN: Affected-rows semantics follow dialect conventions where applicable (for example, MySQL upsert conflict updates may report 2).
    PT-BR: A semântica de linhas afetadas segue convenções por dialeto quando aplicável (por exemplo, update em conflito no upsert MySQL pode retornar 2).

Quick start in 60 seconds | Começo rápido em 60 segundos

using DbSqlLikeMem.MySql;

var db = new MySqlDbMock(version: 80);
var users = db.AddTable("users");
users.AddColumn("Id", DbType.Int32, false);
users.AddColumn("Name", DbType.String, false);
users.AddPrimaryKeyIndexes("id");

using var cnn = new MySqlConnectionMock(db);
cnn.Open();

using var cmd = cnn.CreateCommand();
cmd.CommandText = "INSERT INTO users (Id, Name) VALUES (1, 'Alice')";
cmd.ExecuteNonQuery();

cmd.CommandText = "SELECT Name FROM users WHERE Id = 1";
var name = (string?)cmd.ExecuteScalar();
// name == "Alice"

EN: For provider-specific examples (Dapper, transactions, RETURNING/OUTPUT, etc.), see: docs/getting-started.md
PT-BR: Para exemplos por provedor (Dapper, transações, RETURNING/OUTPUT etc.), veja: docs/getting-started.md

Sequence quick reference | Referência rápida de sequence

  • EN: SQL Server: NEXT VALUE FOR schema.seq_name
    PT-BR: SQL Server: NEXT VALUE FOR schema.seq_name
  • EN: MariaDB: NEXT VALUE FOR schema.seq_name, PREVIOUS VALUE FOR schema.seq_name PT-BR: MariaDB: NEXT VALUE FOR schema.seq_name, PREVIOUS VALUE FOR schema.seq_name
  • EN: PostgreSQL: nextval('schema.seq_name'), currval('schema.seq_name'), setval('schema.seq_name', value, is_called), lastval()
    PT-BR: PostgreSQL: nextval('schema.seq_name'), currval('schema.seq_name'), setval('schema.seq_name', value, is_called), lastval()
  • EN: Oracle: schema.seq_name.NEXTVAL, schema.seq_name.CURRVAL
    PT-BR: Oracle: schema.seq_name.NEXTVAL, schema.seq_name.CURRVAL
  • EN: Firebird: schema.seq_name.NEXTVAL, schema.seq_name.CURRVAL PT-BR: Firebird: schema.seq_name.NEXTVAL, schema.seq_name.CURRVAL
  • EN: DB2: NEXT VALUE FOR schema.seq_name, PREVIOUS VALUE FOR schema.seq_name
    PT-BR: DB2: NEXT VALUE FOR schema.seq_name, PREVIOUS VALUE FOR schema.seq_name

EN: See docs/getting-started.md for end-to-end examples.
PT-BR: Veja docs/getting-started.md para exemplos end-to-end.

Execution plan diagnostics (quick view) | Diagnóstico de plano de execução (visão rápida)

using var cmd = cnn.CreateCommand();
cmd.CommandText = "SELECT Name FROM users WHERE Id = 1";
using var reader = cmd.ExecuteReader();

var plan = cnn.LastExecutionPlan;
// plan.EstimatedCost, plan.EstimatedRowsRead, plan.ActualRows, plan.ElapsedMs, ...

EN: Use LastExecutionPlans when validating a sequence of statements in a single test flow.
PT-BR: Use LastExecutionPlans ao validar uma sequência de comandos no mesmo fluxo de teste.

Requirements | Requisitos

  • EN: Production core and provider packages follow the central targets in src/code/Directory.Build.props: net462, netstandard2.0, and net8.0. PT-BR: Os pacotes de produção do núcleo e dos provedores seguem os alvos centrais de src/code/Directory.Build.props: net462, netstandard2.0 e net8.0.
  • EN: Test and test-tools projects use the dedicated override target set: net462, net6.0, and net8.0.
    PT-BR: Os projetos de teste e test-tools usam o conjunto de alvos do override dedicado: net462, net6.0 e net8.0.
  • EN: Some tooling or integration-specific projects may use narrower target sets (for example, extension/tooling projects outside the main NuGet package flow).
    PT-BR: Alguns projetos específicos de tooling ou integração podem usar conjuntos de alvo mais estreitos (por exemplo, extensões e ferramentas fora do fluxo principal de pacotes NuGet).

Supported Providers | Provedores suportados

Provider / ProvedorPackage/Project / Pacote/Projeto
MySQLDbSqlLikeMem.MySql
MariaDBDbSqlLikeMem.MariaDb
FirebirdDbSqlLikeMem.Firebird
SQL ServerDbSqlLikeMem.SqlServer
SQL AzureDbSqlLikeMem.SqlAzure
OracleDbSqlLikeMem.Oracle
PostgreSQL (Npgsql)DbSqlLikeMem.Npgsql
SQLite (Sqlite)DbSqlLikeMem.Sqlite
DB2DbSqlLikeMem.Db2

Simulated versions by provider | Versões simuladas por provedor

Provider / ProvedorSimulated versions / Versões simuladas
MySQL3.0, 4.0, 5.5, 5.6, 5.7, 8.0, 8.4
MariaDB10.3, 10.5, 10.6, 10.8, 11.0
Firebird2.1, 2.5, 3.0, 4.0, 5.0
SQL Server7, 2000, 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
SQL Azure100, 110, 120, 130, 140, 150, 160, 170
Oracle7, 8, 9, 10, 11, 12, 18, 19, 21, 23
PostgreSQL (Npgsql)6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
SQLite (Sqlite)3.24, 3.25, 3.33, 3.35, 3.38, 3.40, 3.51
DB28, 9, 10, 11

For MySQL, documentation uses dotted versions (8.0, 8.4), while the provider API keeps integer values (80, 84). MariaDB follows the same pattern (10.3 -> 103, 10.5 -> 105, 10.6 -> 106, 10.8 -> 108, 11.0 -> 110). SQLite documentation uses the 3.x release family (3.24, 3.25, 3.33, 3.35, 3.38, 3.40, 3.51), while the provider API keeps integer tokens (324, 325, 333, 335, 338, 340, 351). Para MySQL, a documentação usa versões com ponto (8.0, 8.4), enquanto a API do provider mantém valores inteiros (80, 84). MariaDB segue o mesmo padrão (10.3 -> 103, 10.5 -> 105, 10.6 -> 106, 10.8 -> 108, 11.0 -> 110). A documentação de SQLite usa a família de releases 3.x (3.24, 3.25, 3.33, 3.35, 3.38, 3.40, 3.51), enquanto a API do provider mantém tokens inteiros (324, 325, 333, 335, 338, 340, 351).

Runtime provider factory example | Exemplo de factory de provider em runtime

using DbSqlLikeMem.Db2;
using DbSqlLikeMem.Firebird;
using DbSqlLikeMem.MariaDb;
using DbSqlLikeMem.MySql;
using DbSqlLikeMem.Npgsql;
using DbSqlLikeMem.Oracle;
using DbSqlLikeMem.SqlAzure;
using DbSqlLikeMem.Sqlite;
using DbSqlLikeMem.SqlServer;

public static class DbSqlLikeMemFactory
{
    public static DbConnection Create(string provider)
    {
        return provider.ToLowerInvariant() switch
        {
            "mysql" => new MySqlConnectionMock(new MySqlDbMock()),
            "mariadb" or "maria" => new MariaDbConnectionMock(new MariaDbDbMock()),
            "firebird" or "fb" => new FirebirdConnectionMock(new FirebirdDbMock()),
            "sqlserver" => new SqlServerConnectionMock(new SqlServerDbMock()),
            "sqlazure" or "azure-sql" or "azuresql" or "azure_sql" => new SqlAzureConnectionMock(new SqlAzureDbMock()),
            "oracle" => new OracleConnectionMock(new OracleDbMock()),
            "postgres" or "postgresql" or "npgsql" => new NpgsqlConnectionMock(new NpgsqlDbMock()),
            "sqlite" => new SqliteConnectionMock(new SqliteDbMock()),
            "db2" => new Db2ConnectionMock(new Db2DbMock()),
            _ => throw new ArgumentException($"Unsupported provider: {provider}")
        };
    }
}

Installation and usage examples | Instalação e exemplos de uso

EN: See the dedicated getting-started guide:
PT-BR: Consulte o guia dedicado de início rápido:

EN: The guide includes:
PT-BR: O guia inclui:

  • EN: Project references and DLL usage.
    PT-BR: Referência de projeto e uso de DLLs.
  • EN: NuGet/dependency notes.
    PT-BR: Observações de NuGet/dependências.
  • EN: Runtime provider factory.
    PT-BR: Factory de provider em runtime.
  • EN: InternalsVisibleTo configuration.
    PT-BR: Configuração de InternalsVisibleTo.
  • EN: SQL Server, PostgreSQL, and SQL DDL examples. PT-BR: Exemplos com SQL Server, PostgreSQL e DDL SQL.

Tests | Testes

dotnet test src/DbSqlLikeMem.slnx

EN: For benchmark and fidelity comparison runs, keep the default fast path unless you explicitly enable the suite-specific container flags such as RUN_PERFORMANCE_CONTAINER_TESTS, RUN_TEMPORARY_TABLE_CONTAINER_TESTS, RUN_TABLE_CONTAINER_TESTS, RUN_INSERT_CONTAINER_TESTS, RUN_SELECT_CONTAINER_TESTS, RUN_SCHEMA_CONTAINER_TESTS, or RUN_TRANSACTION_CONTAINER_TESTS. MariaDB, Firebird, and Db2 comparisons also require RUN_MARIADB_CONTAINER_TESTS, RUN_FIREBIRD_CONTAINER_TESTS, or RUN_DB2_CONTAINER_TESTS. Diagnostic benchmark features should stay disabled unless you are measuring ExecutionPlan, DebugTrace, or LastExecutionPlansHistory. PT-BR: Para execuções de benchmark e comparação de fidelidade, mantenha o caminho rápido padrão a menos que você habilite explicitamente as flags específicas de container, como RUN_PERFORMANCE_CONTAINER_TESTS, RUN_TEMPORARY_TABLE_CONTAINER_TESTS, RUN_TABLE_CONTAINER_TESTS, RUN_INSERT_CONTAINER_TESTS, RUN_SELECT_CONTAINER_TESTS, RUN_SCHEMA_CONTAINER_TESTS ou RUN_TRANSACTION_CONTAINER_TESTS. Comparações de MariaDB, Firebird e Db2 também exigem RUN_MARIADB_CONTAINER_TESTS, RUN_FIREBIRD_CONTAINER_TESTS ou RUN_DB2_CONTAINER_TESTS. Os recursos diagnósticos de benchmark devem permanecer desligados, salvo quando você estiver medindo ExecutionPlan, DebugTrace ou LastExecutionPlansHistory.

EN: To run one test project only:
PT-BR: Para executar apenas um projeto de teste:

dotnet test src/DbSqlLikeMem.SqlServer.Test/DbSqlLikeMem.SqlServer.Test.csproj
dotnet test src/DbSqlLikeMem.SqlAzure.Test/DbSqlLikeMem.SqlAzure.Test.csproj

Publishing | Publicação

EN: Publishing documentation is available at:
PT-BR: A documentação de publicação está em:

EN: It includes:
PT-BR: Ela inclui:

  • EN: NuGet package publishing.
    PT-BR: Publicação de pacotes no NuGet.
  • EN: VSIX extension publishing (Visual Studio Marketplace).
    PT-BR: Publicação de extensão VSIX (Visual Studio Marketplace).
  • EN: VS Code extension publishing (Marketplace).
    PT-BR: Publicação de extensão VS Code (Marketplace).

Documentation standard (English + Portuguese) | Padrão de documentação (inglês + português)

EN: For open-source readability, public API documentation should be written in two languages:

PT-BR: Para melhorar a legibilidade em open source, a documentação da API pública deve ser escrita em dois idiomas:

  • EN: English first (<summary> first sentence/paragraph in English).
    PT-BR: Inglês primeiro (primeira frase/parágrafo de <summary> em inglês).
  • EN: Portuguese next (second sentence/paragraph in Portuguese).
    PT-BR: Português em seguida (segunda frase/parágrafo em português).

EN: Recommended XML doc pattern:
PT-BR: Padrão recomendado de documentação XML:

/// <summary>
/// English description.
/// Descrição em português.
/// </summary>

EN: When overriding or implementing members that already have documentation, prefer:
PT-BR: Ao sobrescrever ou implementar membros que já possuem documentação, prefira:

/// <inheritdoc/>

EN: This keeps compiler warnings visible (including CS1591) so missing docs are fixed instead of hidden.
PT-BR: Isso mantém os avisos do compilador visíveis (incluindo CS1591) para que a documentação ausente seja corrigida, e não escondida.

Contribution | Contribuição

EN: Contributions are welcome! If you want to improve DbSqlLikeMem, open an issue to discuss your idea or submit a pull request.

PT-BR: Contribuições são bem-vindas! Se você quiser melhorar o DbSqlLikeMem, abra uma issue para discutir sua ideia ou envie um pull request.

EN: If you want to support the project financially, use GitHub Sponsors ("Sponsor" button) or Buy Me a Coffee: https://buymeacoffee.com/chrisulson.

PT-BR: Se você quiser apoiar o projeto financeiramente, use o GitHub Sponsors (botão "Sponsor") ou o Buy Me a Coffee: https://buymeacoffee.com/chrisulson.

EN: High-impact areas:
PT-BR: Áreas de alto impacto:

  • EN: Expand SQL compatibility by dialect.
    PT-BR: Expandir compatibilidade SQL por dialeto.
  • EN: Add examples and documentation.
    PT-BR: Adicionar exemplos e documentação.
  • EN: Improve performance and diagnostics.
    PT-BR: Melhorar desempenho e diagnósticos.
  • EN: Increase test coverage.
    PT-BR: Aumentar cobertura de testes.

Documentation structure for GitHub Wiki | Estrutura de documentação para Wiki do GitHub

EN: If you want to publish a GitHub Wiki based on local content:
PT-BR: Se você quiser publicar uma Wiki no GitHub com base no conteúdo local:

License | Licença

EN: This project is licensed under the MIT License. See LICENSE.

PT-BR: Este projeto é licenciado sob a Licença MIT. Veja LICENSE.