引用的程序集无法读取app.config

时间:2012-07-17 06:39:34

标签: c# unit-testing sitecore appsettings

我的单元测试有问题。问题是:我正在使用Sitecore。我问过的另一个问题是:Unit Testing Sitecore LicenseManager

我的问题是我得到了例外:

Test method foo.Bar.Framework.Tests.Core.UnitTest1.TestMethod1 threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Sitecore.Services.Heartbeat' threw an exception. ---> System.InvalidOperationException: Could not read Sitecore configuration.

我用dotPeek查看代码,并且函数Sitecorre.Configuration.Settings.GetSetting(“HeartbeatInterval”)抛出异常。因为它无法读取配置。 当我将相同的代码添加到我的单元测试.cs文件并调试测试时,它可以读取配置。 该设置也可在app.config

中找到

看起来引用的程序集无法读取配置并且测试本身可以。 我该如何解决这个问题?

修改

Settings.GetSetting()函数最终使用Sitecore.Configuration.ConfigReader.GetConfigNode()。该函数最终使用此函数:

private static ConfigReader GetReader()
{
    return ConfigurationManager.GetSection("sitecore") as ConfigReader;
}

所以... 为什么引用的dll不能通过ConfigurationManager读取app.config?

1 个答案:

答案 0 :(得分:0)

原来是* .testsettings。 当我在我的电脑上运行它时它工作但在构建服务器上它没有。原来我只需提交* .testsettings并包含/ testsettings参数