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

本文关键字:运行 单元测试 失败 属性 EPiServer 模拟 | 更新日期: 2023-09-27 18:20:34

我正在使用一些模拟的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.

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

AutoCompressString类的构造函数(由PropertyXhtmlString使用)在初始化期间从配置文件中查找一些值。它找不到配置文件,所以初始化失败。

在您的情况下,它正在中查找配置文件

D:'Projects'Antenor-Management-System'Ams.Presenter.Test'bin'Debugweb.config

那个位置存在那个文件吗?

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

Global.EPConfig["EPfEnableFriendlyURL"]

问题是EPiServer.Global在单元测试代码时没有更新。我得看看它是否能以某种方式被模仿。