示例#1
0
        /// <summary>
        /// Will convert ArchiveCountCollection method from Archives.GetPostsByCategoryArchive()
        /// into a <see cref="LinkCategory"/>. LinkCategory is a common item to databind to a web control.
        /// </summary>
        public static LinkCategory BuildCategoriesArchiveLinks(string title, UrlHelper urlHelper)
        {
            ICollection <ArchiveCount> acc = Archives.GetPostCountByCategory();

            var category = new LinkCategory {
                Title = title
            };

            foreach (ArchiveCount ac in acc)
            {
                var link = new Link
                {
                    IsActive  = true,
                    NewWindow = false,
                    Title     = string.Format("{0} ({1})", ac.Title, ac.Count.ToString(CultureInfo.InvariantCulture)),
                    Url       = urlHelper.CategoryUrl(new Category {
                        Id = ac.Id, Title = ac.Title
                    })
                };
                //Ugh, I hate how categories work in Subtext. So intertwined with links.

                category.Links.Add(link);
            }
            return(category);
        }
示例#2
0
        public void CanGetPostsByCategoryArchive()
        {
            UnitTestHelper.SetupBlog();
            ICollection <ArchiveCount> counts = Archives.GetPostCountByCategory();

            Assert.AreEqual(0, counts.Count);

            Entry entry      = UnitTestHelper.CreateEntryInstanceForSyndication("me", "title", "body");
            int   categoryId = UnitTestHelper.CreateCategory(Config.CurrentBlog.Id, "Test");
            int   entryId    = UnitTestHelper.Create(entry);

            ObjectProvider.Instance().SetEntryCategoryList(entryId, new[] { categoryId });
            counts = Archives.GetPostCountByCategory();
            Assert.AreEqual(1, counts.Count);

            foreach (ArchiveCount archiveCount in counts)
            {
                Assert.AreEqual(1, archiveCount.Count, "Expected one post in the archive.");
                archiveCount.Title = "Test";
                Assert.AreEqual("Test", archiveCount.Title);
                archiveCount.Id = 10;
                Assert.AreEqual(10, archiveCount.Id);
                return;
            }
        }