I'm trying to create an integration tests for my project. I need to test a controller that makes call to stored procedure through repository. An empty database should be created on each runs of certain scope of tests. So I'm going to implement the following steps:
In my solution I have .sqlproj
with all tables and SPs. How can I create LocalDB with the same structure as in .sqlproj
from C# code? Or how can I generate the script with all objects to run it on LocalDB?
In bin folder of .sqlproj
exists MyProjectName_Create.sql but it doesn't run in cmd.ExecuteNonQuery();
Any help/suggestion will be appreciated. Thanks
P.S. Related question is How to disable predeployment and postdeployment scripts in DacServices.Deploy()
In Visual Studio Code, press Ctrl+Shift+P (or F1) to open the Command Palette. Select MS SQL:Connect and choose Enter. Select Create Connection Profile. Follow the prompts to specify the new profile's connection properties.
In the build folder of your sqlproj you can also find [DBName].dacpac file. You can use sqlpackage.exe to deploy the dacpac to your localdb. Ben Day explains in this blog pretty nicely. You can find sqlpackage.exe in your sql server installation folder if it is not directly available from the command line.
SqlPackage /Action:Publish
/SourceFile:”Benday.SampleApp.Database.dacpac”
/TargetDatabaseName:BendaySampleAppDb
/TargetServerName:”demo2012util”
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With