使用模拟的EPiServer属性运行单元测试失败

时间:2012-01-18 14:15:54

标签: c# nunit episerver

我正在使用一些模拟的EPiServer属性来测试我的部分代码。而当我新建这些属性时,我得到了例外。这是崩溃的线:

var englishContent = new PropertyXhtmlString {
    Name = "EnglishOperationsMessage",
    LongString = "Message content in english"};

这是生成的异常:

SetUp : System.TypeInitializationException :
The type initializer for 'EPiServer.Util.AutoCompressString' threw an exception.
----> System.IO.FileNotFoundException : Could not find file 'D:\Projects\Antenor-Management-System\Ams.Presenter.Test\bin\Debugweb.config'.
at EPiServer.Core.PropertyLongString.SetDefaultValue()
at EPiServer.SpecializedProperties.PropertyXhtmlString..ctor()
at Ams.Presenter.Test.Login.OperationsMessageTest.GetMockCollection() in OperationsMessageTest.cs: line 58
at Ams.Presenter.Test.Login.OperationsMessageTest.TestSetUp() in OperationsMessageTest.cs: line 19
--FileNotFoundException
at EPiServer.ConfigFileSettings.ᐁ()
at EPiServer.ConfigFileSettings.get_AllAppSettings()
at EPiServer.ApplicationConfiguration..ctor(String configFileName)
at EPiServer.ApplicationConfiguration..ctor(String configFileName, String rootVirtualPath)
at EPiServer.Global.get_EPConfig()
at EPiServer.Util.AutoCompressString..cctor()

如何解决这个问题的任何线索将不胜感激!请记住,这适用于EPiServer 6.42B。

2 个答案:

答案 0 :(得分:0)

AutoCompressString类的构造函数(由PropertyXhtmlString使用)在初始化期间从配置文件中查找一些值。它无法找到配置文件,因此无法初始化。

在你的情况下,它在

中寻找配置文件
D:\Projects\Antenor-Management-System\Ams.Presenter.Test\bin\Debugweb.config

该文件是否存在于该位置?

答案 1 :(得分:0)

在呈现PropertyXhtmlString的方法中,调用Global.EPConfig:

Global.EPConfig["EPfEnableFriendlyURL"]

麻烦的是EPiServer.Global在单元测试代码时没有新建。我将不得不看看它是否可以以某种方式被嘲笑。