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:inetpubbinSitecore.Nexus.dll' or one of its dependencies. The system cannot find the file specified.=== Pre-bind state information === LOG: User = NT AUTHORITYSYSTEM LOG: Where-ref bind. Location = c:inetpubbinSitecore.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:BuildAgenttempbuildTmpSYSTEM_E1259 2012-07-16 14_42_19Outfoo.bar.Framework.Tests.Core.DLL.config LOG: Using host configuration file: LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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的本地路径。 在我这样做之后,我解决了最初的问题
上述就是C#学习教程:unit testingSitecore LicenseManager分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1008353.html