Subtext.Framework.XmlRpc.MetaWeblog.getCategories C# (CSharp) 메소드

getCategories() 공개 메소드

public getCategories ( string blogid, string username, string password ) : Subtext.Framework.XmlRpc.CategoryInfo[]
blogid string
username string
password string
리턴 Subtext.Framework.XmlRpc.CategoryInfo[]
        public CategoryInfo[] getCategories(string blogid, string username, string password)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            ICollection<LinkCategory> lcc = Links.GetCategories(CategoryType.PostCollection, ActiveFilter.None);
            if (lcc == null)
            {
                throw new XmlRpcFaultException(0, "No categories exist");
            }
            CategoryInfo[] categories = new CategoryInfo[lcc.Count];
            int i = 0;
            foreach (LinkCategory linkCategory in lcc)
            {
                CategoryInfo category = new CategoryInfo();
                category.categoryid = linkCategory.Id.ToString(CultureInfo.InvariantCulture);
                category.title = linkCategory.Title;
                category.htmlUrl = info.RootUrl + "Category/" + linkCategory.Id.ToString(CultureInfo.InvariantCulture) + ".aspx";
                category.rssUrl = info.RootUrl + "rss.aspx?catid=" + linkCategory.Id.ToString(CultureInfo.InvariantCulture);
                category.description = linkCategory.Title;

                categories[i] = category;
                i++;
            }
            return categories;
        }

Usage Example

예제 #1
0
        public void getCategories_ReturnsCategoriesInRepository()
        {
            //arrange
            var blog = new Blog { AllowServiceAccess = true, Host = "localhost", UserName = "******", Password = "******" };
            var category = new LinkCategory
            {
                BlogId = blog.Id,
                IsActive = true,
                Description = "Test category",
                Title = "CategoryA",
                CategoryType = CategoryType.PostCollection,
                Id = 42
            };

            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.CategoryUrl(It.IsAny<LinkCategory>())).Returns("/Category/42.aspx");
            subtextContext.Setup(c => c.UrlHelper.CategoryRssUrl(It.IsAny<LinkCategory>())).Returns("/rss.aspx?catId=42");
            subtextContext.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false)).Returns(new[] { category });
            subtextContext.Setup(c => c.ServiceLocator).Returns(new Mock<IDependencyResolver>().Object);
            var api = new MetaWeblog(subtextContext.Object);

            //act
            CategoryInfo[] categories = api.getCategories(blog.Id.ToString(), "username", "password");

            //assert
            Assert.AreEqual(1, categories.Length);
            Assert.AreEqual("http://localhost/Category/42.aspx", categories[0].htmlUrl);
            Assert.AreEqual("http://localhost/rss.aspx?catId=42", categories[0].rssUrl);
        }