-
Notifications
You must be signed in to change notification settings - Fork 36
Settings
sergeyshushlyapin edited this page Nov 11, 2014
·
2 revisions
Important:
If you are running Sitecore 7.5 or higher, consider using
Sitecore.Abstractions.ISettingsinterface from theSitecore.Abstractionsassembly.
In some cases you may prefer to use a setting instead of a dependency injected
in your code via a constructor or property. The code below instantiates the new Db
context and sets MySetting setting value to 1234. Please note that the
setting is not defined explicitly in the App.config file, but it
is accessible via the Sitecore.Configuration.Settings class and can be used in the unit
tests:
[Fact]
public void HowToConfigureSettings()
{
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
// set the setting value in unit test using db instance
db.Configuration.Settings["MySetting"] = "1234";
// get the setting value in your code using regular Sitecore API
var value = Sitecore.Configuration.Settings.GetSetting("MySetting");
Xunit.Assert.Equal("1234", value);
}
}