Skip to content
sergeyshushlyapin edited this page Nov 11, 2014 · 3 revisions

You can use the Sitecore.FakeDb.Sites.FakeSiteContext class to easily create an instance of the Sitecore.Sites.SiteContext and pass it to the Sitecore.Sites.SiteContextSwitcher. Please note that you do not need to register the fake site context in the configuration file.

[Fact]
public void HowToSwitchContextSite()
{
  // create a fake site context
  var fakeSite = new Sitecore.FakeDb.Sites.FakeSiteContext(
    new Sitecore.Collections.StringDictionary
      {
        { "name", "website" }, { "database", "web" }
      });

  // switch the context site
  using (new Sitecore.Sites.SiteContextSwitcher(fakeSite))
  {
    Xunit.Assert.Equal("website", Sitecore.Context.Site.Name);
    Xunit.Assert.Equal("web", Sitecore.Context.Site.Database.Name);
  }
}
Clone this wiki locally