protected override ICollection <Entry> GetFeedEntries() { if (Category == null) { Category = Cacher.SingleCategory(SubtextContext); } if (Category != null && _posts == null) { _posts = Cacher.GetEntriesByCategory(10, Category.Id, SubtextContext); } return(_posts); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Context != null) { Blog info = Blog; LinkCategory lc = Cacher.SingleCategory(SubtextContext); int count = Request.QueryString["Show"] != null ? 0 : info.CategoryListPostCount; //as of 3sep2006, this is a configurable option. //However, we retain the ability to overide the CategoryListPostCount setting via the query string, as usual. if (lc == null) { HttpHelper.SetFileNotFoundResponse(); return; } ICollection <Entry> ec = Cacher.GetEntriesByCategory(count, lc.Id, SubtextContext); EntryStoryList.EntryListItems = ec; EntryStoryList.EntryListTitle = lc.Title; if (lc.HasDescription) { EntryStoryList.EntryListDescription = lc.Description; } if (count != 0 && ec != null && ec.Count == info.CategoryListPostCount) //crappy. If the only category has #CategoryListPostCount entries, we will show the full archive link? { EntryStoryList.EntryListReadMoreText = string.Format(CultureInfo.InvariantCulture, "Full {0} Archive", lc.Title); EntryStoryList.EntryListReadMoreUrl = string.Format(CultureInfo.InvariantCulture, "{0}?Show=All", Request.Path); } Globals.SetTitle(string.Format(CultureInfo.InvariantCulture, "{0} - {1}", Blog.Title, lc.Title), Context); } }
public void GetEntriesByCategory_WithEntriesInCache_RetrievesFromCache() { // arrange var entry = new Entry(PostType.BlogPost) { Title = "Testing Cacher" }; var context = new Mock <ISubtextContext>(); context.Setup(c => c.Blog).Returns(new Blog { Id = 1001 }); context.Setup(c => c.Cache["EC:Count10Category1BlogId1001"]).Returns(new List <Entry> { entry }); context.Setup(c => c.Repository.GetEntriesByCategory(10, 1, true /*activeOnly*/)).Throws(new Exception("Repository should not have been accessed")); // act var cachedEntries = Cacher.GetEntriesByCategory(10 /*count*/, 1 /*categoryId*/, context.Object); // assert Assert.AreEqual(entry, cachedEntries.First()); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (EntryListItems == null && !string.IsNullOrEmpty(Category)) { // This EntryList is independent of an outside control and needs to // populate its own EntryListItems. LinkCategory lc; if (Category.IsNumeric()) { int categoryId = Int32.Parse(Category); lc = Cacher.SingleCategory(categoryId, false, SubtextContext); } else { lc = Cacher.SingleCategory(Category, false, SubtextContext); } EntryListTitle = lc.Title; EntryListItems = Cacher.GetEntriesByCategory(0, lc.Id, SubtextContext); } if (EntryListItems != null) { var entryCollectionTitle = FindControl("EntryCollectionTitle") as Literal; if (entryCollectionTitle != null) { entryCollectionTitle.Text = EntryListTitle; } var entryCollectionDescription = FindControl("EntryCollectionDescription") as Literal; if (entryCollectionDescription != null) { if (EntryListDescription != null) { entryCollectionDescription.Text = EntryListDescription; } else { entryCollectionDescription.Visible = false; } } var entryListReadMoreUrl = FindControl("EntryCollectionReadMoreLink") as HyperLink; if (entryListReadMoreUrl != null) { if (EntryListReadMoreText != null) { entryListReadMoreUrl.Text = EntryListReadMoreText; entryListReadMoreUrl.NavigateUrl = EntryListReadMoreUrl; } else { entryListReadMoreUrl.Visible = false; } } var entryRepeater = FindControl("Entries") as Repeater; if (entryRepeater != null) { entryRepeater.DataSource = EntryListItems; entryRepeater.DataBind(); } } }