Example #1
0
        public void GetCategoryRoot_OutsideBlog()
        {
            var home = Sitecore.Context.Database.GetItem("/sitecore/content/home");
            var root = new Mod.CategoryManager().GetCategoryRoot(home);

            Assert.IsNull(root);
        }
Example #2
0
        public void GetCategories(string startItemPath, bool expectCategories)
        {
            var settings = MockSettings(ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.First())
                    },
                    new DbItem("a folder", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var startItem = string.IsNullOrEmpty(startItemPath) ? null : db.GetItem(startItemPath);
                var categories = manager.GetCategories(startItem);
                var categoryNames = from c in categories select c.Name;

                if (expectCategories)
                    Assert.That(categoryNames, Is.EquivalentTo(new [] { "alpha", "beta", "gamma" }));
                else
                    Assert.That(categoryNames, Is.Empty);
            }
        }
Example #3
0
        public void GetCategory_ByValidNameFromEntry()
        {
            var category = new Mod.CategoryManager().GetCategory(m_entry2, m_category3.Name);

            Assert.IsNotNull(category);
            Assert.AreEqual(m_category3.ID, category.ID);
        }
Example #4
0
        public void GetCategory_ByUppercaseValidNameFromBlog()
        {
            var category = new Mod.CategoryManager().GetCategory(m_blog1, m_category3.Name.ToUpper());

            Assert.IsNotNull(category);
            Assert.AreEqual(m_category3.ID, category.ID);
        }
Example #5
0
        public void GetCategories_OutsideBlogRoot_ById()
        {
            var home       = Sitecore.Context.Database.GetItem("/sitecore/content/home");
            var categories = new Mod.CategoryManager().GetCategories(home.ID.ToString());

            Assert.AreEqual(0, categories.Length);
        }
Example #6
0
        public void GetCategoryRoot_OnBlog()
        {
            var root = new Mod.CategoryManager().GetCategoryRoot(m_blog1);

            Assert.IsNotNull(root);
            Assert.AreEqual(m_categoryRoot.ID, root.ID);
        }
Example #7
0
        public void GetCategoriesByEntryID_Entry2()
        {
            var categories = new Mod.CategoryManager().GetCategoriesByEntryID(m_entry2.ID);
            Assert.AreEqual(2, categories.Length);

            var ids = (from category in categories
                       select category.ID).ToArray();

            Assert.Contains(m_category2.ID, ids);
            Assert.Contains(m_category3.ID, ids);
        }
Example #8
0
        public void GetCategoriesByEntryID_Entry2()
        {
            var categories = new Mod.CategoryManager().GetCategoriesByEntryID(m_entry2.ID);

            Assert.AreEqual(2, categories.Length);

            var ids = (from category in categories
                       select category.ID).ToArray();

            Assert.Contains(m_category2.ID, ids);
            Assert.Contains(m_category3.ID, ids);
        }
Example #9
0
        public void Add(string contextItemPath, string name, bool expectCategory)
        {
            var settings = MockSettings(ID.NewID, ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbTemplate("category1", settings.CategoryTemplateIds.ElementAt(0))
                {
                    new DbField("Title")
                },
                new DbTemplate("category2", settings.CategoryTemplateIds.ElementAt(1))
                {
                    new DbField("Title")
                },
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.ElementAt(0)),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.ElementAt(1)),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.ElementAt(0))
                    },
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var entryItem = contextItemPath != null ? db.GetItem(contextItemPath) : null;
                CategoryItem categoryItem = null;

                using (new SecurityDisabler())
                {
                    categoryItem = manager.Add(name, entryItem);
                }

            if (expectCategory)
                {
                    Assert.That(categoryItem, Is.Not.Null);
                    Assert.That(categoryItem.Name, Is.EqualTo(name));
                }
                else
                    Assert.That(categoryItem, Is.Null);
            }
        }
Example #10
0
        public void GetCategoriesForEntry_WithCategories()
        {
            var settings = MockSettings(ID.NewID, ID.NewID);
            var manager = new CategoryManager(settings);

            var categoryFieldId = ID.NewID;
            var cat1Id = ID.NewID;
            var cat2Id = ID.NewID;

            using (var db = new Db
            {
                new DbTemplate("entry", settings.EntryTemplateIds.First())
                {
                    new DbField("Category", categoryFieldId)
                },
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", cat1Id, settings.CategoryTemplateIds.ElementAt(0)),
                        new DbItem("beta", cat2Id, settings.CategoryTemplateIds.ElementAt(1)),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.ElementAt(0))
                    },
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                        {
                            new DbField(categoryFieldId)
                            {
                                Value = cat1Id + "|" + cat2Id
                            }
                        }
                    }
                }
            })
            {
                var item = db.GetItem("/sitecore/content/blog/entries/entry1");
                var categories = manager.GetCategoriesForEntry(item);
                var categoryNames = from c in categories select c.Name;

                Assert.That(categoryNames, Is.EquivalentTo(new[] { "alpha", "beta" }));
            }
        }
Example #11
0
        public void GetCategoriesForEntry_NullItem()
        {
            var settings = MockSettings(ID.NewID, ID.NewID);
            var manager = new CategoryManager(settings);

            var categories = manager.GetCategoriesForEntry(null);
            Assert.That(categories, Is.Empty);
        }
Example #12
0
        public void GetCategoriesForEntry_NotAnEntryItem()
        {
            var settings = MockSettings(ID.NewID, ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.ElementAt(0)),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.ElementAt(1)),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.ElementAt(0))
                    },
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var item = db.GetItem("/sitecore/content/blog");
                var categories = manager.GetCategoriesForEntry(item);
                Assert.That(categories, Is.Empty);
            }
        }
Example #13
0
 public void GetCategoryRoot_OutsideBlog()
 {
     var home = Sitecore.Context.Database.GetItem("/sitecore/content/home");
     var root = new Mod.CategoryManager().GetCategoryRoot(home);
     Assert.IsNull(root);
 }
Example #14
0
        public void GetCategories_Null()
        {
            var categories = new Mod.CategoryManager().GetCategories((Item)null);

            Assert.AreEqual(0, categories.Length);
        }
Example #15
0
 public void GetCategory_ByInvalidNameFromBlog()
 {
     var category = new Mod.CategoryManager().GetCategory(m_blog1, "blah");
     Assert.IsNull(category);
 }
Example #16
0
 public void GetCategories_Null()
 {
     var categories = new Mod.CategoryManager().GetCategories((Item)null);
     Assert.AreEqual(0, categories.Length);
 }
Example #17
0
 public void GetCategoryRoot_OnBlog()
 {
     var root = new Mod.CategoryManager().GetCategoryRoot(m_blog1);
     Assert.IsNotNull(root);
     Assert.AreEqual(m_categoryRoot.ID, root.ID);
 }
Example #18
0
        public void GetCategory_NoCategories()
        {
            var settings = MockSettings(ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID),
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var entryItem = db.GetItem("/sitecore/content/blog/entries/entry1");
                var categoryItem = manager.GetCategory(entryItem, "alpha");

                Assert.That(categoryItem, Is.Null);
            }
        }
Example #19
0
        public void GetCategory(string startItemPath, string categoryName, bool shouldFindCategory)
        {
            var settings = MockSettings(ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.First())
                    },
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var startItem = string.IsNullOrEmpty(startItemPath) ? null : db.GetItem(startItemPath);
                var categoryItem = manager.GetCategory(startItem, categoryName);

                if (shouldFindCategory)
                {
                    Assert.That(categoryItem, Is.Not.Null);
                    Assert.That(categoryItem.Name, Is.EqualTo(categoryName));
                }
                else
                    Assert.That(categoryItem, Is.Null);
            }
        }
Example #20
0
        public void GetCategoriesByEntryID_InvalidID()
        {
            var categories = new Mod.CategoryManager().GetCategoriesByEntryID(ID.NewID);

            Assert.AreEqual(0, categories.Length);
        }
Example #21
0
        public void GetCategoriesByEntryID_NonEntryItem()
        {
            var categories = new Mod.CategoryManager().GetCategoriesByEntryID(m_blog1.ID);

            Assert.AreEqual(0, categories.Length);
        }
Example #22
0
 public void GetCategories_OutsideBlogRoot_ById()
 {
     var home = Sitecore.Context.Database.GetItem("/sitecore/content/home");
     var categories = new Mod.CategoryManager().GetCategories(home.ID.ToString());
     Assert.AreEqual(0, categories.Length);
 }
Example #23
0
 public void GetCategory_ByUppercaseValidNameFromBlog()
 {
     var category = new Mod.CategoryManager().GetCategory(m_blog1, m_category3.Name.ToUpper());
     Assert.IsNotNull(category);
     Assert.AreEqual(m_category3.ID, category.ID);
 }
Example #24
0
        public void GetCategories_MixedTemplates()
        {
            var settings = MockSettings(ID.NewID, ID.NewID, ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.ElementAt(0)),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.ElementAt(1)),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.ElementAt(2))
                    },
                    new DbItem("Entries", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var entryItem = db.GetItem("/sitecore/content/blog/entries/entry1");
                var categories = manager.GetCategories(entryItem);
                var categoryNames = from c in categories select c.Name;

                Assert.That(categoryNames, Is.EquivalentTo(new[] { "alpha", "beta", "gamma" }));
            }
        }
Example #25
0
 public void GetCategory_ByValidNameFromEntry()
 {
     var category = new Mod.CategoryManager().GetCategory(m_entry2, m_category3.Name);
     Assert.IsNotNull(category);
     Assert.AreEqual(m_category3.ID, category.ID);
 }
Example #26
0
        public void GetCategoryRoot(string startItemPath, bool expectCategoryRoot)
        {
            var settings = MockSettings(ID.NewID);
            var manager = new CategoryManager(settings);

            using (var db = new Db
            {
                new DbItem("blog", ID.NewID, settings.BlogTemplateIds.First())
                {
                    new DbItem("Categories", ID.NewID, ID.NewID)
                    {
                        new DbItem("alpha", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("beta", ID.NewID, settings.CategoryTemplateIds.First()),
                        new DbItem("gamma", ID.NewID, settings.CategoryTemplateIds.First())
                    },
                    new DbItem("a folder", ID.NewID, ID.NewID)
                    {
                        new DbItem("entry1", ID.NewID, settings.EntryTemplateIds.First())
                    }
                }
            })
            {
                var startItem = string.IsNullOrEmpty(startItemPath) ? null : db.GetItem(startItemPath);
                var categoryRoot = manager.GetCategoryRoot(startItem);

                if (expectCategoryRoot)
                {
                    Assert.That(categoryRoot, Is.Not.Null);
                    Assert.That(categoryRoot.Name, Is.EqualTo("Categories"));
                }
                else
                    Assert.That(categoryRoot, Is.Null);
            }
        }
Example #27
0
 public void GetCategoriesByEntryID_NonEntryItem()
 {
     var categories = new Mod.CategoryManager().GetCategoriesByEntryID(m_blog1.ID);
     Assert.AreEqual(0, categories.Length);
 }
Example #28
0
        public void GetCategory_ByInvalidNameFromBlog()
        {
            var category = new Mod.CategoryManager().GetCategory(m_blog1, "blah");

            Assert.IsNull(category);
        }
Example #29
0
 public void GetCategoriesByEntryID_InvalidID()
 {
     var categories = new Mod.CategoryManager().GetCategoriesByEntryID(ID.NewID);
     Assert.AreEqual(0, categories.Length);
 }