public void getCategories_UnknownBlog()
        {
            var api = new TestableMetaBlogApi(null, null)
            {
                AuthenticateFunction = (u, p) => { },
                GetBlogFunction      = id => null
            };

            var categoriesStruct = api.getCategories(ID.NewID.ToString(), "user", "password");

            Assert.That(categoriesStruct, Is.Empty);
        }
        public void getCategories_NoCategories()
        {
            using (var db = new Db
            {
                new DbItem("blog")
            })
            {
                var blog = db.GetItem("/sitecore/content/blog");

                var categoryManager = Mock.Of <ICategoryManager>(x =>
                                                                 x.GetCategories(blog) == new CategoryItem[0]
                                                                 );

                var api = new TestableMetaBlogApi(null, categoryManager)
                {
                    AuthenticateFunction = (u, p) => { },
                    GetBlogFunction      = id => blog
                };

                var categoriesStruct = api.getCategories(blog.ID.ToString(), "user", "password");

                Assert.That(categoriesStruct, Is.Empty);
            }
        }
        public void getCategories_CategoriesPresent()
        {
            using (var db = new Db
            {
                new DbItem("blog")
                {
                    new DbItem("Categories")
                    {
                        new DbItem("alpha")
                        {
                            new DbField("Title")
                            {
                                Value = "Alpha"
                            }
                        },
                        new DbItem("beta")
                        {
                            new DbField("Title")
                            {
                                Value = "Beta"
                            }
                        },
                        new DbItem("gamma")
                        {
                            new DbField("Title")
                            {
                                Value = "Gamma"
                            }
                        }
                    }
                }
            })
            {
                var blog = db.GetItem("/sitecore/content/blog");

                var categoryAlpha = db.GetItem("/sitecore/content/blog/categories/alpha");
                var categoryBeta  = db.GetItem("/sitecore/content/blog/categories/beta");
                var categoryGamma = db.GetItem("/sitecore/content/blog/categories/gamma");

                var categoryManager = Mock.Of <ICategoryManager>(x =>
                                                                 x.GetCategories(blog) == new CategoryItem[] { categoryAlpha, categoryBeta, categoryGamma }
                                                                 );

                var api = new TestableMetaBlogApi(null, categoryManager)
                {
                    AuthenticateFunction = (u, p) => { },
                    GetBlogFunction      = id => blog
                };

                var categoriesStruct = api.getCategories(blog.ID.ToString(), "user", "password");

                var expected = new[]
                {
                    new XmlRpcStruct
                    {
                        { "categoryid", categoryAlpha.ID.ToString() },
                        { "title", "Alpha" },
                        { "description", "Description is not available" },
                    },
                    new XmlRpcStruct
                    {
                        { "categoryid", categoryBeta.ID.ToString() },
                        { "title", "Beta" },
                        { "description", "Description is not available" },
                    },
                    new XmlRpcStruct
                    {
                        { "categoryid", categoryGamma.ID.ToString() },
                        { "title", "Gamma" },
                        { "description", "Description is not available" },
                    }
                };

                Assert.That(categoriesStruct, Is.EqualTo(expected));
            }
        }