I am trying to use sitecore Fake DB for unit testing.
My custom config look like this
<sitecore>
<settings>
<setting name="test1" value="value1" />
<setting name="test2" value="value2" />
</settings>
Constants:
public static class Constants
{
public constant string SettingsTest1 = "test1";
public constant string SettingsTest2 = "test2";
}
Class:
Public class Implementation
{
private static string _const1 = Sitecore.configuration.Settings.GetSetting(Constants.SettingsTest1);
private static string _const2 = Sitecore.configuration.Settings.GetSetting(Constants.SettingsTest2);
public string method()
{
var key = _const1;
//Do something
}
}
While writing unit tests, I am trying to use this to assign the value for settings - https://github.com/sergeyshushlyapin/Sitecore.FakeDb/wiki/Settings and when I write unit test for the method, the settings value is always null because it is trying to get the value from config file. How can I write unit test for the method to use the settings value from fake db instead of config file? Thanks!
SettingsSwitcher
. sitecore.stackexchange.com/a/3006/73