Deb*_*yay 0 c# unit-testing sitecore sitecore8
我想访问MS Test Project中的sitecore上下文.我正在使用Sitecore 8.1和使用VS 2005的MS测试项目(Framework:4.5.2)我按照这里的一些说明http://getfishtank.ca/blog/unit-testing-in-sitecore-with-context-和APP-配置
所以我在单元测试项目中拥有所有必需的DLLS和sitecore配置文件.
我的代码如下:
[TestMethod]
public void TestMethod1()
{
State.HttpRuntime.AppDomainAppPath = Directory.GetCurrentDirectory();
string dataFolder = Sitecore.Configuration.Settings.DataFolder;
string licenseFile = Settings.LicenseFile;
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var home = db.GetItem("/sitecore/content/");
Assert.AreEqual(5, 5);
}
Run Code Online (Sandbox Code Playgroud)
现在我收到以下错误:
Result StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Sitecore.Reflection.ReflectionUtil.LoadAssembly(String name)
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.SecurityModel.License.LicenseManager.GetSnapshotData(Guid instance)
at Sitecore.SecurityModel.License.LicenseManager.UpdateSnapshot()
at Sitecore.SecurityModel.License.LicenseManager..cctor()
--- End of inner exception stack trace ---
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 MSUnitTestSitecore.UnitTest1.TestMethod1() in C:\Devarea_Debajit\MyProjects\MSUnitTestSitecore\MSUnitTestSitecore\UnitTest1.cs:line 20
Result Message:
Test method MSUnitTestSitecore.UnitTest1.TestMethod1 threw exception:
System.TypeInitializationException: The type initializer for 'Sitecore.SecurityModel.License.LicenseManager' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Devarea_Debajit\MyProjects\MSUnitTestSitecore\MSUnitTestSitecore\bin\Debug\Sitecore.Nexus.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
Run Code Online (Sandbox Code Playgroud)
我检查了许可文件路径及其正确.我也加了这个
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
Run Code Online (Sandbox Code Playgroud)
谁能帮我 ?
为了使用Sitecore.Context进行单元测试,您需要将App_Config中的所有Sitecore配置复制到您的单元测试项目中,并复制web.config
并重命名为app.config
.您可以在此处找到更详细的演练:http://getfishtank.ca/blog/unit-testing-in-sitecore-with-context-and-app-config
不过我建议您使用Sitecore FakeDb来运行单元测试.这将允许您更好地隔离测试,而不依赖于runnign Sitecore实例/数据库,并允许执行更多受控测试,因为数据不会因更新而不断变化.
归档时间: |
|
查看次数: |
2096 次 |
最近记录: |