public void ImportBlog_WithStream_DeserializesBlog() { // arrange var stream = @"<?xml version=""1.0"" encoding=""utf-8""?> <blog root-url=""http://*****:*****@blogml.com""> <title type=""text""><![CDATA[The Author]]></title> </author> </authors> <posts> <post id=""b0e03eec-ab81-4dc4-a69b-374d57cfad5e"" date-created=""2006-01-07T03:31:32"" date-modified=""2006-01-07T03:31:32"" approved=""true"" post-url=""http://example.com/whatever""> <title type=""text""><![CDATA[Post Title]]></title> <content type=""base64""> <![CDATA[Q29udGVudCBvZiB0aGUgcG9zdA==]]> </content> <authors> <author ref=""2100"" /> </authors> </post> </posts> </blog>".ToStream(); var repository = new Mock<IBlogImportRepository>(); BlogMLPost deserializedPost = null; repository.Setup(r => r.CreateBlogPost(It.IsAny<BlogMLBlog>(), It.IsAny<BlogMLPost>())).Callback<BlogMLBlog, BlogMLPost>((blog, post) => deserializedPost = post); var service = new BlogImportService(repository.Object); // act service.ImportBlog(stream); // assert Assert.IsNotNull(deserializedPost); Assert.AreEqual("Post Title", deserializedPost.Title); Assert.AreEqual(ContentTypes.Base64, deserializedPost.Content.ContentType); Assert.AreEqual("Content of the post", deserializedPost.Content.UncodedText); Assert.AreEqual(1, deserializedPost.Authors.Count); }
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); }