unit testingSitecore LicenseManager

我正在尝试使用Sitecore api进行unit testing。 我在Visual Studio的解决方案中获得了一个unit testing项目(MSTest)。 我将web.config中的configSections,connectionStrings,appSettings,sitecore,log4net元素复制到我的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中设置。

引发的exception是:

 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. 

奇怪的是,当我使用“在当前上下文中运行测试”运行它时,我没有exception。 当我在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?!

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