我试图与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);
我定义我的datafolder app.config文件中和的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?