最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

app config - How do I set up a configuration file to hold connection strings for a unit test? - Stack Overflow

programmeradmin5浏览0评论

I have the following unit test (simplified).

using Microsoft.VisualStudio.TestTools.UnitTesting;


[TestClass]
public class UnitTest1
{
    
    [TestMethod]
    public void T001b_BasePairs()
    {
        var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        Console.WriteLine($"Configuration file path: {config.FilePath}");
       
        var connectionStrings = ConfigurationManager.ConnectionStrings;
        var connectionStringName = connectionStrings[0].Name;
        Console.WriteLine($"Connection string name: {connectionStringName}");`

In the debugger I see UnitTestProjectCore\bin\Debug\net8.0-windows\testhost.dll

I expected the code to find connectionstrings from my app.config in the connectionStrings section.

发布评论

评论列表(0)

  1. 暂无评论