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

发布于 2024-12-28 04:01:32 字数 1266 浏览 1 评论 0原文

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

I am using some mocked EPiServer properties to test part of my code. And it is while I new up these properties I get the exception. This is the line that crashes:

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

And here is the exception generated:

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()

Any clues how to solve this would be greatly appreciated! Bear in mind, this is for EPiServer 6.42B.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮倦 2025-01-04 04:01:32

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

中查找配置文件?

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

在您的情况下,它在该位置是否存在该文件

The constructor for the AutoCompressString class (used by the PropertyXhtmlString) looks for some values from the config file during initialisation. It can't find the config file so it's failing to initialise.

In your case its looking for the config file in

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

Does that file exist in that location?

_失温 2025-01-04 04:01:32

在呈现 PropertyXhtmlString 的方法中,对 Global.EPConfig 进行了调用:

Global.EPConfig["EPfEnableFriendlyURL"]

问题在于,在对代码进行单元测试时,EPiServer.Global 并未更新。我得看看是否可以以某种方式模拟它。

In the method that renders the PropertyXhtmlString a call is made to Global.EPConfig:

Global.EPConfig["EPfEnableFriendlyURL"]

The trouble is that EPiServer.Global is not newed up while unit testing the code. I will have to see if it can be mocked up somehow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文