Skip to content
sergeyshushlyapin edited this page Jun 9, 2015 · 14 revisions

Include files

Sitecore.FakeDb automatically includes configuration files located in the <test_project>\App_Config\Include folder. You can read more about the include files in the following post:
ALL ABOUT WEB.CONFIG INCLUDE FILES WITH THE SITECORE ASP.NET CMS | JOHN WEST | SITECORE BLOG.

Adding include files to a Project

  1. In a unit test project, create a new App_Config\Include\MyUnitTests.config file which contains the required configuration, for instance, the MyApp.Enabled setting:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="MyApp.Enabled" value="true" />
    </settings>
  </sitecore>
</configuration>
  1. In a unit test, read the setting using the regular Sitecore.Configuration.Settings class:
[Fact]
public void ShouldReadMyAppEnabledSetting()
{
  var enabled =
    Sitecore.Configuration.Settings.GetBoolSetting("MyApp.Enabled", false);
  Assert.True(enabled);
}

Configuring NCrunch

Starting from version 0.26.0 FakeDb supports Sitecore include files. NCrunch uses a concept called Workspaces, which means all the files required to run a test must be copied to a workspace.

In order to run unit tests with NCrunch, in the NCrunch Configuration window, select the tests project and configure the following settings:

As a result, the <test_project>.ncrunchproject file should have the following settings:

<CopyReferencedAssembliesToWorkspace>true</CopyReferencedAssembliesToWorkspace>
<AdditionalFilesToInclude>license.xml;App_Config\**.*</AdditionalFilesToInclude>

Important

You may need to restart NCrunch to apply the configuration changes

Read more about the configuration on the NCrunch documentation website:

Troubleshooting

Cannot find the App_Config\FieldTypes.config file

The error:

*** Failures ***

Exception
System.IO.DirectoryNotFoundException: System.IO.DirectoryNotFoundException :  
Could not find a part of the path 'C:\Users\admin\AppData\Local\NCrunch\296\4\  
app_config\fieldtypes.config'.

By default, Sitecore FakeDb assumes that the location of the App_Config folder is the test project root. Taking into account that the default output paths for the Class Library project is bin\Debug\ (bin\Release), the following relative path is used for the FieldTypes setting:

<fieldTypes>
  <sc.include file="..\..\App_Config\FieldTypes.config" />
</fieldTypes>

Please ensure that the path is correct.

The same stands for the LicensePath setting:

<setting name="LicenseFile" value="..\..\license.xml" />
Clone this wiki locally