[英]Create LocalDB for testing from Visual Studio SQL project
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. 在我的解决方案中,我有
.sqlproj
与所有表和SP。 How can I create LocalDB with the same structure as in .sqlproj
from C# code? 如何使用与C#代码中的
.sqlproj
相同的结构创建LocalDB ? Or how can I generate the script with all objects to run it on LocalDB ? 或者如何生成包含所有对象的脚本以在LocalDB上运行它?
In bin folder of .sqlproj
exists MyProjectName_Create.sql but it doesn't run in cmd.ExecuteNonQuery();
在
.sqlproj
bin文件夹中存在MyProjectName_Create.sql但它不在cmd.ExecuteNonQuery();
运行cmd.ExecuteNonQuery();
Any help/suggestion will be appreciated. 任何帮助/建议将不胜感激。 Thanks
谢谢
PS Related question is How to disable predeployment and postdeployment scripts in DacServices.Deploy() PS相关问题是如何在DacServices.Deploy()中禁用预部署和部署后脚本
In the build folder of your sqlproj you can also find [DBName].dacpac file. 在sqlproj的build文件夹中,您还可以找到[DBName] .dacpac文件。 You can use sqlpackage.exe to deploy the dacpac to your localdb.
您可以使用sqlpackage.exe将dacpac部署到localdb。 Ben Day explains in this blog pretty nicely.
Ben Day在这篇博客中解释得非常好。 You can find sqlpackage.exe in your sql server installation folder if it is not directly available from the command line.
您可以在sql server安装文件夹中找到sqlpackage.exe,如果它不能从命令行直接获得。
SqlPackage /Action:Publish
/SourceFile:”Benday.SampleApp.Database.dacpac”
/TargetDatabaseName:BendaySampleAppDb
/TargetServerName:”demo2012util”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.