示例#1
0
    public virtual SiteDefinition GetSiteDefinition(Item item)
    {
      Assert.ArgumentNotNull(item, nameof(item));

      var itemSiteDefinitionsProvider = new ItemSiteDefinitionsProvider();
      var siteDefinition = itemSiteDefinitionsProvider.GetContextSiteDefinition(item);
      if (siteDefinition != null)
      {
        return siteDefinition;
      }
      var configSiteDefinitionsProvider = new ConfigurationSiteDefinitionsProvider();
      return configSiteDefinitionsProvider.GetContextSiteDefinition(item);
    }
    public void SiteDefinitions_ShouldReturnSiteDefinitionFromTheItemList(Db db, ItemSiteDefinitionsProvider provider, SiteDefinitionsProviderBase baseProvider)
    {
      db.Add(new DbItem("site1", ID.NewID, Templates.Site.ID));
      db.Add(new DbItem("site2", ID.NewID, Templates.Site.ID));
      db.Add(new DbItem("site3", ID.NewID, Sitecore.TemplateIDs.StandardTemplate));
      var fakeSite = new FakeSiteContext(new StringDictionary
      {
        {"displayMode", "normal"},
        {"rootPath", "/sitecore/content"},
        { "name", "site1"}
      }) as SiteContext;

      using (new SiteContextSwitcher(fakeSite))
      {
        var results = provider.SiteDefinitions;
        results.Count().ShouldBeEquivalentTo(2);
        results.Should().As<IEnumerable<SiteDefinition>>();
      }
    }
 public void SiteDefinitions_ContextDoesNotExists_ShouldReturnNull(Db db, ItemSiteDefinitionsProvider provider)
 {
   db.GetItem(Sitecore.ItemIDs.ContentRoot).Delete();
   provider.SiteDefinitions.Should().BeNull();
 }