Exemplo n.º 1
0
        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 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 ConvertComment_WithNullFeedBackItem_ThrowsArgumentNullException()
        {
            // arrange
            var subtextContext = new Mock<ISubtextContext>();
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act, assert
            UnitTestHelper.AssertThrows<ArgumentException>(() => converter.ConvertComment(null));
        }
        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 ConvertComment_WithFeedBackItem_ConvertsBodyToBase64EncodedText()
        {
            // arrange
            var feedback = new FeedbackItem(FeedbackType.Comment)
            {
                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.ConvertComment(feedback);

            // assert
            Assert.AreEqual("213", comment.ID);
            Assert.AreEqual("Comment Title", comment.Title);
            Assert.IsTrue(comment.Approved);
            Assert.AreEqual("Anonymous Troll", comment.UserName);
            Assert.AreEqual("*****@*****.**", comment.UserEMail);
            Assert.AreEqual("http://subtextproject.com/", comment.UserUrl);
            Assert.AreEqual("<p>First!</p>", comment.Content.Text);
        }
        public void ConvertComment_WithFeedBackItemHavingNonCommentFeedbackType_ThrowsArgumentException()
        {
            // arrange
            var feedback = new FeedbackItem(FeedbackType.PingTrack);
            var subtextContext = new Mock<ISubtextContext>();
            var converter = new BlogMLExportMapper(subtextContext.Object);

            // act, assert
            UnitTestHelper.AssertThrows<ArgumentException>(() => converter.ConvertComment(feedback));
        }