2013-03-06 54 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