Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void ImportBlogPost(BlogMLBlog blog, BlogMLPost bmlPost)
        {
            if (bmlPost.Attachments.Count > 0)
            {
                //Updates the post content with new attachment urls.
                bmlPost.Content = BlogMLContent.Create(CreateFilesFromAttachments(bmlPost), ContentTypes.Base64);
            }

            string newEntryId = Repository.CreateBlogPost(blog, bmlPost);

            foreach (BlogMLComment bmlComment in bmlPost.Comments)
            {
                try
                {
                    Repository.CreateComment(bmlComment, newEntryId);
                }
                catch (Exception e)
                {
                    LogError(Resources.Import_ErrorWhileImportingComment, e);
                }
            }

            foreach (BlogMLTrackback bmlPingTrack in bmlPost.Trackbacks)
            {
                try
                {
                    Repository.CreateTrackback(bmlPingTrack, newEntryId);
                }
                catch (Exception e)
                {
                    LogError(Resources.Import_ErrorWhileImportingComment, e);
                }
            }
        }
Exemplo n.º 3
0
        public void Process(BlogMLBlog blogml)
        {
            Log.Info("Fetching Tags.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Tag"))
            {
                var tags = query.Execute();

                foreach (var tag in tags)
                {
                    var category = new BlogMLCategory
                    {
                        Approved     = true,
                        DateCreated  = tag.CreatedDate,
                        DateModified = tag.CreatedDate,
                        Description  = tag.TagName,
                        ID           = tag.TagID.ToString(),
                        ParentRef    = tag.TagID.ToString() == tag.ParentTagID.ToString() ? "0" : tag.ParentTagID.ToString(),
                        Title        = tag.TagName
                    };

                    blogml.Categories.Add(category);
                }
            }

            Log.InfoFormat("Finished adding {0} tags.", blogml.Categories.Count);
        }
Exemplo n.º 4
0
        public void Write_WithBlogContainingEmbeddedAttachmentsWithComments_WritesPostAttachmentsToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime };
            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost { Title = "This is a blog post" };
            var attachment = new BlogMLAttachment
            {
                Data = new byte[] {1, 2, 3, 4, 5},
                Path = @"c:\\path-to-attachment.jpg",
                Url = "/foo/path-to-attachment.jpg",
                Embedded = true,
                MimeType = "img/jpeg"
            };
            post.Attachments.Add(attachment);
            var posts = new List<BlogMLPost> { post };

            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Assert.Contains(output, @"external-uri=""c:\\path-to-attachment.jpg""");
            Assert.Contains(output, @"url=""/foo/path-to-attachment.jpg""");
            Assert.Contains(output, @"mime-type=""img/jpeg""");
            Assert.Contains(output, @"embedded=""true""");
            Assert.Contains(output, @"AQIDBAU=</attachment>");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load blog categories
        /// </summary>
        /// <param name="blog">BlogML blog</param>
        private void LoadBlogCategories(BlogMLBlog blog)
        {
            foreach (var cat in blog.Categories)
            {
                var c = new Category
                {
                    Id           = new Guid(cat.ID),
                    Title        = cat.Title,
                    Description  = string.IsNullOrEmpty(cat.Description) ? "" : cat.Description,
                    DateCreated  = cat.DateCreated,
                    DateModified = cat.DateModified
                };

                if (!string.IsNullOrEmpty(cat.ParentRef) && cat.ParentRef != "0")
                {
                    c.Parent = new Guid(cat.ParentRef);
                }

                categoryLookup.Add(c);

                if (Category.GetCategory(c.Id) == null)
                {
                    c.Save();
                }
            }
        }
Exemplo n.º 6
0
        public void ConvertBlogPost_WithPostHavingTwoCategories_AddsBothCategoriesToEntry()
        {
            // arrange
            var blog = new BlogMLBlog();

            blog.Categories.Add(new BlogMLCategory {
                ID = "abc", Title = "Category A"
            });
            blog.Categories.Add(new BlogMLCategory {
                ID = "def", Title = "Category B"
            });
            blog.Categories.Add(new BlogMLCategory {
                ID = "#@!", Title = "Category C"
            });
            var post = new BlogMLPost();

            post.Categories.Add("abc");
            post.Categories.Add("#@!");
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual(2, entry.Categories.Count);
            Assert.AreEqual("Category A", entry.Categories.First());
            Assert.AreEqual("Category C", entry.Categories.Last());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void Process(BlogMLBlog blogml)
        {
            Log.Info("Fetching Tags.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Tag"))
            {
                var tags = query.Execute();

                foreach (var tag in tags)
                {
                    var category = new BlogMLCategory
                    {
                        Approved = true,
                        DateCreated = tag.CreatedDate,
                        DateModified = tag.CreatedDate,
                        Description = tag.TagName,
                        ID = tag.TagID.ToString(),
                        ParentRef = tag.TagID.ToString() == tag.ParentTagID.ToString() ? "0" : tag.ParentTagID.ToString(),
                        Title = tag.TagName
                    };

                    blogml.Categories.Add(category);
                }
            }

            Log.InfoFormat("Finished adding {0} tags.", blogml.Categories.Count);
        }
        public async Task <BlogResponse <BlogMLBlog> > GetAllBlogPostsAsync(ProgressDialogController progressController)
        {
            var response = new BlogResponse <BlogMLBlog>();

            try
            {
                _password = Settings.Instance.GWBPassword.DecryptString().ToInsecureString();
                var blogs = _proxy.getUsersBlogs(_blogId, _userName, _password);

                await Task.Run(() =>
                {
                    foreach (BlogInfo blog in blogs)
                    {
                        BlogMLBlog xblog = new BlogMLBlog
                        {
                            Title   = blog.blogName,
                            RootUrl = blog.url
                        };
                        progressController.SetMessage("Getting categories");
                        var categories       = GetCategories(blog);
                        var blogMlCategories = categories as IList <BlogMLCategory> ?? categories.ToList();
                        xblog.Categories.AddRange(blogMlCategories);
                        progressController.SetMessage("Getting posts");
                        var posts = GetPosts(blog, blogMlCategories);
                        xblog.Posts.AddRange(posts);
                        response.Data = xblog;
                    }
                });
            }
            catch (Exception exception)
            {
                response.Exception = exception;
            }
            return(response);
        }
        public Entry ConvertBlogPost(BlogMLPost post, BlogMLBlog blogMLBlog, Blog blog)
        {
            DateTime dateModified = blog != null?blog.TimeZone.FromUtc(post.DateModified) : post.DateModified;

            DateTime dateCreated = blog != null?blog.TimeZone.FromUtc(post.DateCreated) : post.DateCreated;

            var newEntry = new Entry((post.PostType == BlogPostTypes.Article) ? PostType.Story : PostType.BlogPost)
            {
                Title                    = GetTitleFromPost(post).Left(BlogPostTitleMaxLength),
                DateCreated              = dateCreated,
                DateModified             = dateModified,
                DateSyndicated           = post.Approved ? dateModified : DateTime.MaxValue,
                Body                     = post.Content.UncodedText,
                IsActive                 = post.Approved,
                DisplayOnHomePage        = post.Approved,
                IncludeInMainSyndication = post.Approved,
                IsAggregated             = post.Approved,
                AllowComments            = true,
                Description              = post.HasExcerpt ? post.Excerpt.UncodedText: null
            };

            if (!string.IsNullOrEmpty(post.PostName))
            {
                newEntry.EntryName = post.PostName;
            }
            else
            {
                SetEntryNameForBlogspotImport(post, newEntry);
            }

            SetEntryAuthor(post, newEntry, blogMLBlog);

            SetEntryCategories(post, newEntry, blogMLBlog);
            return(newEntry);
        }
Exemplo n.º 11
0
        public void CreateBlogPost_WithEntryPublisher_RemovesKeywordExpander()
        {
            // arrange
            var context = new Mock <ISubtextContext>();

            context.Setup(c => c.Blog.TimeZone.FromUtc(It.IsAny <DateTime>())).Returns(DateTime.Now);
            context.Setup(c => c.Repository.Create(It.IsAny <Entry>(), It.IsAny <IEnumerable <int> >()));
            var transformation  = new CompositeTextTransformation();
            var searchengine    = new Mock <IIndexingService>();
            var entryPublisher  = new EntryPublisher(context.Object, transformation, null, searchengine.Object);
            var keywordExpander = new KeywordExpander((IEnumerable <KeyWord>)null);

            transformation.Add(keywordExpander);
            var blog = new BlogMLBlog()
            {
                Title = "MyBlog"
            };
            var post       = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher, new BlogMLImportMapper());

            // act
            repository.CreateBlogPost(blog, post);

            // assert
            Assert.IsFalse(transformation.Contains(keywordExpander));
        }
        private async Task LoadBlogCategories(BlogMLBlog blog)
        {
            foreach (var cat in blog.Categories)
            {
                var c = new Category
                {
                    Id           = GetGuid("category", cat.ID).ToString(),
                    Name         = cat.Title,
                    Description  = cat.Description,
                    DisplayOrder = 1,
                };

                c.Slug = c.GetSeName();

                //if (!string.IsNullOrEmpty(cat.ParentRef) && cat.ParentRef != "0")
                //    c.Parent = GetGuid("category", cat.ParentRef);

                if (!_categoryManager.GetQueryable().Any(t => t.Slug == c.Slug))
                {
                    await _categoryManager.CreateAsync(c);
                }
                else
                {
                    c = _categoryManager.GetQueryable().FirstOrDefault(t => t.Slug == c.Slug);
                }

                categoryLookup.Add(c);
            }
        }
Exemplo n.º 13
0
        public BlogMLBlog GetBlog()
        {
            BlogMLBlog blog = BlogMLConverter.ConvertBlog(SubtextContext.Blog);

            blog.Categories.AddRange(Categories);
            return(blog);
        }
Exemplo n.º 14
0
        public void Write_WithBlogContainingBase64EncodedPosts_WritesPostsToWriterAsBase64Encoded()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost {
                Content = BlogMLContent.Create("<p>This is a Test</p>", ContentTypes.Base64)
            };
            var posts = new List <BlogMLPost> {
                post
            };

            blog.Posts.Add(post);
            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes("<p>This is a Test</p>")));
            Assert.Contains(output, @"<content type=""base64""><![CDATA[PHA+VGhpcyBpcyBhIFRlc3Q8L3A+]]></content>");
        }
Exemplo n.º 15
0
        public void Write_WithSourceReturningAuthors_WritesAuthorsToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            blog.Authors.Add(new BlogMLAuthor {
                ID = "112", Title = "Phineas", Email = "*****@*****.**", Approved = true
            });
            source.Setup(s => s.GetBlog()).Returns(blog);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"<author id=""112""");
            Assert.Contains(output, @"email=""*****@*****.**""");
            Assert.Contains(output, @"approved=""true""");
            Assert.Contains(output, @"<title type=""text""><![CDATA[Phineas]]></title>");
        }
Exemplo n.º 16
0
        public void Write_WithBlogContainingExtendedProperties_WritesPropertiesToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            blog.ExtendedProperties.Add(new Pair <string, string>("Color", "Blue"));
            source.Setup(s => s.GetBlog()).Returns(blog);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"<property name=""Color"" value=""Blue"" />");
        }
Exemplo n.º 17
0
        public void Write_WithBlogContainingCategories_WritesCategoriesToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };
            var source   = new Mock <IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog     = new BlogMLBlog {
                Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime
            };

            blog.Categories.Add(new BlogMLCategory {
                ID = "221", Title = "Test Category"
            });
            source.Setup(s => s.GetBlog()).Returns(blog);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();

            Assert.Contains(output, @"<category id=""221""");
            Assert.Contains(output, @"<title type=""text""><![CDATA[Test Category]]></title>");
        }
Exemplo n.º 18
0
        public List <BlogPostImportResult> ValidateImport(BlogMLBlog blogPosts, bool useOriginalUrls = false)
        {
            List <BlogPostImportResult> result = new List <BlogPostImportResult>();
            var unsavedUrls = new List <string>();

            if (blogPosts != null && blogPosts.Posts != null)
            {
                foreach (var blogML in blogPosts.Posts)
                {
                    var blogPostModel = MapViewModel(blogML, useOriginalUrls, null, unsavedUrls);
                    unsavedUrls.Add(blogPostModel.BlogUrl);

                    BlogPostImportResult blogPost;
                    if (!ValidateModel(blogPostModel, blogML, out blogPost))
                    {
                        result.Add(blogPost);
                        continue;
                    }

                    blogPost = new BlogPostImportResult
                    {
                        Title   = blogPostModel.Title,
                        PageUrl = blogPostModel.BlogUrl,
                        Success = true,
                        Id      = blogML.ID
                    };
                    result.Add(blogPost);
                }
            }

            return(result);
        }
Exemplo n.º 19
0
        public Entry ConvertBlogPost(BlogMLPost post, BlogMLBlog blogMLBlog, Blog blog)
        {
            DateTime dateModified = blog != null ? blog.TimeZone.FromUtc(post.DateModified) : post.DateModified;
            DateTime dateCreated = blog != null ? blog.TimeZone.FromUtc(post.DateCreated) : post.DateCreated;

            var newEntry = new Entry((post.PostType == BlogPostTypes.Article) ? PostType.Story : PostType.BlogPost)
            {
                Title = GetTitleFromPost(post).Left(BlogPostTitleMaxLength),
                DateCreated = dateCreated,
                DateModified = dateModified,
                DateSyndicated = post.Approved ? dateModified : DateTime.MaxValue,
                Body = post.Content.UncodedText,
                IsActive = post.Approved,
                DisplayOnHomePage = post.Approved,
                IncludeInMainSyndication = post.Approved,
                IsAggregated = post.Approved,
                AllowComments = true,
                Description = post.HasExcerpt ? post.Excerpt.UncodedText: null
            };

            if(!string.IsNullOrEmpty(post.PostName))
            {
                newEntry.EntryName = post.PostName;
            }
            else
            {
                SetEntryNameForBlogspotImport(post, newEntry);
            }

            SetEntryAuthor(post, newEntry, blogMLBlog);

            SetEntryCategories(post, newEntry, blogMLBlog);
            return newEntry;
        }
Exemplo n.º 20
0
        private string GetCategoryById(BlogMLBlog BlogData, string CategoryId)
        {
            string results = "none";
            bool   found   = false;

            //try to find by ID
            for (int i = 0; i <= BlogData.categories.Count - 1; i++)
            {
                if (BlogData.categories[i].ID == CategoryId)
                {
                    results = String.Join(" ", BlogData.categories[i].Title);
                    found   = true;
                    break;
                }
            }
            if (!found)
            {
                //try to find by description
                for (int i = 0; i <= BlogData.categories.Count - 1; i++)
                {
                    if (BlogData.categories[i].Description == CategoryId)
                    {
                        results = String.Join(" ", BlogData.categories[i].Title);
                        found   = true;
                        break;
                    }
                }
            }
            Debug.Assert(found, CategoryId);
            return(results);
        }
Exemplo n.º 21
0
 public void ImportBlog(BlogMLBlog blog)
 {
     using (Repository.SetupBlogForImport())
     {
         Import(blog);
     }
 }
Exemplo n.º 22
0
        public List <BlogPostImportResult> ValidateImport(BlogMLBlog blogPosts)
        {
            List <BlogPostImportResult> result = new List <BlogPostImportResult>();
            var unsavedUrls = new List <string>();

            if (blogPosts != null && blogPosts.Posts != null)
            {
                foreach (var blogML in blogPosts.Posts)
                {
                    // Validate authors
                    if (blogML.Authors != null &&
                        blogML.Authors.Count > 0 &&
                        (blogPosts.Authors == null || blogPosts.Authors.All(a => a.ID != blogML.Authors[0].Ref)))
                    {
                        var failedResult = CreateFailedResult(blogML);
                        failedResult.ErrorMessage = string.Format(BlogGlobalization.ImportBlogPosts_AuthorByRefNotFound_Message, blogML.Authors[0].Ref);
                        result.Add(failedResult);

                        continue;
                    }

                    var blogPostModel = MapViewModel(blogML, null, unsavedUrls);
                    unsavedUrls.Add(blogPostModel.BlogUrl);

                    BlogPostImportResult blogPost;
                    if (!ValidateModel(blogPostModel, blogML, out blogPost))
                    {
                        result.Add(blogPost);
                        continue;
                    }

                    blogPost = new BlogPostImportResult
                    {
                        Title   = blogML.PostName ?? blogML.Title,
                        PageUrl = blogPostModel.BlogUrl,
                        Success = true,
                        Id      = blogML.ID
                    };
                    result.Add(blogPost);
                }

                // Validate for duplicate IDS
                result
                .Where(bp => bp.Success)
                .GroupBy(bp => bp.Id)
                .Where(group => group.Count() > 1)
                .ToList()
                .ForEach(group => group
                         .ToList()
                         .ForEach(
                             bp =>
                {
                    bp.Success      = false;
                    bp.ErrorMessage = string.Format(BlogGlobalization.ImportBlogPosts_DuplicateId_Message, group.Key);
                }));
            }

            return(result);
        }
 public void CreateCategories(BlogMLBlog blog)
 {
     foreach (BlogMLCategory bmlCategory in blog.Categories)
     {
         LinkCategory category = Mapper.ConvertCategory(bmlCategory);
         Repository.CreateLinkCategory(category);
     }
 }
Exemplo n.º 24
0
 void ImportPostsFromBlog(BlogMLBlog blog)
 {
     foreach (BlogMLPost post in blog.Posts) {
         Post importPost = _tasks.ImportPost(_postMapper.MapFrom(post, blog.Categories));
         importPost.Author = _authors.FirstOrDefault();
         importPost.AllowComments = true;
         foreach (BlogMLComment comment in post.Comments) importPost.AddComment(_commentMapper.MapFrom(comment));
     }
 }
Exemplo n.º 25
0
        void ImportBlogPosts(IDocumentStore store, BlogMLBlog blog)
        {
            Stopwatch sp = Stopwatch.StartNew();

            var usersList = ImportUserList(store, blog);

            importBlogPosts(store, blog, usersList);

            Console.WriteLine(sp.Elapsed);
        }
Exemplo n.º 26
0
        void ImportBlogPosts(IDocumentStore store, BlogMLBlog blog)
        {
            Stopwatch sp = Stopwatch.StartNew();

            var usersList = ImportUserList(store, blog);

            importBlogPosts(store, blog, usersList);

            Console.WriteLine(sp.Elapsed);
        }
Exemplo n.º 27
0
 void ImportAuthorsFromBlog(BlogMLBlog blog)
 {
     foreach (BlogMLAuthor author in blog.Authors) {
         User user = _users.GetUserByEmail(author.Email) ?? _users.AddUser(new CreateUserDetails {
                                                                                                 Email = author.Email,
                                                                                                 RealName = author.Title,
                                                                                                 Username = author.Email.Split('@')[0]
                                                                                                 });
         _authors.Add(user);
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// extended post has all BlogML plus fields not supported
 /// by BlogML like tags. here we assign BlogML post
 /// to extended matching on post URL
 /// </summary>
 /// <param name="blog">BlogML blog</param>
 private void LoadBlogExtendedPosts(BlogMLBlog blog)
 {
     foreach (var post in blog.Posts)
     {
         if (post.PostType == BlogPostTypes.Normal)
         {
             BlogMLPost p = post;
             blogsExtended.Where(b => b.PostUrl == p.PostUrl).FirstOrDefault().BlogPost = post;
         }
     }
 }
Exemplo n.º 29
0
        public void Import(BlogMLBlog blog)
        {
            Repository.SetExtendedProperties(blog.ExtendedProperties);

            Repository.CreateCategories(blog);

            foreach (BlogMLPost bmlPost in blog.Posts)
            {
                ImportBlogPost(blog, bmlPost);
            }
        }
Exemplo n.º 30
0
        public BlogMLBlog SerializeBlogML(string fileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(BlogMLBlog));

            TextReader reader   = new StreamReader(fileName);
            BlogMLBlog blogData = (BlogMLBlog)serializer.Deserialize(reader);

            reader.Close();

            return(blogData);
        }
Exemplo n.º 31
0
        public Importer(string filepath, string connectionString)
        {
            using (var stream = File.Open(filepath, FileMode.Open))
            {
                _blog = BlogMLSerializer.Deserialize(stream);
            }

            _store = new DocumentStore
            {
                ConnectionStringName = connectionString
            }.Initialize();
        }
Exemplo n.º 32
0
        public void Process(BlogMLBlog blogml)
        {
            ProcessPosts(blogml);

            foreach (var post in blogml.Posts)
            {
                foreach (var worker in Workers)
                {
                    worker.Process(post);
                }
            }
        }
Exemplo n.º 33
0
        public void Process(BlogMLBlog blogml)
        {
            ProcessPosts(blogml);

            foreach(var post in blogml.Posts)
            {
                foreach (var worker in Workers)
                {
                    worker.Process(post);
                }
            }
        }
Exemplo n.º 34
0
        public void Migrate()
        {
            Log.Info("Starting the export process.");

            var blog = new BlogMLBlog();

            foreach (var worker in Workers)
            {
                worker.Process(blog);
            }

            Log.Info("Finished exporting. All done.");
        }
Exemplo n.º 35
0
        public void Process(BlogMLBlog blogml)
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ExportFileName);
            Log.InfoFormat("Creating BlogML export file in {0}", path);

            using (var output = new FileStream(path, FileMode.Create))
            {
                Log.Info("Serializing Blog data into file.");
                BlogMLSerializer.Serialize(output, blogml);
            }

            Log.Info("Finished writing the export file.");
        }
Exemplo n.º 36
0
        public void Migrate()
        {
            Log.Info("Starting the export process.");

            var blog = new BlogMLBlog();

            foreach (var worker in Workers)
            {
                worker.Process(blog);
            }

            Log.Info("Finished exporting. All done.");
        }
Exemplo n.º 37
0
 private ICollection<Category> GetPostCategoryies(BlogMLBlog.CategoryCollection categories, BlogMLPost blogMLPost)
 {
     var list = new List<Category>();
     if (blogMLPost == null || blogMLPost.Categories == null) return new Collection<Category>();
     for (int i = 0; i < blogMLPost.Categories.Count; i++)
     {
         string postCategoryId = blogMLPost.Categories[i].Ref;
         list.AddRange(from category in categories
                       where category.ID == postCategoryId
                       select new Category {CategoryName = category.Title});
     }
     return list;
 }
Exemplo n.º 38
0
 public static BlogMLBlog CreateBlogInstance(string title, string subtitle, string rootUrl, string author, string email, DateTime dateCreated)
 {
     BlogMLBlog blog = new BlogMLBlog();
     BlogMLAuthor blogAuthor = new BlogMLAuthor();
     blogAuthor.Title = author;
     blogAuthor.Email = email;
     blog.Authors.Add(blogAuthor);
     blog.Title = title;
     blog.SubTitle = subtitle;
     blog.RootUrl = rootUrl;
     blog.DateCreated = dateCreated;
     return blog;
 }
Exemplo n.º 39
0
        /// <summary>
        ///  setps:
        ///  1, import category,tags, authors ...
        ///  2, import post, page, command
        /// </summary>
        public async Task <BlogMLImporterResult> ImportAsync(User user, string xml)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            _xml  = xml;
            _user = user;

            var blog = new BlogMLBlog();

            try
            {
                blog = BlogMLSerializer.Deserialize(XmlReader);
            }
            catch (Exception ex)
            {
                string message = string.Format("BlogML could not load with 2.0 specs. {0}", ex.Message);

                _logger.LogError(message);
            }

            try
            {
                await ImportCategoryAsync(blog);

                LoadFromXmlDocument();

                await ImportPostsAsync(blog);

                _logger.LogInformation($"Import completed. \n Category count: {CategoryCount}, Post count: {PostCount}, Page count: {PageCount} . ");

                return(new BlogMLImporterResult()
                {
                    CategoryCount = CategoryCount,
                    PageCount = PageCount,
                    PostCount = PostCount,
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "BlogML import failed.");
                throw;
            }
        }
Exemplo n.º 40
0
 private void GetAuthors(Blog blog, BlogMLBlog blogMLBlog)
 {
     foreach (var blogMLAuthor in blogMLBlog.Authors)
     {
         Author author = new Author();
         author.ID           = blogMLAuthor.ID;
         author.Approved     = blogMLAuthor.Approved;
         author.DateCreated  = blogMLAuthor.DateCreated;
         author.DateModified = blogMLAuthor.DateModified;
         author.Email        = blogMLAuthor.Email;
         author.Title        = blogMLAuthor.Title;
         blog.Authors.AuthorList.Add(author);
     }
 }
Exemplo n.º 41
0
        private void PopulateAuthors(Blog blog, BlogMLBlog bmlBlog)
        {
            var bmlAuthor = new BlogMLAuthor
            {
                ID           = blog.Id.ToString(CultureInfo.InvariantCulture),
                Title        = blog.Author,
                Approved     = true,
                Email        = blog.Email,
                DateCreated  = Blog.TimeZone.ToUtc(blog.LastUpdated),
                DateModified = Blog.TimeZone.ToUtc(blog.LastUpdated)
            };

            bmlBlog.Authors.Add(bmlAuthor);
        }
 private void SetEntryCategories(BlogMLPost post, Entry newEntry, BlogMLBlog blog)
 {
     if (post.Categories.Count > 0)
     {
         foreach (BlogMLCategoryReference categoryRef in post.Categories)
         {
             string categoryTitle = GetCategoryTitleById(categoryRef.Ref, blog.Categories);
             if (categoryTitle != null)
             {
                 newEntry.Categories.Add(categoryTitle);
             }
         }
     }
 }
    public BlogMLBlog Export(Id entryCollectionId, Id pagesCollectionId, Id mediaCollectionId)
    {
      LogService.Info("Beginning export of collection with Id='{0}'", entryCollectionId);
      BlogMLBlog blog = new BlogMLBlog();
      AppService appSvc = AtomPubService.GetService();

      AppCollection coll = appSvc.GetCollection(entryCollectionId);

      blog.Title = coll.Title.Text;
      if (coll.Subtitle != null) blog.SubTitle = coll.Subtitle.Text;
      blog.RootUrl = coll.Href.ToString();

      //extended properties
      blog.ExtendedProperties.Add(new BlogML.Pair<string, string>("CommentModeration", AuthorizeService.IsAuthorized(AuthRoles.Anonymous, coll.Id.ToScope(),
        AuthAction.ApproveAnnotation) ? "Anonymous" : "Authenticated"));
      blog.ExtendedProperties.Add(new BlogML.Pair<string, string>("SendTrackback", new BlogAppCollection(coll).TrackbacksOn ? "Yes" : "No"));

      foreach (BlogMLCategory cat in coll.AllCategories.Select(c => new BlogMLCategory()
      {
        ID = c.Term,
        Approved = true,
        DateCreated = DateTime.UtcNow,
        DateModified = DateTime.UtcNow,
        Title = c.ToString()
      })) { blog.Categories.Add(cat); }

      IPagedList<AtomEntry> entries = null;
      int page = 0;
      do
      {
        entries = AtomPubService.GetEntries(new EntryCriteria() { WorkspaceName = entryCollectionId.Workspace, CollectionName = entryCollectionId.Collection, Authorized = true },
        page, 100); page++;
        foreach (AtomEntry entry in entries)
        {
          try
          {
            LogService.Info("Processing entry with ID='{0}'", entry.Id);
            AddEntry(entry, blog);
          }
          catch (Exception ex)
          {
            LogService.Error(ex);
          }
        }
      } while (entries.PageIndex < entries.PageCount);

      LogService.Info("Finished export!");
      return blog;
    }
        public void ConvertBlogPost_WithAuthorTitleTooLong_TruncatesTitleToMaxLength()
        {
            // arrange
            var title = new string('a', 51);
            var blog = new BlogMLBlog();
            blog.Authors.Add(new BlogMLAuthor{ID = "123", Title = title});
            var post = new BlogMLPost();
            post.Authors.Add("123");
            var mapper = new BlogMLImportMapper();

            // act
            Entry entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual(50, entry.Author.Length);
        }
        public void ConvertBlogPost_WithAuthorMatchingBlogAuthor_SetsAuthorNameAndEmail()
        {
            // arrange
            var blog = new BlogMLBlog();
            blog.Authors.Add(new BlogMLAuthor { ID = "111", Title = "Not-Haacked", Email = "*****@*****.**"});
            blog.Authors.Add(new BlogMLAuthor { ID = "222", Title = "Haacked", Email = "*****@*****.**"});
            var post = new BlogMLPost();
            post.Authors.Add("222");
            var mapper = new BlogMLImportMapper();

            // act
            var entry = mapper.ConvertBlogPost(post, blog, null);

            // assert
            Assert.AreEqual("Haacked", entry.Author);
            Assert.AreEqual("*****@*****.**", entry.Email);
        }
        public void CreateCategories_WithBlogHavingCategories_CreatesCategories()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog { Id = 123 });
            bool categoryCreated = false;
            context.Setup(c => c.Repository.CreateLinkCategory(It.IsAny<LinkCategory>())).Callback(() => categoryCreated = true);
            var blog = new BlogMLBlog();
            blog.Categories.Add(new BlogMLCategory { Title = "Category Title", ID = "123" });
            var repository = new BlogImportRepository(context.Object, null, null, new BlogMLImportMapper());

            // act
            repository.CreateCategories(blog);

            // assert
            Assert.IsTrue(categoryCreated);
        }
        public void CreateBlogPost_WithEntryPublisher_PublishesBlogPostAndReturnsId()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            var entryPublisher = new Mock<IEntryPublisher>();
            entryPublisher.Setup(p => p.Publish(It.IsAny<Entry>())).Returns(310);
            var blog = new BlogMLBlog();
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher.Object, new BlogMLImportMapper());

            // act
            var id = repository.CreateBlogPost(blog, post);

            // assert
            Assert.AreEqual("310", id);
        }
Exemplo n.º 48
0
        public void Process(BlogMLBlog blogml)
        {
            Log.Info("Fetching Blog information");

            using (var siteQuery = new OxiteReader("SELECT * FROM oxite_Site"))
            using (var areaQuery = new OxiteReader("SELECT * FROM oxite_Area"))
            {
                var blog = siteQuery.Execute().First();
                var area = areaQuery.Execute().First();

                Log.WarnFormat("This version only supports migration from one Blog and one Area.");
                Log.InfoFormat("Migrating '{0}' blog...", blog.SiteDisplayName);

                blogml.RootUrl = string.Format("{0}/{1}", blog.SiteHost, blog.SiteDisplayName);
                blogml.DateCreated = area.CreatedDate;
                blogml.Title = blog.SiteDescription;
                blogml.SubTitle = area.Description;
            }
        }
Exemplo n.º 49
0
        public void Write_WithBlogContainingCategories_WritesCategoriesToWriter()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime };
            blog.Categories.Add(new BlogMLCategory { ID = "221", Title = "Test Category"});
            source.Setup(s => s.GetBlog()).Returns(blog);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Assert.Contains(output, @"<category id=""221""");
            Assert.Contains(output, @"<title type=""text""><![CDATA[Test Category]]></title>");
        }
        public void CreateBlogPost_WithEntryPublisher_RemovesKeywordExpander()
        {
            // arrange
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog());
            context.Setup(c => c.Repository.Create(It.IsAny<Entry>(), It.IsAny<IEnumerable<int>>()));
            var transformation = new CompositeTextTransformation();
            var searchengine = new Mock<IIndexingService>();
            var entryPublisher = new EntryPublisher(context.Object, transformation, null, searchengine.Object);
            var keywordExpander = new KeywordExpander((IEnumerable<KeyWord>)null);
            transformation.Add(keywordExpander);
            var blog = new BlogMLBlog() { Title = "MyBlog" };
            var post = new BlogMLPost();
            var repository = new BlogImportRepository(context.Object, null, entryPublisher, new BlogMLImportMapper());

            // act
            repository.CreateBlogPost(blog, post);

            // assert
            Assert.IsFalse(transformation.Contains(keywordExpander));
        }
Exemplo n.º 51
0
        private void ProcessPosts(BlogMLBlog blogml)
        {
            Log.Info("Fetching blog posts.");

            using (var query = new OxiteReader("SELECT * FROM oxite_Post"))
            {
                var posts = query.Execute();

                foreach (var post in posts)
                {
                    var postml = new BlogMLPost
                    {
                        Content = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text = post.Body
                        },
                        Excerpt = new BlogMLContent
                        {
                            ContentType = ContentTypes.Html,
                            Text = post.BodyShort
                        },
                        Approved = post.State == (int)RecordStates.Normal,
                        DateCreated = post.CreatedDate,
                        DateModified = post.ModifiedDate,
                        HasExcerpt = !string.IsNullOrWhiteSpace(post.BodyShort),
                        ID = post.PostID.ToString(),
                        PostName = post.Title,
                        PostType = BlogPostTypes.Normal,
                        PostUrl = post.Slug,
                        Title = post.Title,
                    };

                    blogml.Posts.Add(postml);
                }

                Log.InfoFormat("Finished adding {0} posts.", blogml.Posts.Count);
            }
        }
Exemplo n.º 52
0
        public void Write_WithBlogContainingBase64EncodedPosts_WritesPostsToWriterAsBase64Encoded()
        {
            // arrange
            var stringWriter = new StringWriter();
            var xmlWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented };
            var source = new Mock<IBlogMLSource>();
            var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture);
            var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime };
            source.Setup(s => s.GetBlog()).Returns(blog);
            var post = new BlogMLPost { Content = BlogMLContent.Create("<p>This is a Test</p>", ContentTypes.Base64) };
            var posts = new List<BlogMLPost> { post };
            blog.Posts.Add(post);
            source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts);
            var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/);

            // act
            ((IBlogMLWriter)writer).Write(xmlWriter);

            // assert
            string output = stringWriter.ToString();
            Console.WriteLine(Convert.ToBase64String(Encoding.UTF8.GetBytes("<p>This is a Test</p>")));
            Assert.Contains(output, @"<content type=""base64""><![CDATA[PHA+VGhpcyBpcyBhIFRlc3Q8L3A+]]></content>");
        }
Exemplo n.º 53
0
 public IList<Post> MapToEntity(BlogMLBlog blogML)
 {
     var list = new List<Post>();
     foreach (BlogMLPost blogMLPost in blogML.Posts)
     {
         var post = new Post();
         post.Categories = GetPostCategoryies(blogML.Categories, blogMLPost);
         post.DateCreated = blogMLPost.DateCreated;
         post.DateModified = blogMLPost.DateModified;
         post.IsPublished = true;
         post.DatePublished = blogMLPost.DateModified;
         if (blogMLPost.Excerpt != null) post.Description = blogMLPost.Excerpt.Text;
         post.IsDeleted = false;
         if (blogMLPost.Content != null) post.PostContent = blogMLPost.Content.Text;
         post.Slug = blogMLPost.Title.ToSlug();
         post.Title = blogMLPost.Title;
         Guid guid;
         if (!Guid.TryParse(blogMLPost.ID, out guid))
             guid = Guid.NewGuid();
         post.UniqueId = guid;
         list.Add(post);
     }
     return list;
 }
Exemplo n.º 54
0
        /// <summary>
        /// Imports BlogML file into blog
        /// </summary>
        /// <returns>
        /// True if successful
        /// </returns>
        public override bool Import()
        {
            Message = string.Empty;
            var blog = new BlogMLBlog();
            try
            {
                blog = BlogMLSerializer.Deserialize(XmlReader);
            }
            catch (Exception ex)
            {
                Message = string.Format("BlogReader.Import: BlogML could not load with 2.0 specs. {0}", ex.Message);
                Utils.Log(Message);
                return false;
            }

            try
            {
                LoadFromXmlDocument();

                LoadBlogCategories(blog);

                LoadBlogExtendedPosts(blog);

                LoadBlogPosts();

                Message = string.Format("Imported {0} new posts", PostCount);
            }
            catch (Exception ex)
            {
                Message = string.Format("BlogReader.Import: {0}", ex.Message);
                Utils.Log(Message);
                return false;
            }

            return true;
        }
Exemplo n.º 55
0
        private List<BlogPostImportResult> GetImportingBogPosts(BlogMLBlog.PostCollection posts)
        {
            var list = new List<BlogPostImportResult>();

            var i = 0;
            foreach (var post in posts)
            {
                list.Add(new BlogPostImportResult
                         {
                             Id = post.ID,
                             Title = post.Title,
                             PageUrl = post.PostUrl + "-test"
                         });

                i++;
                if (i >= 3)
                {
                    break;
                }
            }

            return list;
        }
Exemplo n.º 56
0
        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);
        }
Exemplo n.º 57
0
        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);
        }
Exemplo n.º 58
0
        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);
        }
Exemplo n.º 59
0
        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);
        }
Exemplo n.º 60
0
        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);
        }