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 集合
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
