Exemplo n.º 1
0
        public void GetSettingsItem_ShouldReturnSettingItem(string settingName, [Frozen] Item contextItem, [Substitute] SiteContext context, Db db, string definitionItemName)
        {
            var provider      = new SiteSettingsProvider(context);
            var settingItemId = ID.NewID;
            var definitionId  = ID.NewID;

            db.Add(new DbItem(definitionItemName, definitionId)
            {
                new DbItem(SiteSettingsProvider.SettingsRootName)
                {
                    new DbItem(DatasourceProvider.DatasourceSettingsName, ID.NewID, Templates.SiteSettings.ID)
                    {
                        new DbItem(settingName, settingItemId)
                    }
                }
            });
            var definitionItem = db.GetItem(definitionId);
            var setting        = db.GetItem(settingItemId);

            context.GetSiteDefinition(Arg.Any <Item>()).Returns(new SiteDefinition {
                Item = definitionItem
            });
            var settingItem = provider.GetSetting(contextItem, DatasourceProvider.DatasourceSettingsName, settingName);

            settingItem.ID.ShouldBeEquivalentTo(setting.ID);
        }
Exemplo n.º 2
0
        public void GetSettingsItem_SiteDefinitionDoesNotExists_ShouldReturnNull(string settingName, [Frozen] Item contextItem, [Substitute] SiteContext context, Db db, string definitionItemName)
        {
            var provider = new SiteSettingsProvider(context);

            context.GetSiteDefinition(Arg.Any <Item>()).Returns((SiteDefinition)null);
            var settingItem = provider.GetSetting(contextItem, DatasourceProvider.DatasourceSettingsName, settingName);

            settingItem.Should().BeNull();
        }
Exemplo n.º 3
0
 public void GetSiteDefinition_ItemInSiteHierarcy_ShouldReturnHierarchicalSiteDefinition(SiteContext siteContext, DbItem item , Db db, string siteName)
 {
   var siteDefinitionId = ID.NewID;
   db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) {item});
   var contextItem = db.GetItem(item.ID);
   var definitionItem = db.GetItem(siteDefinitionId);
   var siteDefinition = siteContext.GetSiteDefinition(contextItem);
   siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
 }
Exemplo n.º 4
0
    public void GetSiteDefinition_ProviderReturnsEmpty_ShouldReturnNull(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName)
    {
      db.Add(item);
      var contextItem = db.GetItem(item.ID);

      provider.GetContextSiteDefinition(Arg.Any<Item>()).Returns((SiteDefinition)null);

      var siteContext = new SiteContext(provider);
      siteContext.GetSiteDefinition(contextItem).ShouldBeEquivalentTo(null);
    }
Exemplo n.º 5
0
        public void GetSiteDefinition_ProviderReturnsEmpty_ShouldReturnNull(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName)
        {
            db.Add(item);
            var contextItem = db.GetItem(item.ID);

            provider.GetContextSiteDefinition(Arg.Any <Item>()).Returns((SiteDefinition)null);

            var siteContext = new SiteContext(provider);

            siteContext.GetSiteDefinition(contextItem).Should().BeNull();
        }
Exemplo n.º 6
0
        public void GetSiteDefinition_ItemInSiteHierarcy_ShouldReturnHierarchicalSiteDefinition(SiteContext siteContext, DbItem item, Db db, string siteName)
        {
            var siteDefinitionId = ID.NewID;

            db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID)
            {
                item
            });
            var contextItem    = db.GetItem(item.ID);
            var definitionItem = db.GetItem(siteDefinitionId);
            var siteDefinition = siteContext.GetSiteDefinition(contextItem);

            siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
        }
Exemplo n.º 7
0
    public virtual SiteInfo GetCurrentSiteInfo(Item contextItem)
    {
      var context = new SiteContext();

      var currentDefinition = context.GetSiteDefinition(contextItem);
      if (currentDefinition == null)
      {
        {
          return null;
        }
      }

      var siteInfo = Factory.GetSiteInfo(currentDefinition.Name);
      return siteInfo;
    }
Exemplo n.º 8
0
        public virtual SiteInfo GetCurrentSiteInfo(Item contextItem)
        {
            var context = new SiteContext();

            var currentDefinition = context.GetSiteDefinition(contextItem);

            if (currentDefinition == null)
            {
                {
                    return(null);
                }
            }

            var siteInfo = Factory.GetSiteInfo(currentDefinition.Name);

            return(siteInfo);
        }
Exemplo n.º 9
0
    public void GetSiteDefinition_ProviderReturnsDefinition_ShouldReturnDefinition(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName)
    {
      var siteDefinitionId = ID.NewID;
      db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) { item });
      var definitionItem = db.GetItem(siteDefinitionId);

      var definition = new SiteDefinition();
      definition.Item = definitionItem;
      provider.GetContextSiteDefinition(Arg.Any<Item>()).Returns(definition);

      var siteContext = new SiteContext(provider);

      var contextItem = db.GetItem(item.ID);
      var siteDefinition = siteContext.GetSiteDefinition(contextItem);

      siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
    }
Exemplo n.º 10
0
    public void GetSiteDefinition_ItemOutsideSiteHierarcy_ShouldReturnContextSiteDefinition(SiteContext siteContext, DbItem item, Db db, string siteName)
    {
      var siteDefinitionId = ID.NewID;
      var home = new DbItem("home", ID.NewID);
      db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID) { home });
      var definitionItem = db.GetItem(siteDefinitionId);

      db.Add(item);
      var contextItem = db.GetItem(item.ID);

      var fakeSite = new Sitecore.FakeDb.Sites.FakeSiteContext(new Sitecore.Collections.StringDictionary { { "name", siteName }, { "database", db.Database.Name }, { "rootPath", "/sitecore/content/" + siteName }, { "startItem", "/home" } });
      using (new Sitecore.Sites.SiteContextSwitcher(fakeSite))
      {
        var siteDefinition = siteContext.GetSiteDefinition(contextItem);
        siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
      }
    }
Exemplo n.º 11
0
        public void GetSiteDefinition_ProviderReturnsDefinition_ShouldReturnDefinition(ISiteDefinitionsProvider provider, DbItem item, Db db, string siteName)
        {
            var siteDefinitionId = ID.NewID;

            db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID)
            {
                item
            });
            var definitionItem = db.GetItem(siteDefinitionId);

            var definition = new SiteDefinition();

            definition.Item = definitionItem;
            provider.GetContextSiteDefinition(Arg.Any <Item>()).Returns(definition);

            var siteContext = new SiteContext(provider);

            var contextItem    = db.GetItem(item.ID);
            var siteDefinition = siteContext.GetSiteDefinition(contextItem);

            siteDefinition.Item.ID.Should().BeEquivalentTo(definitionItem.ID);
        }
Exemplo n.º 12
0
        public static IEnumerable <Language> GetSupportedLanguages()
        {
            var languages      = GetAll();
            var siteContext    = new SiteContext();
            var siteDefinition = siteContext.GetSiteDefinition(Sitecore.Context.Item);

            if (siteDefinition?.Item == null || !siteDefinition.Item.IsDerived(Feature.Language.Templates.LanguageSettings.ID))
            {
                return(languages);
            }

            var supportedLanguagesField = new MultilistField(siteDefinition.Item.Fields[Feature.Language.Templates.LanguageSettings.Fields.SupportedLanguages]);

            if (supportedLanguagesField.Count == 0)
            {
                return(languages);
            }

            var supportedLanguages = supportedLanguagesField.GetItems();

            languages = languages.Where(language => supportedLanguages.Any(item => item.Name.Equals(language.Name)));

            return(languages);
        }
Exemplo n.º 13
0
        public void GetSiteDefinition_ItemOutsideSiteHierarcy_ShouldReturnContextSiteDefinition(SiteContext siteContext, DbItem item, Db db, string siteName)
        {
            var siteDefinitionId = ID.NewID;
            var home             = new DbItem("home", ID.NewID);

            db.Add(new DbItem(siteName, siteDefinitionId, Templates.Site.ID)
            {
                home
            });
            var definitionItem = db.GetItem(siteDefinitionId);

            db.Add(item);
            var contextItem = db.GetItem(item.ID);

            var fakeSite = new Sitecore.FakeDb.Sites.FakeSiteContext(new Sitecore.Collections.StringDictionary {
                { "name", siteName }, { "database", db.Database.Name }, { "rootPath", "/sitecore/content/" + siteName }, { "startItem", "/home" }
            });

            using (new Sitecore.Sites.SiteContextSwitcher(fakeSite))
            {
                var siteDefinition = siteContext.GetSiteDefinition(contextItem);
                siteDefinition.Item.ID.ShouldBeEquivalentTo(definitionItem.ID);
            }
        }