Summary description for EntryStatsView.
Наследование: Entry
Пример #1
0
 public void CanSetAndGetSimpleEntryStatsViewProperties()
 {
     string host = UnitTestHelper.GenerateRandomString();
     Config.CreateBlog("title", "blah", "blah", host, string.Empty);
     UnitTestHelper.SetHttpContextWithBlogRequest(host, string.Empty);
     EntryStatsView view = new EntryStatsView();
     UnitTestHelper.AssertSimpleProperties(view);
 }
Пример #2
0
 public void CanSetAndGetSimpleEntryStatsViewProperties()
 {
     string host = UnitTestHelper.GenerateUniqueString();
     var repository = new DatabaseObjectProvider();
     repository.CreateBlogInternal("title", "blah", "blah", host, string.Empty, 1);
     UnitTestHelper.SetHttpContextWithBlogRequest(host, string.Empty);
     BlogRequest.Current.Blog = repository.GetBlog(host, string.Empty);
     var view = new EntryStatsView();
     UnitTestHelper.AssertSimpleProperties(view);
 }
Пример #3
0
        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);
        }
Пример #4
0
        //Crappy. Need to clean up all of the entry references
        public static EntryStatsView LoadEntryStatsView(IDataReader reader)
        {
            EntryStatsView entry = new EntryStatsView();

            entry.PostType = ((PostType)ReadInt32(reader, "PostType"));

            if(reader["WebCount"] != DBNull.Value)
            {
                entry.WebCount = ReadInt32(reader, "WebCount");
            }

            if(reader["AggCount"] != DBNull.Value)
            {
                entry.AggCount = ReadInt32(reader, "AggCount");
            }

            if(reader["WebLastUpdated"] != DBNull.Value)
            {
                entry.WebLastUpdated = (DateTime)reader["WebLastUpdated"];
            }

            if(reader["AggLastUpdated"] != DBNull.Value)
            {
                entry.AggLastUpdated = (DateTime)reader["AggLastUpdated"];
            }

            if(reader["Author"] != DBNull.Value)
            {
                entry.Author = ReadString(reader, "Author");
            }
            if(reader["Email"] != DBNull.Value)
            {
                entry.Email = ReadString(reader, "Email");
            }
            entry.DateCreated = (DateTime)reader["DateAdded"];

            if(reader["DateUpdated"] != DBNull.Value)
            {
                entry.DateModified = (DateTime)reader["DateUpdated"];
            }

            entry.Id = ReadInt32(reader, "ID");

            if(reader["Description"] != DBNull.Value)
            {
                entry.Description = ReadString(reader, "Description");
            }

            if(reader["EntryName"] != DBNull.Value)
            {
                entry.EntryName = ReadString(reader, "EntryName");
            }

            if(reader["FeedBackCount"] != DBNull.Value)
            {
                entry.FeedBackCount = ReadInt32(reader, "FeedBackCount");
            }

            if(reader["Text"] != DBNull.Value)
            {
                entry.Body = ReadString(reader, "Text");
            }

            if(reader["Title"] != DBNull.Value)
            {
                entry.Title =ReadString(reader, "Title");
            }

            if(reader["PostConfig"] != DBNull.Value)
            {
                entry.PostConfig = (PostConfig)(ReadInt32(reader, "PostConfig"));
            }

            if(reader["DateSyndicated"] != DBNull.Value)
            {
                entry.DateSyndicated = (DateTime)reader["DateSyndicated"];
            }

            SetUrlPattern(entry);

            return entry;
        }
Пример #5
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 = entry.DateCreatedUtc,
                DateModified = entry.IsActive ? entry.DatePublishedUtc : entry.DateModifiedUtc,
                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 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_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 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 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);
        }
        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));
        }