public void ConvertBlogPost_WithPostHavingBase64EncodedExcerpt_DecodesContent()
        {
            // arrange
            var post = new BlogMLPost {
                HasExcerpt = true, Excerpt = BlogMLContent.Create("This is a story about a 3 hour voyage", ContentTypes.Base64)
            };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual("This is a story about a 3 hour voyage", entry.Description);
        }
        public void ConvertBlogPost_WithNullTitleNameButWithPostUrlContainingBlogSpotDotCom_UsesLastSegmentAsTitle()
        {
            // arrange
            var post = new BlogMLPost {
                PostUrl = "http://example.blogspot.com/2003/07/the-last-segment.html"
            };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual("the last segment", entry.Title);
        }
        public void ConvertBlogPost_WithPostHavingNoTitleAndNoPostName_UsesPostId()
        {
            // arrange
            var post = new BlogMLPost {
                Title = null, PostName = null, ID = "87618298"
            };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual("Post #87618298", entry.Title);
        }
Beispiel #4
0
 private void SetEntryCategories(BlogMLPost post, Entry newEntry, BlogMLBlog blog)
 {
     if (post.Categories.Count > 0)
     {
         foreach (BlogMLCategoryReference categoryRef in post.Categories)
         {
             string categoryTitle = GetCategoryTitleById(categoryRef.Ref, blog.Categories);
             if (categoryTitle != null)
             {
                 newEntry.Categories.Add(categoryTitle);
             }
         }
     }
 }
Beispiel #5
0
 private static void SetEntryNameForBlogspotImport(BlogMLPost post, Entry newEntry)
 {
     if (!String.IsNullOrEmpty(post.PostUrl) &&
         post.PostUrl.Contains("blogspot.com/", StringComparison.OrdinalIgnoreCase))
     {
         Uri    postUrl  = post.PostUrl.ParseUri();
         string fileName = postUrl.Segments.Last();
         newEntry.EntryName = Path.GetFileNameWithoutExtension(fileName);
         if (String.IsNullOrEmpty(post.Title) && String.IsNullOrEmpty(post.PostName))
         {
             newEntry.Title = newEntry.EntryName.Replace("-", " ").Replace("+", " ").Replace("_", " ");
         }
     }
 }
        public void ConvertBlogPost_WithTitleTooLong_TruncatesTitleToMaxLength()
        {
            // arrange
            var title = new string('a', 256);
            var post  = new BlogMLPost {
                Title = title
            };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual(255, entry.Title.Length);
        }
Beispiel #7
0
        private void ImportTags(XDocument xdoc, IContent postNode, BlogMLPost post)
        {
            //since this blobml serializer doesn't support tags (can't find one that does) we need to manually take care of that
            var xmlPost = xdoc.Descendants(XName.Get("post", xdoc.Root.Name.NamespaceName))
                          .SingleOrDefault(x => ((string)x.Attribute("id")) == post.Id);

            if (xmlPost == null)
            {
                return;
            }

            var tags = xmlPost.Descendants(XName.Get("tag", xdoc.Root.Name.NamespaceName)).Select(x => (string)x.Attribute("ref")).ToArray();

            postNode.SetTags("tags", tags, true, "ArticulateTags");
        }
        public void ConvertBlogPost_WithPostHavingExcerpt_SetsEntryDescription()
        {
            // arrange
            var post = new BlogMLPost {
                HasExcerpt = true, Excerpt = new BlogMLContent {
                    Text = "This is a story about a 3 hour voyage"
                }
            };
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.AreEqual("This is a story about a 3 hour voyage", entry.Description);
        }
Beispiel #9
0
        private string getAuthorId(Dictionary <string, User> usersList, BlogMLPost post)
        {
            string authorId;
            User   user;

            if (post.Authors.Count > 0 &&
                usersList.TryGetValue(post.Authors.Cast <BlogMLAuthorReference>().First().Ref, out user))
            {
                authorId = user.Id;
            }
            else
            {
                authorId = usersList.First().Value.Id;
            }
            return(authorId);
        }
Beispiel #10
0
        public void Import_WithCreateTrackbackThrowingException_DoesNotPropagateException()
        {
            // arrange
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();

            post.Trackbacks.Add(new BlogMLTrackback());
            blog.Posts.Add(post);
            var repository = new Mock <IBlogImportRepository>();

            repository.Setup(r => r.CreateTrackback(It.IsAny <BlogMLTrackback>(), It.IsAny <string>())).Throws(new InvalidOperationException());
            var service = new BlogImportService(repository.Object);

            // act, assert
            service.Import(blog);
        }
 private static void SetEntryAuthor(BlogMLPost post, Entry newEntry, BlogMLBlog blog)
 {
     if (post.Authors.Count > 0)
     {
         foreach (BlogMLAuthor author in blog.Authors)
         {
             if (author.ID != post.Authors[0].Ref)
             {
                 continue;
             }
             newEntry.Author = author.Title.Left(AuthorTitleMaxLength);
             newEntry.Email  = author.Email;
             break;
         }
     }
 }
        public void ConvertBlogPost_WithDateModified_ReturnsItAsDatePublishedUtc()
        {
            // arrange
            DateTime utcNow = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            var      post   = new BlogMLPost {
                Approved = true, DateModified = utcNow
            };
            var blog   = new Mock <Blog>();
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), blog.Object);

            // assert
            Assert.AreEqual(utcNow, entry.DatePublishedUtc);
        }
        public string GetSuggestedFilenameFromTitle(BlogMLPost post)
        {
            var postTitle = post.Title;

            if (string.IsNullOrEmpty(postTitle))
            {
                return(string.Empty);
            }
            if (string.IsNullOrEmpty(postTitle))
            {
                return(string.Empty);
            }
            var filename = post.DateCreated.ToString("yyyy-MM-dd-") + postTitle.ToSlug(true);

            return(filename);
        }
Beispiel #14
0
        public void Write_WithBlogContainingEmbeddedAttachmentsWithComments_WritesPostAttachmentsToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost {
                Title = "This is a blog post"
            };
            var attachment = new BlogMLAttachment
            {
                Data     = new byte[] { 1, 2, 3, 4, 5 },
                Path     = @"c:\\path-to-attachment.jpg",
                Url      = "/foo/path-to-attachment.jpg",
                Embedded = true,
                MimeType = "img/jpeg"
            };

            post.Attachments.Add(attachment);
            var posts = new List <BlogMLPost> {
                post
            };

            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"external-uri=""c:\\path-to-attachment.jpg""");
            Assert.Contains(output, @"url=""/foo/path-to-attachment.jpg""");
            Assert.Contains(output, @"mime-type=""img/jpeg""");
            Assert.Contains(output, @"embedded=""true""");
            Assert.Contains(output, @"AQIDBAU=</attachment>");
        }
        public void ConvertBlogPost_WithApprovedPost_SetsAppropriatePublishPropertiesOfEntry()
        {
            // arrange
            var post = new BlogMLPost {
                Approved = true
            };
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), null);

            // assert
            Assert.IsTrue(entry.IsActive);
            Assert.IsTrue(entry.DisplayOnHomePage);
            Assert.IsTrue(entry.IncludeInMainSyndication);
            Assert.IsTrue(entry.IsAggregated);
        }
Beispiel #16
0
        public BlogMLPost ConvertEntry(EntryStatsView entry, bool embedAttachments)
        {
            string postUrl          = null;
            var    entryVirtualPath = Url.EntryUrl(entry);

            if (entryVirtualPath != null)
            {
                postUrl = entryVirtualPath.ToFullyQualifiedUrl(Blog).ToString();
            }
            var post = new BlogMLPost
            {
                Title        = entry.Title,
                PostUrl      = postUrl,
                PostType     = (entry.PostType == PostType.Story) ? BlogPostTypes.Article : BlogPostTypes.Normal,
                Approved     = entry.IsActive,
                Content      = BlogMLContent.Create(entry.Body ?? string.Empty, ContentTypes.Base64),
                HasExcerpt   = entry.HasDescription,
                Excerpt      = BlogMLContent.Create(entry.Description ?? string.Empty, ContentTypes.Base64),
                DateCreated  = Blog.TimeZone.ToUtc(entry.DateCreated),
                DateModified = Blog.TimeZone.ToUtc(entry.IsActive ? entry.DateSyndicated : entry.DateModified),
                Views        = (uint)entry.WebCount
            };

            if (entry.HasEntryName)
            {
                post.PostName = entry.EntryName;
            }

            // When we support multiple authors, this will have to change
            post.Authors.Add(Blog.Id.ToString(CultureInfo.InvariantCulture));
            post.Attachments.AddRange(GetPostAttachments(entry.Body, embedAttachments).ToArray());
            var comments = (from c in entry.Comments where c.FeedbackType == FeedbackType.Comment select ConvertComment(c)).ToList();

            if (comments.Count > 0)
            {
                post.Comments.AddRange(comments);
            }
            var trackbacks = (from c in entry.Comments where c.FeedbackType == FeedbackType.PingTrack select ConvertTrackback(c)).ToList();

            if (trackbacks.Count > 0)
            {
                post.Trackbacks.AddRange(trackbacks);
            }
            return(post);
        }
        public void ConvertBlogPost_WithSyndicatedDate_ConvertsDateToBlogTimezone()
        {
            // arrange
            DateTime utcNow = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            var      post   = new BlogMLPost {
                Approved = true, DateModified = utcNow
            };
            var      blog     = new Mock <Blog>();
            DateTime expected = DateTime.ParseExact("2009/08/15 05:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);

            blog.Setup(b => b.TimeZone.FromUtc(utcNow)).Returns(expected);
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, new BlogMLBlog(), blog.Object);

            // assert
            Assert.AreEqual(expected, entry.DateSyndicated);
        }
Beispiel #18
0
        public void CreateBlogPost_WithEntryPublisher_PublishesBlogPostAndReturnsId()
        {
            // arrange
            var context = new Mock <ISubtextContext>();

            context.Setup(c => c.Blog.TimeZone.FromUtc(It.IsAny <DateTime>())).Returns(DateTime.Now);
            var entryPublisher = new Mock <IEntryPublisher>();

            entryPublisher.Setup(p => p.Publish(It.IsAny <Entry>())).Returns(310);
            var blog       = new BlogMLBlog();
            var post       = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher.Object, new BlogMLImportMapper());

            // act
            var id = repository.CreateBlogPost(blog, post);

            // assert
            Assert.AreEqual("310", id);
        }
        public string CreateBlogPost(BlogMLBlog blog, BlogMLPost post)
        {
            Entry newEntry = Mapper.ConvertBlogPost(post, blog, Blog);

            newEntry.BlogId = Blog.Id;
            newEntry.Blog   = Blog;
            var publisher = EntryPublisher as EntryPublisher;

            if (publisher != null)
            {
                var transform = publisher.Transformation as CompositeTextTransformation;
                if (transform != null)
                {
                    transform.Clear();
                }
            }

            return(EntryPublisher.Publish(newEntry).ToString(CultureInfo.InvariantCulture));
        }
        public void Process(BlogMLPost postml)
        {
            Log.DebugFormat("Setting up category references on post {0}", postml.ID);

            using (var query = new OxiteReader("SELECT * FROM oxite_Post A, oxite_PostTagRelationship B WHERE A.PostID=B.PostID AND A.PostID='" + postml.ID + "'"))
            {
                var tagRefs = query.Execute();

                foreach (var tag in tagRefs)
                {
                    var commentRef = new BlogMLCategoryReference
                    {
                        Ref = tag.TagID.ToString()
                    };

                    postml.Categories.Add(commentRef);
                }
            }
        }
Beispiel #21
0
        public void Write_WithBlogContainingMultipleAuthors_WritesPostAuthorsToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            blog.Authors.Add(new BlogMLAuthor {
                ID = "10"
            });
            blog.Authors.Add(new BlogMLAuthor {
                ID = "20"
            });
            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost {
                Title = "This is a blog post"
            };

            post.Authors.Add(new BlogMLAuthorReference {
                Ref = "20"
            });
            var posts = new List <BlogMLPost> {
                post
            };

            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"<author ref=""20"" />");
        }
Beispiel #22
0
 protected void WriteStartBlogMLPost(BlogMLPost post)
 {
     WriteStartElement("post");
     WriteNodeAttributes(post.ID, post.DateCreated, post.DateModified, post.Approved);
     WriteAttributeString("post-url", post.PostUrl);
     WriteAttributeStringRequired("type", "normal");
     WriteAttributeStringRequired("hasexcerpt", post.HasExcerpt.ToString().ToLowerInvariant());
     WriteAttributeStringRequired("views", post.Views.ToString());
     WriteContent("title", BlogMLContent.Create(post.Title, ContentTypes.Text));
     WriteBlogMLContent("content", post.Content);
     if (!string.IsNullOrEmpty(post.PostName))
     {
         WriteContent("post-name", BlogMLContent.Create(post.PostName, ContentTypes.Text));
     }
     if (post.HasExcerpt)
     {
         WriteBlogMLContent("excerpt", post.Excerpt);
     }
 }
Beispiel #23
0
        public string CreateFilesFromAttachments(BlogMLPost post)
        {
            string postContent = post.Content.UncodedText;

            foreach (BlogMLAttachment bmlAttachment in post.Attachments)
            {
                string assetDirPath = Repository.GetAttachmentDirectoryPath();
                string assetDirUrl  = Repository.GetAttachmentDirectoryUrl();

                if (!String.IsNullOrEmpty(assetDirPath) && !String.IsNullOrEmpty(assetDirUrl))
                {
                    if (!Directory.Exists(assetDirPath))
                    {
                        Directory.CreateDirectory(assetDirPath);
                    }
                    postContent = CreateFileFromAttachment(bmlAttachment, assetDirPath, assetDirUrl, postContent);
                }
            }
            return(postContent);
        }
        public void ConvertBlogPost_WithAuthorTitleTooLong_TruncatesTitleToMaxLength()
        {
            // arrange
            var title = new string('a', 51);
            var blog  = new BlogMLBlog();

            blog.Authors.Add(new BlogMLAuthor {
                ID = "123", Title = title
            });
            var post = new BlogMLPost();

            post.Authors.Add("123");
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual(50, entry.Author.Length);
        }
Beispiel #25
0
        private void ProcessPosts(BlogMLBlog blogml)
        {
            Log.Info("Fetching blog posts.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Post"))
            {
                var posts = query.Execute();

                foreach (var post in posts)
                {
                    var postml = new BlogMLPost
                    {
                        Content = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text        = post.Body
                        },
                        Excerpt = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text        = post.BodyShort
                        },
                        Approved     = post.State == (int)RecordStates.Normal,
                        DateCreated  = post.CreatedDate,
                        DateModified = post.ModifiedDate,
                        HasExcerpt   = !string.IsNullOrWhiteSpace(post.BodyShort),
                        ID           = post.PostID.ToString(),
                        PostName     = post.Title,
                        PostType     = BlogPostTypes.Normal,
                        PostUrl      = post.Slug,
                        Title        = post.Title,
                    };

                    blogml.Posts.Add(postml);
                }

                Log.InfoFormat("Finished adding {0} posts.", blogml.Posts.Count);
            }
        }
        private void LoadBlogExtendedPosts(BlogMLBlog blog)
        {
            foreach (var post in blog.Posts)
            {
                BlogMLPost p = post;

                blogsExtended.Where(b => b.PostUrl == p.PostUrl).FirstOrDefault().BlogPost = post;

                //if (post.PostType == BlogPostTypes.Normal)
                //{
                //    BlogMLPost p = post;

                //    blogsExtended.Where(b => b.PostUrl == p.PostUrl).FirstOrDefault().BlogPost = post;
                //}
                //else if (post.PostType == BlogPostTypes.Article)
                //{
                //    BlogMLPost p = post;

                //    blogsExtended.Where(b => b.PostUrl == p.PostUrl).FirstOrDefault().BlogPost = post;
                //}
            }
        }
Beispiel #27
0
        private bool ValidateModel(BlogPostViewModel blogPostModel, BlogMLPost blogML, out BlogPostImportResult failedResult)
        {
            failedResult = null;

            if (string.IsNullOrWhiteSpace(blogML.ID))
            {
                failedResult = CreateFailedResult(blogML);
                failedResult.ErrorMessage = BlogGlobalization.ImportBlogPosts_ImportingBlogPostIdIsNotSet_Message;

                return(false);
            }

            var validationContext = new ValidationContext(blogPostModel, null, null);
            var validationResults = new List <ValidationResult>();

            if (!Validator.TryValidateObject(blogPostModel, validationContext, validationResults, true) &&
                validationResults.Count > 0)
            {
                failedResult = CreateFailedResult(blogML);
                failedResult.ErrorMessage = validationResults[0].ErrorMessage;

                return(false);
            }

            try
            {
                pageService.ValidatePageUrl(blogPostModel.BlogUrl);
            }
            catch (Exception exc)
            {
                failedResult = CreateFailedResult(blogML);
                failedResult.ErrorMessage = exc.Message;

                return(false);
            }

            return(true);
        }
Beispiel #28
0
        public void Write_WithBlogContainingTrackbacksWithComments_WritesPostTrackbacksToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost {
                Title = "This is a blog post"
            };

            post.Trackbacks.Add(new BlogMLTrackback {
                Title = "Post Test Trackback", Url = "http://example.com/trackback-source"
            });
            var posts = new List <BlogMLPost> {
                post
            };

            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"<title type=""text""><![CDATA[Post Test Trackback]]></title>");
            Assert.Contains(output, @"url=""http://example.com/trackback-source""");
        }
Beispiel #29
0
        public void Import_WithBlogPostHavingComments_CreatesCommentUsingPostId()
        {
            // arrange
            var blog    = new BlogMLBlog();
            var post    = new BlogMLPost();
            var comment = new BlogMLComment();

            post.Comments.Add(comment);
            blog.Posts.Add(post);
            var repository = new Mock <IBlogImportRepository>();

            repository.Setup(r => r.CreateBlogPost(blog, post)).Returns("98053");
            bool commentCreated = false;

            repository.Setup(r => r.CreateComment(comment, "98053")).Callback(() => commentCreated = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(commentCreated);
        }
Beispiel #30
0
        public void Import_WithBlogPostHavingTrackback_CreatesTrackbackUsingPostId()
        {
            // arrange
            var blog      = new BlogMLBlog();
            var post      = new BlogMLPost();
            var trackback = new BlogMLTrackback();

            post.Trackbacks.Add(trackback);
            blog.Posts.Add(post);
            var repository = new Mock <IBlogImportRepository>();

            repository.Setup(r => r.CreateBlogPost(blog, post)).Returns("98053");
            bool trackbackCreated = false;

            repository.Setup(r => r.CreateTrackback(trackback, "98053")).Callback(() => trackbackCreated = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(trackbackCreated);
        }