【问题标题】:Unit Testing Sitecore LicenseManager单元测试 Sitecore LicenseManager
【发布时间】:2012-07-23 15:52:23
【问题描述】:

我正在尝试使用 Sitecore api 进行单元测试。 我在 Visual Studio 的解决方案中获得了一个单元测试项目 (MSTest)。我将 configSections、connectionStrings、appSettings、sitecore、log4net 元素从我的 web.config 复制到了我的 app.config。

我要运行的测试是:

Sitecore.Context.Database = Factory.GetDatabase("master");
Item a = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
Assert.IsFalse(a.HasChildren);

我在 app.config 文件中定义了我的数据文件夹,并且我的核心、主数据库和 Web 数据库的连接字符串也在 app.config 中设置。

抛出的异常是:

System.TypeInitializationException: The type initializer for 'Sitecore.SecurityModel.License.LicenseManager' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'file:///c:\inetpub\bin\Sitecore.Nexus.dll' or one of its dependencies. The system cannot find the file specified.=== Pre-bind state information ===
LOG: User = NT AUTHORITY\SYSTEM
LOG: Where-ref bind. Location = c:\inetpub\bin\Sitecore.Nexus.dll
LOG: Appbase = file:///C:/BuildAgent/temp/buildTmp/SYSTEM_E1259 2012-07-16 14_42_19/Out
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\BuildAgent\temp\buildTmp\SYSTEM_E1259 2012-07-16 14_42_19\Out\foo.bar.Framework.Tests.Core.DLL.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///c:/inetpub/bin/Sitecore.Nexus.dll.

奇怪的是,当我使用“在当前上下文中运行测试”运行它时,我没有遇到异常。当我在 TeamCity 或使用“在解决方案中运行所有测试”运行它时,我得到了异常。显然该文件不在 c:/inetpub/bin/Sitecore.Nexus.dll 中

谁能告诉我我做错了什么?

编辑

当我添加一个 HttpSimulator 时,错误消失了。 发生另一个错误:

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.

正在读取的设置是“HeartbeatInterval”,这个设置在我的 app.config 中。当我将 Settings.GetSetting("HeartbeatInterval") 添加到我的快速手表时,它会返回正确的值。 好像sitecore.kernel不能访问app.config?!

【问题讨论】:

    标签: c# unit-testing sitecore


    【解决方案1】:

    正如您在“编辑”下方看到的那样:我没有使用 HttpContext,我可以在其中设置 webroot 的本地路径。在我这样做之后,我解决了最初的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      相关资源
      最近更新 更多