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);
        }
        public void Import_WithEmbeddedAttachments_CreatesFilesForAttachmentsAndRewritesBlogPost()
        {
            // arrange
            var data = new byte[] { 1, 2, 3 };
            var attachment = new BlogMLAttachment { Url = "http://old.example.com/images/my-mug.jpg", Embedded = true, Data = data };
            var post = new BlogMLPost { Content = new BlogMLContent { Text = @"<img src=""http://old.example.com/images/my-mug.jpg"" />" } };
            post.Attachments.Add(attachment);
            var blog = new BlogMLBlog();
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.GetAttachmentDirectoryPath()).Returns(ImageDirectory + "/wlw");
            repository.Setup(r => r.GetAttachmentDirectoryUrl()).Returns("http://example.com/images/wlw/");
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(File.Exists(Path.Combine(ImageDirectory, @"wlw\my-mug.jpg")));
            Assert.AreEqual(@"<img src=""http://example.com/images/wlw/my-mug.jpg"" />", post.Content.UncodedText);
        }
        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);
        }
        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);
        }
        public void Import_WithBlogPostHavingBase64EncodedContentWithAttachments_ProperlyRewritesAttachments()
        {
            // arrange
            var blog = new BlogMLBlog();
            const string originalPostContent = @"<img src=""http://old.example.com/images/my-mug.jpg"" />";
            var post = new BlogMLPost { Content = BlogMLContent.Create(originalPostContent, ContentTypes.Base64) };
            var attachment = new BlogMLAttachment { Url = "http://old.example.com/images/my-mug.jpg", Embedded = false};
            post.Attachments.Add(attachment);
            blog.Posts.Add(post);
            var repository = new Mock<IBlogImportRepository>();
            repository.Setup(r => r.GetAttachmentDirectoryUrl()).Returns("http://new.example.com/images/");
            repository.Setup(r => r.GetAttachmentDirectoryPath()).Returns(@"c:\web\images");
            BlogMLPost publishedPost = null;
            repository.Setup(r => r.CreateBlogPost(blog, post)).Callback<BlogMLBlog, BlogMLPost>((b, p) => publishedPost = p);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.AreEqual(ContentTypes.Base64, publishedPost.Content.ContentType);
            Assert.AreEqual(@"<img src=""http://new.example.com/images/my-mug.jpg"" />", publishedPost.Content.UncodedText);
        }
        public void Import_WithBlogHavingCategories_CreatesCategories()
        {
            // arrange
            var blog = new BlogMLBlog();
            var repository = new Mock<IBlogImportRepository>();
            bool categoriesCreated = false;
            repository.Setup(r => r.CreateCategories(blog)).Callback(() => categoriesCreated = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(categoriesCreated);
        }
        public void Import_SetsExtendedPropertiesOnBlog()
        {
            // arrange
            var blog = new BlogMLBlog();
            var repository = new Mock<IBlogImportRepository>();
            bool extendedPropertiesSet = false;
            repository.Setup(r => r.SetExtendedProperties(blog.ExtendedProperties)).Callback(() => extendedPropertiesSet = true);
            var service = new BlogImportService(repository.Object);

            // act
            service.Import(blog);

            // assert
            Assert.IsTrue(extendedPropertiesSet);
        }