NUnit 和 App.config

发布于 2024-10-26 16:47:08 字数 1483 浏览 2 评论 0原文

我尝试测试我的实体类,但总是失败:

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=
                                  &quot;Data Source=.\SQLExpress;
                                  Initial Catalog=TestDB;
                                  Integrated Security=True;
                                  MultipleActiveResultSets=True&quot;"
       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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯℡ 2024-11-02 16:47:08

查看我的答案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

倒数 2024-11-02 16:47:08

运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文