2013-03-06 53 views
0

所以,我是Sitecore的新手,并不确切知道如何启用它。我在服务器A上安装了Sitecore,并且正在运行服务器B的单元测试。但是,我遇到了通过它们的API远程访问Sitecore的问题(在Sitecore.Kernel.dll中)。单元测试Sitecore从不同服务器安装

  1. 的Sitecore的安装已正确设置,我可以访问CMS管理,我可以添加项目,我可以看到数据库等
  2. 从下面的堆栈跟踪,我可以看到它在寻找数据文件夹(服务器B上不存在,它是服务器A上的Sitecore安装的一部分)。
  3. 许可证存储在这个目录(数据文件夹),因为失败的调用代码被称为LicenseManager,我猜测有些东西正试图验证许可证。
  4. 我已经在下面的参考链接中指定了我的单元测试。这有我的设置的所有具体细节(但随意提问)。

问:有(最好是通过DLL中的Sitecore的API)的方式来设置此,从不同的服务器执行针对Sitecore的安装单元测试?

参考文献:

实施例试验编号:

[TestMethod] 
    public void GetItemTest() 
    { 
     var database = global::Sitecore.Configuration.Factory.GetDatabase("master"); 
     Assert.IsNotNull(database); 

     var item = database.GetItem("/sitecore/content"); 
     Assert.IsNotNull(item); 
     Assert.AreEqual("content", item.Name); 
    } 

例外:

System.TypeInitializationException was unhandled by user code 
    Message=The type initializer for 'Sitecore.SecurityModel.License.LicenseManager' threw an exception. 
    Source=Sitecore.Kernel 
    TypeName=Sitecore.SecurityModel.License.LicenseManager 
    StackTrace: 
     at Sitecore.SecurityModel.License.LicenseManager.DemandRuntime(Boolean acceptExpress) 
     at Sitecore.Data.Managers.ItemManager.get_Provider() 
     at Sitecore.Data.Managers.ItemManager.GetItem(String itemPath, Language language, Version version, Database database) 
     at Sitecore.Data.Database.GetItem(String path) 
     at Spacely.Web.Tests.Services.SitecoreServiceTest.GetItemTest() in C:\Users\foo\src\spacely\Spacely.Web.Tests\Services\SitecoreServiceTest.cs:line 25 
    InnerException: System.Reflection.TargetInvocationException 
     Message=Exception has been thrown by the target of an invocation. 
     Source=mscorlib 
     StackTrace: 
      at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType) 
      at System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct signature, RuntimeType declaringType) 
      at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
      at System.Reflection.ConstructorInfo.Invoke(Object[] parameters) 
      at Sitecore.Reflection.ReflectionUtil.CreateObject(Type type, Object[] parameters) 
      at Sitecore.Reflection.ReflectionUtil.CreateObject(String assembly, String className, Object[] parameters) 
      at Sitecore.Reflection.ReflectionUtil.CreateObject(String typeName, Object[] parameters) 
      at Sitecore.Reflection.Nexus.GetApi[T](String typeName, T& api) 
      at Sitecore.Reflection.Nexus.get_LicenseApi() 
      at Sitecore.SecurityModel.License.LicenseManager.GetSnapshotData(Guid instance) 
      at Sitecore.SecurityModel.License.LicenseManager.UpdateSnapshot() 
      at Sitecore.SecurityModel.License.LicenseManager..cctor() 
     InnerException: System.ArgumentException 
      Message=The directory name \data is invalid. 
      Source=System 
      StackTrace: 
       at System.IO.FileSystemWatcher.set_Path(String value) 
       at Sitecore.IO.FileWatcher.InitializeWatcher(String filter, String folder) 
       at Sitecore.IO.FileWatcher..ctor(String folder, String filter) 
       at Sitecore.SecurityModel.License.LicenseWatcher..ctor() 
       at Sitecore.Nexus.Licensing.NexusLicenseApi.() 
       at Sitecore.Nexus.Licensing.NexusLicenseApi..ctor() 
      InnerException: 

回答

2

您描述的体系结构是不可能的,因为Sitecore API无法调用“到另一台服务器”,至少不是您在这里做的方式。您链接的文章介绍了如何设置一个单独测试项目,该项目可以独立于使用Sitecore的Web服务器运行。即它实际上会在web上下文之外运行Sitecore。这是可能的,但可以采取一些工作。部分必要的设置是在运行单元测试的服务器上放置sitecore许可证,并将AppForm中的dataFolder指向该位置。

另一种方法是use a web harness to run your unit tests,但这可能不是您正在寻找的自动化解决方案。该解决方案也是available on GitHub。我们有一段时间的想法是通过Web服务调用远程测试工具。这将是实现从远程服务器运行测试的目标的一种方法。

+0

的部分是什么你提到为我工作!关键步骤是在该文件中添加数据目录和许可证副本,并将其部署到正确的测试位置(实际执行测试的位置)。有趣的是,我实际上已经在我的桌上得到了答案......对于任何感兴趣的人,请查看John West的专业Sitecore开发书。我的解决方案在第8章 - 自动测试第338页 - “考虑在没有HTTP上下文的情况下调用Sitecore API”(具体而言,我错过了第10步和第11步)。嘘。 – longda 2013-03-06 23:42:32