Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Programmatically deploy database project in Visual Studio (for testing)

We have a micro service solution that includes:

  • A SQL Server database project
  • A Service project
  • A Test project

We are interested to know if there is a programmatic way, ideally in C# to deploy the database project to a specified target server to enable us to seed and then run a set of API -> database tests. This is to aid both developer and CI/CD testing.

We have explored in memory and SQLite substitution options but ideally want to run tests as representative of production as possible to avoid the potential for the "quirks" of those solutions resulting in problems being missed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add a reference to: Microsoft.SqlServer.Dac.

For my usage, I create the UnitTesting database separately as an empty database, then run the Database project against this database.

DacServices instance = new DacServices(connectionString);
String path = Path.GetFullPath(@"..\..\..\..\DatabaseProjectFolder\bin\Debug\DatabaseProject.dacpac");

String databaseName = $"UnitTesting";

using (DacPackage dacPackage = DacPackage.Load(path))
{
    instance.Deploy(dacPackage, databaseName);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading