public void ConvertComment_WithDateCreated_ConvertsToUtc()
        {
            // arrange
            DateTime dateCreatedUtc = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal).ToUniversalTime();
            var feedback = new FeedbackItem(FeedbackType.Comment)
            {
                DateCreatedUtc = dateCreatedUtc,
            };
            var subtextContext = new Mock<ISubtextContext>();
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var comment = converter.ConvertComment(feedback);

            // assert
            Assert.AreEqual(dateCreatedUtc, comment.DateCreated);
        }
        public void ConvertCategories_WithBlogCategories_ConvertsToBLogMLCategories()
        {
            // arrange
            var categories = new List<LinkCategory> {new LinkCategory(1, "Category Uno"), new LinkCategory(2, "Category Dos")};
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "example.com" });
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var blogMLCategories = converter.ConvertCategories(categories);

            // assert
            Assert.AreEqual(2, blogMLCategories.Count());
            Assert.AreEqual("Category Uno", blogMLCategories.First().Title);
            Assert.AreEqual("Category Dos", blogMLCategories.ElementAt(1).Title);
        }
        public void ConvertBlog_WithSubtextBlog_ReturnsCorrespondingBlogMLBlog()
        {
            // arrange
            var blog = new Blog {Title = "Test Blog Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true};
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(blog);
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var blogMLBlog = converter.ConvertBlog(blog);

            // assert
            Assert.AreEqual("Test Blog Title", blogMLBlog.Title);
            Assert.AreEqual("Test Blog Subtitle", blogMLBlog.SubTitle);
            Assert.AreEqual("http://example.com/", blogMLBlog.RootUrl);
            Assert.AreEqual("Charles Dickens", blogMLBlog.Authors[0].Title);
            Assert.AreEqual(BlogMLBlogExtendedProperties.CommentModeration, blogMLBlog.ExtendedProperties[0].Key);
            Assert.AreEqual("Enabled", blogMLBlog.ExtendedProperties[0].Value);
        }
        public void GetBlogPosts_WithBlogPostHavingCategories_ReturnsPostsWithCategories()
        {
            // arrange
            var categories = new List<LinkCategory> { new LinkCategory(1, "Category Title"), new LinkCategory(2, "Some Other Category Title") };
            var blog = new Blog { Title = "Irrelevant Title", SubTitle = "Test Blog Subtitle", Author = "Charles Dickens", Host = "example.com", ModerationEnabled = true };
            var entry = new EntryStatsView {Title = "Test Post Title"};
            entry.Categories.Add("Some Other Category Title");
            var posts = new PagedCollection<EntryStatsView> { entry };
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(blog);
            context.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            context.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant");
            context.Setup(c => c.Repository.GetCategories(CategoryType.PostCollection, false /*activeOnly*/)).Returns(categories);
            context.Setup(c => c.Repository.GetEntriesForExport(It.IsAny<int>() /*pageIndex*/, 100 /*pageSize*/)).Returns(posts);
            var converter = new BlogMLExportMapper(context.Object);
            var source = new BlogMLSource(context.Object, converter);

            // act
            var blogMLPosts = source.GetBlogPosts(false /*embedAttachments*/);

            // assert
            Assert.AreEqual("2", blogMLPosts.First().Categories[0].Ref);
        }
        public void ConvertEntry_WithEntry_ConvertsToBLogMLPostWithPostUrl()
        {
            // arrange
            var entry = new EntryStatsView { EntryName = "my-cool-post" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "foo.example.com" });
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/my-cool-post.aspx");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual("http://foo.example.com/my-cool-post.aspx", post.PostUrl);
        }
        public void GetPostAttachments_WithImageSrcAsVirtualPath_ReturnsAttachment()
        {
            // arrange
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "test.example.com" });
            subtextContext.Setup(c => c.UrlHelper.AppRoot()).Returns("/");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var attachments = converter.GetPostAttachments(@"<em>Test <img src=""/images/foo.jpg"" /></em>", false);

            // assert
            Assert.AreEqual(1, attachments.Count());
            Assert.AreEqual("/images/foo.jpg", attachments.First().Path);
            Assert.AreEqual("/images/foo.jpg", attachments.First().Url);
        }
        public void ConvertComment_WithDateModified_ConvertsToUtc()
        {
            // arrange
            DateTime dateModified = DateTime.ParseExact("2009/08/15 05:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
            DateTime dateModifiedUtc = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            var feedback = new FeedbackItem(FeedbackType.Comment)
            {
                DateModified = dateModified,
            };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog.TimeZone.ToUtc(dateModified)).Returns(dateModifiedUtc);
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var comment = converter.ConvertComment(feedback);

            // assert
            Assert.AreEqual(dateModifiedUtc, comment.DateModified);
        }
        public void ConvertTrackback_WithFeedBackItem_ConvertsToBlogMlComment()
        {
            // arrange
            var feedback = new FeedbackItem(FeedbackType.PingTrack)
            {
                Id = 213,
                Title = "Comment Title",
                Approved = true,
                Author = "Anonymous Troll",
                Email = "*****@*****.**",
                SourceUrl = new Uri("http://subtextproject.com/"),
                Body = "<p>First!</p>",
            };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog());
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var comment = converter.ConvertTrackback(feedback);

            // assert
            Assert.AreEqual("213", comment.ID);
            Assert.AreEqual("Comment Title", comment.Title);
            Assert.IsTrue(comment.Approved);
            Assert.AreEqual("http://subtextproject.com/", comment.Url);
        }
        public void ConvertTrackback_WithNullFeedBackItem_ThrowsArgumentNullException()
        {
            // arrange
            var subtextContext = new Mock<ISubtextContext>();
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act, assert
            UnitTestHelper.AssertThrows<ArgumentException>(() => converter.ConvertTrackback(null));
        }
        public void ConvertTrackback_WithDateModified_ConvertsDateModifiedToUtc()
        {
            // arrange
            DateTime dateModified = DateTime.ParseExact("2009/08/15 05:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
            DateTime dateModifiedUtc = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);

            var dateCreated = DateTime.Now.AddDays(-1);
            var feedback = new FeedbackItem(FeedbackType.PingTrack)
            {
                Id = 213,
                Title = "Comment Title",
                Approved = true,
                Author = "Anonymous Troll",
                Email = "*****@*****.**",
                SourceUrl = new Uri("http://subtextproject.com/"),
                Body = "<p>First!</p>",
                DateCreated = dateCreated,
                DateModified = dateModified
            };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog.TimeZone.ToUtc(dateModified)).Returns(dateModifiedUtc);
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var comment = converter.ConvertTrackback(feedback);

            // assert
            Assert.AreEqual(dateModifiedUtc, comment.DateModified);
        }
        public void ConvertTrackback_WithFeedBackItemHavingNonTrackbackFeedbackType_ThrowsArgumentException()
        {
            // arrange
            var feedback = new FeedbackItem(FeedbackType.Comment);
            var subtextContext = new Mock<ISubtextContext>();
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act, assert
            UnitTestHelper.AssertThrows<ArgumentException>(() => converter.ConvertTrackback(feedback));
        }
        public void ConvertEntry_WithInActiveEntry_SetsDateModifiedToDateModified()
        {
            // arrange
            DateTime dateModified = DateTime.ParseExact("2009/08/15 05:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
            DateTime dateModifiedUtc = DateTime.ParseExact("2009/08/15 11:00 PM", "yyyy/MM/dd hh:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            var entry = new EntryStatsView { Title = "Test Entry", DateModified = dateModified, IsActive = false };
            var subtextContext = new Mock<ISubtextContext>();
            var blog = new Mock<Blog>();
            blog.Object.Host = "example.com";
            blog.Setup(b => b.TimeZone.ToUtc(dateModified)).Returns(dateModifiedUtc);
            subtextContext.Setup(c => c.Blog).Returns(blog.Object);
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual(dateModifiedUtc, post.DateModified);
        }
        public void ConvertEntry_WithEntryHavingAttachments_EmbedsAttachmentsWhenEmbedIsTrue()
        {
            // arrange
            var entry = new EntryStatsView { EntryName = "my-cool-post", Body = @"<div><img src=""/my-dogs.jpg"" />" };
            var subtextContext = new Mock<ISubtextContext>();
            string filePath = UnitTestHelper.UnpackEmbeddedBinaryResource("BlogMl.blank.gif", "blank.gif");
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 321, Host = "foo.example.com" });
            subtextContext.Setup(c => c.HttpContext.Server.MapPath("/my-dogs.jpg")).Returns(filePath);
            subtextContext.Setup(c => c.UrlHelper.AppRoot()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/my-cool-post.aspx");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, true /*embedAttachments*/);

            // assert
            Assert.AreEqual(1, post.Attachments.Count);
            var attachment = post.Attachments[0];
            Assert.IsTrue(attachment.Embedded);
            Assert.AreEqual("/my-dogs.jpg", attachment.Url);
            Assert.AreEqual("/my-dogs.jpg", attachment.Path);
            Assert.AreEqual("R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", Convert.ToBase64String(attachment.Data));
        }
        public void ConvertEntry_WithEntry_ConvertsToBLogMLPosts()
        {
            // arrange
            var entry = new EntryStatsView{ Title = "Test Entry"};
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "example.com" });
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual("Test Entry", post.Title);
        }
        public void ConvertComment_WithFeedBackItem_ConvertsToBlogMlComment()
        {
            // arrange
            var feedback = new FeedbackItem(FeedbackType.Comment) {
                Id = 213,
                Body = "<p><![CDATA[First!]]></p>",
            };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog());
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var comment = converter.ConvertComment(feedback);

            // assert
            Assert.AreEqual("<p><![CDATA[First!]]></p>", comment.Content.UncodedText);
            Assert.AreEqual(ContentTypes.Base64, comment.Content.ContentType);
        }
        public void ConvertEntry_WithEntry_ContvertsBodyAndExcerptToBase64Encoding()
        {
            // arrange
            var entry = new EntryStatsView { Body = "<style><![CDATA[Test]]></style>", Description = "<style><![CDATA[excerpt]]></style>" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Host = "example.com" });
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/irrelevant");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual("<style><![CDATA[Test]]></style>", post.Content.UncodedText);
            Assert.AreEqual(ContentTypes.Base64, post.Content.ContentType);
            Assert.AreEqual("<style><![CDATA[excerpt]]></style>", post.Excerpt.UncodedText);
            Assert.AreEqual(ContentTypes.Base64, post.Excerpt.ContentType);
        }
        public void ConvertEntry_WithEntryHavingNoDateSyndicated_DoesNotThrowNullReferenceException()
        {
            // arrange
            var entry = new EntryStatsView { Title = "Test Entry", DateCreated = DateTime.Now, IsActive = true };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>(), It.IsAny<Blog>())).Returns((VirtualPath)null);
            var blog = new Mock<Blog>();
            blog.Setup(b => b.TimeZone.ToUtc(It.IsAny<DateTime>())).Returns(DateTime.Now);
            blog.Object.Host = "example.com";
            subtextContext.Setup(c => c.Blog).Returns(blog.Object);
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.IsNotNull(post);
        }
        public void ConvertEntry_WithEntryHavingFullyQualifiedImage_IgnoresImage()
        {
            // arrange
            var entry = new EntryStatsView { EntryName = "my-cool-post", Body = @"<div><img src=""http://example.com/my-dogs.jpg"" />" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 321, Host = "foo.example.com" });
            subtextContext.Setup(c => c.UrlHelper.AppRoot()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/my-cool-post.aspx");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual(0, post.Attachments.Count);
        }
        public void ConvertEntry_WithEntryHavingCommentsAndTrackbacks_IncludesCommentsAndTrackbacks()
        {
            // arrange
            var entry = new EntryStatsView();
            entry.Comments.AddRange(new[] { new FeedbackItem(FeedbackType.Comment), new FeedbackItem(FeedbackType.Comment), new FeedbackItem(FeedbackType.PingTrack) });
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 321, Host = "foo.example.com" });
            subtextContext.Setup(c => c.UrlHelper.AppRoot()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/my-cool-post.aspx");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual(2, post.Comments.Count);
            Assert.AreEqual(1, post.Trackbacks.Count);
        }
        public void ConvertEntry_WithEntryHavingAttachments_IncludesAttachmentsWithoutEmbedding()
        {
            // arrange
            var entry = new EntryStatsView { EntryName = "my-cool-post", Body = @"<div><img src=""/my-dogs.jpg"" />" };
            var subtextContext = new Mock<ISubtextContext>();
            subtextContext.Setup(c => c.Blog).Returns(new Blog { Id = 321, Host = "foo.example.com" });
            subtextContext.Setup(c => c.UrlHelper.AppRoot()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.BlogUrl()).Returns("/");
            subtextContext.Setup(c => c.UrlHelper.EntryUrl(It.IsAny<IEntryIdentity>())).Returns("/my-cool-post.aspx");
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act
            var post = converter.ConvertEntry(entry, false /*embedAttachments*/);

            // assert
            Assert.AreEqual(1, post.Attachments.Count);
            var attachment = post.Attachments[0];
            Assert.IsFalse(attachment.Embedded);
            Assert.AreEqual("/my-dogs.jpg", attachment.Url);
        }