public void LogoutUrl_WithSubfolderAndApp_ReturnsLoginUrlInSubfolder() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act string url = helper.LogoutUrl(); //assert Assert.AreEqual("/Subtext.Web/sub/account/logout.ashx", url); }
public void TagUrl_CorrectlyEncodesPoundCharacter() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act VirtualPath url = helper.TagUrl("C#"); //assert Assert.AreEqual("/Subtext.Web/sub/tags/C%23/default.aspx", url.ToString()); }
public virtual void Write(IEnumerable <Blog> blogs, TextWriter writer, BlogUrlHelper urlHelper) { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Document, Indent = true, IndentChars = ("\t") }; using (XmlWriter xmlWriter = XmlWriter.Create(writer, settings)) { if (xmlWriter != null) { xmlWriter.WriteStartDocument(); //OPML ROOT xmlWriter.WriteStartElement("opml"); xmlWriter.WriteAttributeString("version", "1.0"); xmlWriter.WriteStartElement("head"); xmlWriter.WriteStartElement("title"); xmlWriter.WriteString(ConfigurationManager.AppSettings["AggregateTitle"]); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); //Body xmlWriter.WriteStartElement("body"); xmlWriter.WriteStartElement("outline"); xmlWriter.WriteAttributeString("text", ConfigurationManager.AppSettings["AggregateTitle"] + " Feeds"); foreach (Blog blog in blogs) { xmlWriter.WriteStartElement("outline"); string title = blog.Title; string xmlUrl = urlHelper.RssUrl(blog).ToString(); xmlWriter.WriteAttributeString("type", "rss"); xmlWriter.WriteAttributeString("text", title); xmlWriter.WriteAttributeString("xmlUrl", xmlUrl); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); //outline xmlWriter.WriteEndElement(); //body xmlWriter.WriteEndElement(); //opml xmlWriter.Flush(); } } }
public void LoginUrl_WithSubfolderAndAppAndReturnUrl_ReturnsLoginUrlWithReturnUrlInQueryString() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act string url = helper.LoginUrl("/Subtext.Web/AdminPage.aspx").ToString().ToLowerInvariant(); //assert Assert.AreEqual(("/Subtext.Web/sub/login.aspx?ReturnUrl=" + HttpUtility.UrlEncode("/Subtext.Web/AdminPage.aspx")).ToLowerInvariant(), url); }
public void WlwManifestUrl_WithSubfolderAndApp_ReturnsPerBlogManifestUrl() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act string manifestUrl = helper.WlwManifestUrl(); //assert Assert.AreEqual("/Subtext.Web/sub/wlwmanifest.xml.ashx", manifestUrl); }
public void TagCloudUrl_WithSubfolderAndApp_ReturnsTagCloudUrl() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act VirtualPath url = helper.TagCloudUrl(); //assert Assert.AreEqual("/Subtext.Web/sub/tags/default.aspx", url.ToString()); }
public void AdminUrl_WithBlogHavingSubfolderAndVirtualPath_RendersAdminUrlToPage() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act string url = helper.AdminUrl("log.aspx"); //assert Assert.AreEqual("/Subtext.Web/sub/admin/log.aspx", url); }
public void AdminRssUrl_WithFeednameAndSubfolderAndApp_ReturnsAdminRssUrl() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act VirtualPath url = helper.AdminRssUrl("Referrers"); //assert Assert.AreEqual("/Subtext.Web/sub/admin/ReferrersRss.axd", url.ToString()); }
public void AtomUrl_WithRssProxy_ReturnsRssUri() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var blog = new Blog { Host = "example.com", RssProxyUrl = "http://atom.example.com/atom" }; //act Uri url = helper.AtomUrl(blog); //assert Assert.AreEqual("http://atom.example.com/atom", url.ToString()); }
public void AppRootUrl_WithSubfolder_ReturnsAppRootAndIgnoresSubfolder() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/", routeData); //act VirtualPath url = helper.AppRoot(); //assert Assert.AreEqual("/", url.ToString()); }
public void CustomCssUrl_WithSubfolderAndApp_ReturnsFullyQualifiedUrl() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act VirtualPath url = helper.CustomCssUrl(); //assert Assert.AreEqual("/Subtext.Web/sub/customcss.aspx", url.ToString()); }
public void ContactFormUrl_WithSubfolderAndApp_ReturnsUrlWithAppAndSubfolder() { //arrange var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act string url = helper.ContactFormUrl(); //assert Assert.AreEqual("/Subtext.Web/sub/contact.aspx", url); }
public void RssProxyUrl_WithBlogHavingFeedBurnerName_ReturnsFeedburnerUrl() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var blog = new Blog { RssProxyUrl = "test" }; //act Uri url = helper.RssProxyUrl(blog); //assert Assert.AreEqual("http://feedproxy.google.com/test", url.ToString()); }
public static BlogUrlHelper SetupUrlHelper(string appPath, RouteData routeData) { var routes = new RouteCollection(); var subtextRoutes = new SubtextRouteMapper(routes, new Mock <IDependencyResolver>().Object); Routes.RegisterRoutes(subtextRoutes); var httpContext = new Mock <HttpContextBase>(); httpContext.Setup(c => c.Request.ApplicationPath).Returns(appPath); httpContext.Setup(c => c.Response.ApplyAppPathModifier(It.IsAny <string>())).Returns <string>(s => s); var requestContext = new RequestContext(httpContext.Object, routeData); var helper = new BlogUrlHelper(requestContext, routes); return(helper); }
public void RssProxyUrl_WithBlogHavingSyndicationProviderUrl_ReturnsFullUrl() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var blog = new Blog { RssProxyUrl = "http://feeds.example.com/" }; //act Uri url = helper.RssProxyUrl(blog); //assert Assert.AreEqual("http://feeds.example.com/", url.ToString()); }
public void GalleryImageUrl_WithImageInBlogWithSubfolder_ReturnsGalleryUrlWithId() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); //act string url = helper.GalleryImagePageUrl(new Image { ImageID = 1234, Blog = new Blog { Subfolder = "subfolder" } }); //assert Assert.AreEqual("/subfolder/gallery/image/1234.aspx", url); }
public void FeedbackUrl_WithNullEntry_ReturnsNullUrl() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var comment = new FeedbackItem(FeedbackType.ContactPage) { Id = 321, Entry = null }; //act string url = helper.FeedbackUrl(comment); //assert Assert.IsNull(url); }
public void GalleryImageUrl_WithoutAppPathWithoutSubfolderAndImage_ReturnsUrlToImageFile() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var blog = new Blog { Host = "localhost", Subfolder = "" }; var image = new Image { CategoryID = 1234, FileName = "close.gif", Blog = blog }; //act string url = helper.GalleryImageUrl(image); //assert Assert.AreEqual("/images/localhost/1234/o_close.gif", url); }
public void DayUrl_WithDate_ReturnsUrlWithDateInIt() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); //Make sure date isn't midnight. DateTime dateTime = DateTime.ParseExact("2009/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); dateTime.AddMinutes(231); //act string url = helper.DayUrl(dateTime); //assert Assert.AreEqual("/archive/2009/01/23.aspx", url); }
public void GalleryUrl_WithImageAndBlogWithSubfolder_ReturnsGalleryUrlWithSubfolder() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var image = new Image { CategoryID = 1234, Blog = new Blog { Subfolder = "subfolder" } }; //act string url = helper.GalleryUrl(image); //assert Assert.AreEqual("/subfolder/gallery/1234.aspx", url); }
public void RsdUrl_WithSubfolderAndApp_ReturnsFullyQualifiedUrl() { //arrange var blog = new Blog { Host = "example.com", Subfolder = "sub" }; var routeData = new RouteData(); routeData.Values.Add("subfolder", "sub"); BlogUrlHelper helper = SetupUrlHelper("/Subtext.Web", routeData); //act Uri url = helper.RsdUrl(blog); //assert Assert.AreEqual("http://example.com/Subtext.Web/sub/rsd.xml.ashx", url.ToString()); }
public static void AddCommunityCredits(Entry entry, BlogUrlHelper urlHelper, Blog blog) { string result; bool commCreditsEnabled; if (!bool.TryParse(ConfigurationManager.AppSettings["CommCreditEnabled"], out commCreditsEnabled)) { return; } if (commCreditsEnabled && entry.IsActive) { var wsCommunityCredit = new AffiliateServices(); string url = urlHelper.EntryUrl(entry).ToFullyQualifiedUrl(blog).ToString(); string category = String.Empty; if (entry.PostType == PostType.BlogPost) { category = "Blog"; } else if (entry.PostType == PostType.Story) { category = "Article"; } string description = "Blogged about: " + entry.Title; string firstName = string.Empty; string lastName = blog.Author; string email = blog.Email; string affiliateCode = ConfigurationManager.AppSettings["CommCreditAffiliateCode"]; string affiliateKey = ConfigurationManager.AppSettings["CommCreditAffiliateKey"]; Log.InfoFormat("Sending notification to community credit for url {0} in category {1} for user {2}", url, category, email); result = wsCommunityCredit.AddCommunityCredit(email, firstName, lastName, description, url, category, affiliateCode, affiliateKey); Log.InfoFormat("Response Received was: {0}", result); if (!result.Equals("Success")) { throw new CommunityCreditNotificationException(result); } } }
public void Ctor_WithAllNonNullArgs_SetsProperties() { //arrange var requestContext = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData()); var urlHelper = new BlogUrlHelper(requestContext, new RouteCollection()); ObjectRepository objectRepository = new Mock <ObjectRepository>().Object; var blog = new Blog(); //act var subtextContext = new SubtextContext(blog, requestContext, urlHelper, objectRepository, null, null, null); //assert Assert.AreEqual(blog, subtextContext.Blog); Assert.AreEqual(urlHelper, subtextContext.UrlHelper); Assert.AreEqual(requestContext, subtextContext.RequestContext); Assert.AreEqual(objectRepository, subtextContext.Repository); }
public void GalleryImageUrl_WithBlogHavingNoSubfolderAndImageHavingNullUrlAndFileName_ReturnsUrlToImage() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var blog = new Blog { Host = "localhost", Subfolder = "" }; var image = new Image { Blog = blog, Url = null, FileName = "open.gif", CategoryID = 1234 }; //act string url = helper.GalleryImageUrl(image, image.OriginalFile); //assert Assert.AreEqual("/images/localhost/1234/o_open.gif", url); }
public void GalleryDirectoryPath_WithBlogAndCategoryId_ReturnPhysicalDirectoryPath() { // arrange BlogUrlHelper helper = UnitTestHelper.SetupUrlHelper("/Subtext.Web"); Mock <HttpContextBase> httpContext = Mock.Get(helper.HttpContext); httpContext.Setup(c => c.Server.MapPath("/Subtext.Web/images/localhost/Subtext_Web/123/")).Returns( @"c:\123\"); var blog = new Blog { Host = "localhost", Subfolder = "" }; // act string path = helper.GalleryDirectoryPath(blog, 123); // assert Assert.AreEqual(@"c:\123\", path); }
public void FeedbackUrl_WithEntryHavingNoEntryName_RendersVirtualPathWithFeedbackIdInFragment() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); var datePublishedUtc = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); var comment = new FeedbackItem(FeedbackType.Comment) { Id = 321, EntryId = 1234, ParentDatePublishedUtc = datePublishedUtc }; //act string url = helper.FeedbackUrl(comment); //assert Assert.AreEqual("/archive/2008/01/23/1234.aspx#321", url); }
/// <summary> /// Converts a LinkCategoryCollection into a single LinkCategory with its own LinkCollection. /// </summary> public static LinkCategory MergeLinkCategoriesIntoSingleLinkCategory(string title, CategoryType catType, IEnumerable <LinkCategory> links, BlogUrlHelper urlHelper, Blog blog) { if (!links.IsNullOrEmpty()) { var mergedLinkCategory = new LinkCategory { Title = title }; var merged = from linkCategory in links select GetLinkFromLinkCategory(linkCategory, catType, urlHelper, blog); mergedLinkCategory.Links.AddRange(merged); return(mergedLinkCategory); } return(null); }
public void EntryUrl_WithEntryWhichIsReallyAnArticle_ReturnsArticleLink() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); DateTime datePublished = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); var entry = new Entry(PostType.BlogPost) { Id = 123, DateCreatedUtc = datePublished.AddDays(-4), DatePublishedUtc = datePublished, EntryName = "post-slug", PostType = PostType.Story }; //act string url = helper.EntryUrl(entry); //assert Assert.AreEqual("/articles/post-slug.aspx", url); }
public static int Create(Entry entry) { var requestContext = new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()); var serviceLocator = new Mock <IDependencyResolver>().Object; var searchEngineService = new Mock <IIndexingService>().Object; DependencyResolver.SetResolver(serviceLocator); var routes = new RouteCollection(); var subtextRoutes = new SubtextRouteMapper(routes, serviceLocator); Routes.RegisterRoutes(subtextRoutes); var urlHelper = new BlogUrlHelper(requestContext, routes); var subtextContext = new SubtextContext(Config.CurrentBlog, requestContext, urlHelper, new DatabaseObjectProvider(), requestContext.HttpContext.User, new SubtextCache(requestContext.HttpContext.Cache), serviceLocator); IEntryPublisher entryPublisher = CreateEntryPublisher(subtextContext, searchEngineService); int id = entryPublisher.Publish(entry); entry.Id = id; return(id); }
public void FeedbackUrl_WithEntryIdEqualToIntMinValue_ReturnsNull() { //arrange BlogUrlHelper helper = SetupUrlHelper("/"); DateTime dateCreated = DateTime.ParseExact("2008/01/23", "yyyy/MM/dd", CultureInfo.InvariantCulture); var comment = new FeedbackItem(FeedbackType.Comment) { Id = 123, Entry = new Entry(PostType.BlogPost) { Id = NullValue.NullInt32, DateCreatedUtc = dateCreated, EntryName = "post-slug" } }; //act string url = helper.FeedbackUrl(comment); //assert Assert.IsNull(url); }