简体   繁体   English

使用Web.config代替app.config在ASP.NET MVC应用程序中进行集成测试

[英]Use Web.config instead of app.config for integration test in ASP.NET MVC app

I have a web app which contains a project called EnterpriseInfrastructure with a class called Pager. 我有一个Web应用程序,其中包含一个名为EnterpriseInfrastructure的项目以及一个名为Pager的类。 This class simply creates a PagerClient specified by a WSDL which is linked in a service reference. 此类仅创建由服务引用中链接的WSDL指定的PagerClient。

When I run the application in production, the PagerClient is initialized with settings from the Web.config from the application. 当我在生产环境中运行应用程序时,将使用应用程序中Web.config中的设置来初始化PagerClient。 That works great. 效果很好。 But when I try to perform an integration test to make sure we have the correct endpoints specified in the Web.config, an exception is thrown that the configuration file is not found. 但是,当我尝试执行集成测试以确保我们在Web.config中指定了正确的端点时,抛出了一个异常,即找不到配置文件。 The service is looking for the app.config--not the web.config. 该服务正在寻找app.config而不是web.config。

Is there a way to run the test in the same way as our web app, so that the web.config is called upon rather than the app.config? 有没有一种以与我们的Web应用程序相同的方式运行测试的方法,以便调用web.config而不是app.config?

I am using [DeploymentItem(@"../../../UI/Web.config")] to copy the web.config from our actual project. 我正在使用[DeploymentItem(@"../../../UI/Web.config")]从我们的实际项目中复制web.config。

Your unit test project also needs the web.config in order to run the test. 您的单元测试项目还需要web.config才能运行测试。 I have typically done this with other app.config files by doing Add Existing Item, navigate to the web.config in the other project, and then press the little down arrow on the Add button and choose Add as Link 我通常使用其他app.config文件来完成此操作,方法是添加现有项,导航到其他项目中的web.config,然后按“ Add按钮上的向下小箭头,然后选择“ Add as Link

This way any changes you make in the main config file will also be used by the test project... you won't need to manage two config files. 这样,您在主配置文件中所做的任何更改也将被测试项目使用...您将不需要管理两个配置文件。

EDIT: This appears to only work with app.config files, I couldn't get my test project to ignore the app.config and use a linked web.config 编辑:这似乎仅适用于app.config文件,我无法让我的测试项目忽略app.config并使用链接的web.config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC 项目 web.config 和 app.config 文件 - ASP.NET MVC project web.config and app.config files ASP.NET MVC应用程序从app.config(而不是web.config)获取绑定重定向设置 - ASP.NET MVC application getting binding redirect settings from app.config, not web.config WCF客户端实现,有办法将服务和端点详细信息保留在类库app.config中,而不是在ASP.NET MVC应用程序中保留在web.config中 - WCF Client Implementation, is there way to keep services and end-point detail in class library app.config rather then web.config for ASP.NET MVC app TeamCity中的MSBuild步骤考虑app.config而不是ASP.NET WEB API项目的web.config,导致警告MSB3247 - MSBuild step in TeamCity considers app.config instead of web.config for ASP.NET WEB API project resulting in warning MSB3247 从 .NET 中的 app.config 或 web.config 读取设置 - Reading settings from app.config or web.config in .NET App.config或Web.config - App.config or Web.config 将TableAdapter XSD更改为使用Web.config连接字符串而不是App.config - Change TableAdapter XSD to use Web.config Connection String Instead of App.config ASP.NET 5 MVC 6中的web.config - web.config in ASP.NET 5 MVC 6 在ASP.NET中访问app.config - Accessing app.config in ASP.NET IIS 6无法识别ASP.NET MVC 4 Web应用程序中的〜/ Views / web.config - IIS 6 doesn't recognize ~/Views/ web.config in ASP.NET MVC 4 web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM