使用模拟的 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 的。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AutoCompressString 类的构造函数(由 PropertyXhtmlString 使用)在初始化期间从配置文件中查找一些值。它找不到配置文件,因此无法初始化。
中查找配置文件?
在您的情况下,它在该位置是否存在该文件
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
Does that file exist in that location?
在呈现 PropertyXhtmlString 的方法中,对 Global.EPConfig 进行了调用:
问题在于,在对代码进行单元测试时,EPiServer.Global 并未更新。我得看看是否可以以某种方式模拟它。
In the method that renders the PropertyXhtmlString a call is made to Global.EPConfig:
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.