NUnit 和 App.config
我尝试测试我的实体类,但总是失败:
System.Data.MetadataException
:
无法加载指定的元数据资源。
我认为问题出在连接字符串和App.config
中。我尝试了很多东西:添加一些东西来构建事件,更改配置名称,将配置文件复制到解决方案文件夹,项目文件夹,project_folder/bin/debug,再次更改很多名称......但它仍然不起作用。
我有一个包含 3 个项目的“AppProject”解决方案:
- “Entity”
- “WebTest”
- “MVCApp”
Entity 项目有一个 .edmx 文件和简单的 POCO 类。当我将连接字符串从 Entity/App.config 添加到 MVCApp/Web.config 时,“MVCApp”和数据库工作正常。
当我将 Entity/App.config 复制到 WebTest/App.config 时,它不起作用。我不知道问题出在哪里。
我使用 Visual NUnit,但是当我尝试在 NUnit 中打开时仍然不起作用。
我的App.config:
<connectionStrings>
<add name="UserDB"
connectionString="metadata=res://*/Model.Entity.csdl|
res://*/Model.Entity.ssdl|
res://*/Model.Entity.msl;
provider=System.Data.SqlClient;
provider connection string=
"Data Source=.\SQLExpress;
Initial Catalog=TestDB;
Integrated Security=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<!-- NOTE: line breaks in the above connection string have been inserted only
for better legibility. -->
</connectionStrings>
I try test my Entity class, but i always get a Failure:
System.Data.MetadataException
:
Unable to load the specified metadata resource.
I think the problem is in connection string and App.config
. I try a lot of stuff: add something to build events, changing config name, copy the config file into solution folder, project folder, project_folder/bin/debug, again change a lot of names... but it still doesn't work.
I have a "AppProject" solution containing 3 projects:
- "Entity"
- "WebTest"
- "MVCApp"
The Entity project has a .edmx
file, and simple POCO classes. When I add the connection string from the Entity/App.config
into MVCApp/Web.config
, the "MVCApp" and database works fine.
When I copy the Entity/App.config
into WebTest/App.config
it doesn't work. I don't know where the problem is.
I use a Visual NUnit, but when I try turn on in NUnit still doesn't work.
My App.config
:
<connectionStrings>
<add name="UserDB"
connectionString="metadata=res://*/Model.Entity.csdl|
res://*/Model.Entity.ssdl|
res://*/Model.Entity.msl;
provider=System.Data.SqlClient;
provider connection string=
"Data Source=.\SQLExpress;
Initial Catalog=TestDB;
Integrated Security=True;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<!-- NOTE: line breaks in the above connection string have been inserted only
for better legibility. -->
</connectionStrings>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看我的答案nunit 和配置
您需要告诉 nunit 配置文件的名称是什么。它默认查找namespace.config,它接缝
See my answer nunit and configs
You need to tell nunit what the name of the config file is. it looks for namespace.config by default it seams
运行 webtest 查看任务管理器中运行的处理器。我的是QTAgent32_40,通常转到C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE下的配置文件。查找名为“QTAgent32_40.exe.config”的配置文件。使用记事本对其进行编辑,然后将连接字符串复制粘贴到其中。这对我来说很有效。
Run the webtest see what processor runs in task manager. Mine was QTAgent32_40, go to the configuration file usually under C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE. Look for the config file named "QTAgent32_40.exe.config". edit it with notepad and copy paste your connection string into there. That did the trick for me.