2012-07-16 46 views
2

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

我试图运行测试是:

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

我定义我的app.config文件datafolder和的ConnectionStrings我的核心,掌握和网络数据库也被设置在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 IS。当我将Settings.GetSetting(“HeartbeatInterval”)添加到我的快速监视中时,它会返回正确的值。 这就像sitecore.kernel无法访问app.config ?!

回答

1

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