我从标准Sitecore.Kernel
和Sitecore.Nexus
开始。 Sitecore在此处提供了非常具有描述性的错误消息,因此我也添加了DependencyInjection
。它带来了很多依赖项,并且它们没有显示在config belo中。如您所见,我使用*.NoReferences
版本的Sitecore软件包来控制依赖项。
<packages>
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
<package id="Sitecore.FakeDb" version="1.2.2" targetFramework="net452" />
<package id="Sitecore.Kernel.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Nexus.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
</packages>
之后我卡住了。我收到的错误并未提供错误信息:
System.NullReferenceException : Object reference not set to an instance of an object.
at Sitecore.Configuration.DefaultFactory.CreateType(XmlNode configNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
at Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert)
at Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, Boolean assert)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name, Boolean assert)
at Sitecore.Configuration.DefaultFactory.GetDatabase(String name)
at Sitecore.Configuration.Factory.GetDatabase(String name)
at Sitecore.Data.Database.GetDatabase(String databaseName)
at Sitecore.FakeDb.Db..ctor(String databaseName)
at Sitecore.FakeDb.Db..ctor()
at SitecoreTests.Class1.HowToCreateSimpleItem() in C:\prog\temp\SitecoreTests\SitecoreTests\Class1.cs:line 17
那么,简单的假数据库测试工作缺少什么呢?
答案 0 :(得分:7)
在完整Sitecore.Kernel
中尝试所有被引用为依赖项的软件包后,我以此设置结束:
<packages>
<package id="Lucene.Net" version="3.0.3" targetFramework="net452" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
<package id="Sitecore.FakeDb" version="1.2.2" targetFramework="net452" />
<package id="Sitecore.Kernel.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Logging.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Nexus.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
</packages>
现在很清楚,Sitecore无法在没有Sitecore.Logging
的情况下启动。
Lucene.Net
也需要,但错误更有帮助:
System.IO.FileNotFoundException:无法加载文件或程序集 &#39; Lucene.Net,版本= 3.0.3.0,文化=中立, 公钥= 85089178b9ac3181&#39;或其中一个依赖项。该 系统找不到指定的文件。
P.S。如果您不关心引用额外的DLL,则只需添加两个软件包即可让您进行测试工作 - Sitecore.Nexus
(不.NoReferences
)和Microsoft.Extensions.DependencyInjection
答案 1 :(得分:1)
以下是我在Fortis单元测试项目中使用的软件包列表:
<packages>
<package id="AutoFixture" version="3.0.1" targetFramework="net452" />
<package id="Lucene.Net" version="3.0.3" targetFramework="net452" />
<package id="Microsoft.AspNet.Mvc" version="3.0.50813.1" targetFramework="net452" />
<package id="Microsoft.AspNet.Razor" version="1.0.20105.408" targetFramework="net452" />
<package id="Microsoft.AspNet.WebPages" version="1.0.20105.408" targetFramework="net452" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net452" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
<package id="NSubstitute" version="1.10.0.0" targetFramework="net452" />
<package id="RazorGenerator.Mvc" version="2.4.7" targetFramework="net452" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
<package id="Sitecore.Abstractions.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Analytics.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Buckets.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.ContentSearch.Linq.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.ContentSearch.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.FakeDb" version="1.1.3" targetFramework="net452" />
<package id="Sitecore.FakeDb.AutoFixture" version="1.1.3" targetFramework="net452" />
<package id="Sitecore.FakeDb.NSubstitute" version="1.1.3" targetFramework="net452" />
<package id="Sitecore.FakeDb.Serialization" version="1.1.3" targetFramework="net452" />
<package id="Sitecore.Kernel.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Logging.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="Sitecore.Nexus.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
<package id="System.Collections" version="4.0.11" targetFramework="net452" />
<package id="System.Collections.Concurrent" version="4.0.12" targetFramework="net452" />
<package id="System.ComponentModel" version="4.0.1" targetFramework="net452" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net452" />
<package id="System.Globalization" version="4.0.11" targetFramework="net452" />
<package id="System.Linq" version="4.1.0" targetFramework="net452" />
<package id="System.Linq.Expressions" version="4.1.0" targetFramework="net452" />
<package id="System.Reflection" version="4.1.0" targetFramework="net452" />
<package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net452" />
<package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net452" />
<package id="System.Threading" version="4.0.11" targetFramework="net452" />
<package id="System.Threading.Tasks" version="4.0.11" targetFramework="net452" />
<package id="WebActivatorEx" version="2.0.3" targetFramework="net452" />
<package id="xunit" version="2.1.0" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net452" />
<package id="xunit.assert" version="2.1.0" targetFramework="net452" />
<package id="xunit.core" version="2.1.0" targetFramework="net452" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net452" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net452" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net452" />
</packages>
另外,请确保为您的配置设置了/App_Config/Include
文件夹:Here is the Fortis one