DacHelpers 0.0.2-alpha6

This is a prerelease version of DacHelpers.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package DacHelpers --version 0.0.2-alpha6
NuGet\Install-Package DacHelpers -Version 0.0.2-alpha6
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="DacHelpers" Version="0.0.2-alpha6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DacHelpers --version 0.0.2-alpha6
#r "nuget: DacHelpers, 0.0.2-alpha6"
#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.
// Install DacHelpers as a Cake Addin
#addin nuget:?package=DacHelpers&version=0.0.2-alpha6&prerelease

// Install DacHelpers as a Cake Tool
#tool nuget:?package=DacHelpers&version=0.0.2-alpha6&prerelease

DacHelpers

Wrapper for Microsoft.SqlServer.Dac and Docker.DotNet to simplify integration testing against databases with DacPacs.

Usage

To deploy a DacPac to localhost or to local docker simply supply a path and a name. Note that it drops the existing database first.

var dacpacPath = "TestDb.dacpac";
var databaseName = "TestDb";
var testDatabaseHelper = await DacHelper.DropAndDeployLocalAsync(dacpacPath, databaseName);
//Or
var testDatabaseHelper = await DacHelper.DeployDockerAsync(dacpacPath, databaseName);

The databaseTestHelper has a few helper functions to aid tests like supplying connectionstrings, resetting the database or cleaning up after use:

var connectionString = testDatabaseHelper.GetConnectionString();
await testDatabaseHelper.ResetDatabaseAsync();
await testDatabaseHelper.CleanUpAsync();

If deploying to a docker container or server that already exist just supply a ConnectionString. Note though that the returned testDatabaseHelper can't be relied on then to dispose a container':

var connectionString = testDatabaseHelper.GetConnectionString();
var testDatabaseHelper = await DacHelper.DropAndDeployAsync(dacpacPath, databaseName, connectionString);

Specifically for docker you can specify an image if you need to target a specific version of sql server:

var testDatabaseHelper = await DacHelper.DeployDockerAsync(dacpacPath, databaseName, "mcr.microsoft.com/mssql/server:2019-latest");

If using SqlCmd variables in the DacPac you can supply a dictionary with mappings:

var variableMap = new Dictionary<string, string>() { { "Registration", "Registration" } }
var testDatabaseHelper = DacHelper.DropAndDeployLocalAsync(dacpacPath, databaseName, variableMap);

To deploy a list of changescripts instead of a DacPac locally:

var folder = "changescripts/"
var changescripts = new List<string> = { $"{folder}001-addSchemas.sql", $"{folder}002-addEmployeeTable", $"{folder}003-addOfficeTable" }
await DacHelper.DeployChangescriptsLocalAsync(databaseName, changescripts);

Or to simply deploy a folder of changescripts locally (in alphabetical order):

var folder = "changescripts/"
await DacHelper.DeployChangescriptsLocalAsync(databaseName, folder);

Testing that a list of changescripts match a DacPac is as simple as:

var changes = await DacHelper.CompareLocalAsync(dacpacPath, changescriptFolder);
Assert.That(changes, Has.Count.EqualTo(0));
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.3-alpha1 104 1/8/2023
0.0.2-alpha6 105 12/21/2022
0.0.2-alpha5 91 12/11/2022
0.0.2-alpha4 91 12/8/2022
0.0.2-alpha3 94 12/8/2022
0.0.2-alpha2 94 12/8/2022
0.0.2-alpha1 92 12/7/2022
0.0.1-alpha1 93 12/6/2022