所以,我是Sitecore的新手,并不确定如何启用它。我在服务器A上安装了Sitecore,并且我正在从服务器B运行单元测试。但是,我遇到了通过其API(在Sitecore.Kernel.dll中)远程访问Sitecore的问题。
问题:有没有办法将其设置为针对来自其他服务器的Sitecore安装执行单元测试(理想情况下通过dll中的Sitecore API)?
参考文献:
示例测试代码:
[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:
答案 0 :(得分:3)
答案 1 :(得分:2)
您描述的架构是不可能的,因为Sitecore API无法调用“到另一台服务器”,至少不像您在此处所做的那样。您链接到的文章介绍了如何设置独立于使用Sitecore的Web服务器运行的单元测试项目。即它实际上会在Web上下文之外运行Sitecore。这是可能的,但可能需要一些工作。部分必需的设置是将sitecore许可证放在运行单元测试的服务器上,并将App.config中的dataFolder指向该位置。
另一种选择是use a web harness to run your unit tests,但这可能不是您正在寻找的自动化解决方案。此解决方案也是available on GitHub。我们有一段时间的想法是通过Web服务调用远程测试工具。这将是实现从远程服务器运行测试的目标的一种方法。