Skip to content
sergeyshushlyapin edited this page May 25, 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

To run tests that require include files with NCrunch, in the <test_project>.ncrunchproject file, configure the following settings:

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

Read more about the configuration on the NCrunch documentation website:

Clone this wiki locally