public void GetEntryFromRequest_WithSlugInRouteDataMatchingEntryInRepository_ReturnsEntry() { //arrange var httpContext = new Mock <HttpContextBase>(); httpContext.FakeRequest("~/archive/the-slug.aspx"); var routeData = new RouteData(); routeData.Values.Add("slug", "the-slug"); var subtextContext = new Mock <ISubtextContext>(); subtextContext.SetupRequestContext(httpContext, routeData) .SetupBlog(new Blog { Id = 1, TimeZoneId = TimeZonesTest.PacificTimeZoneId /* pacific */ }) .Setup(c => c.Repository.GetEntry("the-slug", true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, EntryName = "the-slug", Title = "Testing 123" }); //act Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object); //assert Assert.AreEqual(123, entry.Id); Assert.AreEqual("Testing 123", entry.Title); Assert.AreEqual("the-slug", entry.EntryName); }
public void GetEntryFromRequest_WithIdInRouteDataMatchingEntryInRepository_ReturnsEntry() { //arrange var httpContext = new Mock <HttpContextBase>(); httpContext.FakeRequest("~/archive/123.aspx"); var routeData = new RouteData(); routeData.Values.Add("id", "123"); var subtextContext = new Mock <ISubtextContext>(); subtextContext.SetupRequestContext(httpContext, routeData, new Blog { Id = 123 }) .Setup(c => c.Repository.GetEntry(123, true, true)).Returns(new Entry(PostType.BlogPost) { Id = 123, Title = "Testing 123" }); //act Entry entry = Cacher.GetEntryFromRequest(true, subtextContext.Object); //assert Assert.AreEqual(123, entry.Id); Assert.AreEqual("Testing 123", entry.Title); }
public void InitializeControls(ISkinControlLoader controlLoader) { IEnumerable <string> controlNames = _controls; if (controlNames != null) { var apnlCommentsWrapper = new UpdatePanel { Visible = true, ID = CommentsPanelId }; if (!controlNames.Contains("HomePage", StringComparer.OrdinalIgnoreCase) && !String.IsNullOrEmpty(Query)) { int entryId = -1; Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext); if (entry != null) { entryId = entry.Id; } var query = Query; if (!String.IsNullOrEmpty(query)) { var searchResults = SearchEngineService.Search(query, 5, Blog.Id, entryId); if (searchResults.Any()) { AddMoreResultsControl(searchResults, controlLoader, apnlCommentsWrapper); } } } foreach (string controlName in controlNames) { Control control = controlLoader.LoadControl(controlName); AddControlToBody(controlName, control, apnlCommentsWrapper, CenterBodyControl); } } }
protected override void OnLoad(EventArgs e) { int blogId = Blog.Id >= 1 ? Blog.Id : 0; var urlRelatedLinks = FindControl("Links") as Repeater; if (urlRelatedLinks != null) { if (SearchResults == null) { int entryId = -1; Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext); if (entry != null) { entryId = entry.Id; } SearchResults = SearchEngineService.Search(Query, RowCount, blogId, entryId); } urlRelatedLinks.DataSource = SearchResults; urlRelatedLinks.DataBind(); } var keywords = FindControl("keywords") as Literal; if (keywords != null) { keywords.Text = HttpUtility.HtmlEncode(Query); } base.OnLoad(e); }
protected override void OnLoad(EventArgs e) { int blogId = Blog.Id >= 1 ? Blog.Id : 0; var urlRelatedLinks = FindControl("Links") as Repeater; Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext); urlRelatedLinks.DataSource = SearchEngineService.RelatedContents(entry.Id, RowCount, blogId);; urlRelatedLinks.DataBind(); if (urlRelatedLinks.Items.Count == 0) { this.Visible = false; } base.OnLoad(e); }
public void GetEntryFromRequest_WithEntryHavingEntryNameButIdInRouteDataMatchingEntryInRepository_RedirectsToUrlWithSlug() { //arrange var repository = new Mock <ObjectProvider>(); var entry = new Entry(PostType.BlogPost) { Id = 123, EntryName = "testing-slug", Title = "Testing 123" }; repository.Setup(r => r.GetEntry(123, true, true)).Returns(entry); var urlHelper = new Mock <UrlHelper>(); urlHelper.Setup(u => u.EntryUrl(It.IsAny <Entry>())).Returns("/archive/testing-slug.aspx"); UnitTestHelper.SetupBlog(); var response = new Mock <HttpResponseBase>(); response.Setup(r => r.End()); response.SetupSet(r => r.StatusCode, 301); response.SetupSet(r => r.StatusDescription, "301 Moved Permanently"); response.SetupSet(r => r.RedirectLocation, "http://localhost/archive/testing-slug.aspx"); var httpContext = new Mock <HttpContextBase>(); httpContext.FakeRequest("~/archive/testing-slug.aspx"); httpContext.Setup(c => c.Response).Returns(response.Object); var routeData = new RouteData(); routeData.Values.Add("id", "123"); var subtextContext = new Mock <ISubtextContext>(); subtextContext.SetupRequestContext(httpContext, routeData) .SetupUrlHelper(urlHelper) .SetupRepository(repository.Object) .SetupBlog(new Blog { Host = "localhost" }); subtextContext.Setup(c => c.HttpContext).Returns(httpContext.Object); //act Entry cachedEntry = Cacher.GetEntryFromRequest(true /* allowRedirect */, subtextContext.Object); //assert response.VerifySet(r => r.StatusCode, 301); response.VerifySet(r => r.StatusDescription, "301 Moved Permanently"); response.VerifySet(r => r.RedirectLocation, "http://localhost/archive/testing-slug.aspx"); Assert.AreEqual(123, cachedEntry.Id); Assert.AreEqual("Testing 123", cachedEntry.Title); }
/// <summary> /// Gets the feed entries. /// </summary> /// <returns></returns> protected override ICollection <FeedbackItem> GetFeedEntries() { if (ParentEntry == null) { ParentEntry = Cacher.GetEntryFromRequest(false, SubtextContext); } if (ParentEntry == null) { // bad news... we couldn't find the entry the request is looking for - return 404. HttpHelper.SetFileNotFoundResponse(); } if (ParentEntry != null && Comments == null) { Comments = Cacher.GetFeedback(ParentEntry, SubtextContext); } return(Comments); }
public void GetEntryFromRequest_WithNonExistentEntry_DoesNotThrowNullReferenceException() { //arrange var httpContext = new Mock <HttpContextBase>(); httpContext.FakeRequest("~/archive/99999.aspx"); var routeData = new RouteData(); routeData.Values.Add("id", "999999"); var subtextContext = new Mock <ISubtextContext>(); subtextContext.SetupRequestContext(httpContext, routeData) .Setup(c => c.Repository.GetEntry(It.IsAny <int>(), true, true)).Returns((Entry)null); //act Cacher.GetEntryFromRequest(true, subtextContext.Object); //assert //None needed. }
protected override void Render(HtmlTextWriter writer) { //var ctx = Parent.Page SubtextContext ctx = base.SubtextContext as SubtextContext; if (ctx != null) { HtmlMeta summaryTitleMeta = new HtmlMeta(); summaryTitleMeta.Name = "twitter:title"; HtmlMeta descriptionMeta = new HtmlMeta(); descriptionMeta.Name = "twitter:description"; Entry entry = Cacher.GetEntryFromRequest(true, ctx); if (entry != null) { string title = entry.Title; string description = entry.HasDescription ? entry.Description : entry.Body; summaryTitleMeta.Content = title; var cleanedDescription = HttpUtility.HtmlDecode(Regex.Replace(description, "<[^>]*(>|$)", string.Empty)); var maxLen = (cleanedDescription.Length > 180) ? 180 : cleanedDescription.Length; descriptionMeta.Content = cleanedDescription.Substring(0, maxLen) + "..."; } else { // get the default title/summary from the blog summaryTitleMeta.Content = ctx.Blog.Title; descriptionMeta.Content = ctx.Blog.SubTitle; } summaryTitleMeta.RenderControl(writer); descriptionMeta.RenderControl(writer); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); //Get the entry Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext); //if found if (entry != null) { //Sent entry properties MainLink.NavigateUrl = Url.BlogUrl(); var entries = Cacher.GetPreviousNextEntry(entry.Id, PostType.BlogPost, SubtextContext); //Remember, the NEXT entry is the MORE RECENT entry. switch (entries.Count) { case 0: { //you have no entries. You should blog more if (PrevLink != null) { PrevLink.Visible = false; } if (NextLink != null) { NextLink.Visible = false; } break; } case 1: { //since there is only one record, you are at an end //Check EntryId to see if it is greater or less than //the current ID if (entries.First().DateSyndicated > entry.DateSyndicated) { //this is the oldest blog if (PrevLink != null) { PrevLink.Visible = false; } if (LeftPipe != null) { LeftPipe.Visible = false; } SetNav(NextLink, entries.First()); } else { //this is the latest blog if (NextLink != null) { NextLink.Visible = false; } if (RightPipe != null) { RightPipe.Visible = false; } SetNav(PrevLink, entries.First()); } break; } case 2: { //two records found. The first record will be NEXT //the second record will be PREVIOUS //This is because the query is sorted by EntryId SetNav(NextLink, entries.First()); SetNav(PrevLink, entries.ElementAt(1)); break; } } } else { //No post? Deleted? Help :) Controls.Clear(); Controls.Add( new LiteralControl("<p><strong>The entry could not be found or has been removed</strong></p>")); } }
/// <summary> /// Loads the entry specified by the URL. If the user is an /// admin and the skin supports it, will also display an edit /// link that navigates to the admin section and allows the /// admin to edit the post. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); //Get the entry Entry entry = Cacher.GetEntryFromRequest(true, SubtextContext); //if found if (entry != null) { BindCurrentEntryControls(entry, this); DisplayEditLink(entry); Bootstrapper.RequestContext = SubtextContext.RequestContext; var statistics = Bootstrapper.ServiceLocator.GetService <IStatisticsService>(); statistics.RecordWebView(new EntryView { EntryId = entry.Id, BlogId = Blog.Id }); //Set the page title Globals.SetTitle(entry.Title, Context); //Sent entry properties TitleUrl.Text = entry.Title; ControlHelper.SetTitleIfNone(TitleUrl, "Title of this entry."); TitleUrl.NavigateUrl = Url.EntryUrl(entry); Body.Text = entry.Body; if (PostDescription != null) { PostDescription.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}", entry.DateSyndicated.ToLongDateString(), entry.DateSyndicated.ToShortTimeString()); } Trace.Write("loading categories"); if (Categories != null) { Categories.LinkCategories = Links.GetLinkCategoriesByPostId(entry.Id); Categories.DataBind(); } if (date != null) { string entryUrl = Url.EntryUrl(entry); if (date.Attributes["Format"] != null) { date.Text = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{2}\">{1}</a>", entryUrl, entry.DateSyndicated.ToString(date.Attributes["Format"]), Resources.EntryList_PermanentLink); date.Attributes.Remove("Format"); } else { date.Text = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" title=\"{2}\">{1}</a>", entryUrl, entry.DateSyndicated.ToString("f"), Resources.EntryList_PermanentLink); } } if (commentCount != null) { if (Blog.CommentsEnabled && entry.AllowComments) { string entryUrl = Url.EntryUrl(entry); if (entry.FeedBackCount == 0) { commentCount.Text = string.Format(LinkToComments, entryUrl, Resources.EntryList_AddComment, string.Empty); } else if (entry.FeedBackCount == 1) { commentCount.Text = string.Format(LinkToComments, entryUrl, Resources.EntryList_OneComment, string.Empty); } else if (entry.FeedBackCount > 1) { commentCount.Text = string.Format(LinkToComments, entryUrl, entry.FeedBackCount, Resources.EntryList_CommentsPlural); } } } BindEnclosure(entry); //Set Pingback/Trackback if (PingBack == null) { PingBack = Page.FindControl("pinbackLinkTag") as Literal; } if (PingBack != null) { PingBack.Text = TrackHelpers.GetPingPackTag(Url); } if (TrackBack != null) { TrackBack.Text = TrackHelpers.TrackBackTag(entry, Blog, Url); } DataBind(); } else { //No post? Deleted? Help :) Controls.Clear(); Controls.Add(new LiteralControl(Resources.ViewPost_EntryNotFound)); } }