How to initialize ConnectionStrings collection in NUnit(如何在 NUnit 中初始化 ConnectionStrings 集合)
问题描述
我想使用 NUnit 测试 ASP.NET 应用程序,但是从 NUnit GUI 运行时,WebConfigurationManager.ConnectionStrings 集合似乎是空的.
I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is empty when running from NUnit GUI.
你能告诉我如何初始化这个集合吗(可能在 [TestFixture] 的 [SetUp] 函数中)?我应该在那里复制 Web.config 吗?
Could you tell me how to initialize this collection (probably in [SetUp] function of [TestFixture])? Should I copy Web.config somethere?
谢谢!
推荐答案
如果您的单元测试程序集名为 Company.Component.Tests.dll,那么只需确保 Company.Component.Tests.dll.config 存在使用正确的连接字符串.
If you have your unit-test assembly named Company.Component.Tests.dll, then just make sure that Company.Component.Tests.dll.config is there with the proper connection string.
此外,将连接提供程序类与配置分离可能是个好主意,这样您就可以灵活地进行持久性(即:从 *.config 切换到其他内容)并更轻松地进行测试.
Additionally, it might be a good idea to decouple your connection provider class from the configuration, so that you will have flexibility in persistence (i.e.: switching from *.config to something else) and easier testing.
还可以查看NUnit 如何查找配置文件"
这篇关于如何在 NUnit 中初始化 ConnectionStrings 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 NUnit 中初始化 ConnectionStrings 集合


基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01