public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Entry entry = null; Database.WithRepository( repo => { entry = new Entry {Name = name, Author = "A1", Status = EntryStatus.PublicBlog}; var revision = entry.Revise(); revision.Body = "Hello"; repo.Add(entry); var comment = entry.Comment(); comment.AuthorName = "Test"; comment.AuthorEmail = "*****@*****.**"; comment.AuthorUrl = ""; comment.Body = "Comment"; comment.Posted = DateTime.Now; comment.Entry = entry; comment.IsSpam = false; repo.Add(comment); var comment2 = entry.Comment(); comment2.AuthorName = "Test"; comment2.AuthorEmail = "*****@*****.**"; comment2.AuthorUrl = ""; comment2.Body = "Comment"; comment2.Posted = DateTime.Now; comment2.Entry = entry; comment2.IsSpam = false; repo.Add(comment2); var comment3 = entry.Comment(); comment3.AuthorName = "Test"; comment3.AuthorEmail = "*****@*****.**"; comment3.AuthorUrl = ""; comment3.Body = "Comment"; comment3.Posted = DateTime.Now; comment3.Entry = entry; comment3.IsSpam = true; repo.Add(comment3); }); Database.WithSession( s => { var repo = new AdminRepository(s); repo.UpdateCommentCountFor(entry.Id); }); Database.WithRepository( repo => Assert.AreEqual(2, repo.Get<Entry>(entry.Id).CommentCount)); }
public override void TestQuery() { var name = "test-" + Guid.NewGuid(); Database.WithRepository( repo => { var entry1 = new Entry { Name = name, Author = "A1" }; var revision1 = entry1.Revise(); revision1.Body = "Hello"; repo.Add(entry1); var comment1 = entry1.Comment(); comment1.AuthorName = "A2"; comment1.AuthorEmail = "*****@*****.**"; comment1.AuthorUrl = "somesite.com"; comment1.Body = "some comment"; repo.Add(comment1); }); Database.WithRepository( repo => { var result = repo.Find(new GetFullEntriesQuery(true), 0, 1); Assert.AreEqual(1, result.Count); Assert.AreEqual(1, result.Single().Comments.Count); }); }
public IEnumerable<TaskStep> Execute(Dictionary<string, object> properties) { var inputFile = (string)properties["inputFile"]; if (!File.Exists(inputFile)) { throw new ArgumentException("The file: '{0}' does not exist."); } var progress = 0; yield return new TaskStep(progress++, "Input file '{0}' found", inputFile); using (var reader = new StreamReader(inputFile)) { yield return new TaskStep(progress++, "Deserializing input file into BlogML object model"); var blog = BlogMLSerializer.Deserialize(reader); yield return new TaskStep(progress++, "Successfully deserialized BlogML object model from input file"); yield return new TaskStep(progress++, "Blog posts found: {0}", blog.Posts.Count); var remainingProgress = 100 - progress; var postCount = blog.Posts.Count; var postIndex = 0; foreach (var post in blog.Posts) { postIndex++; progress = (int)(((double)postIndex / postCount) * (double)remainingProgress); var entry = new Entry(); entry.Author = authenticator.GetName(); entry.HideChrome = false; entry.IsDiscussionEnabled = true; entry.Status = post.PostType == BlogPostTypes.Article ? EntryStatus.PublicPage : EntryStatus.PublicBlog; entry.Title = entry.MetaTitle = NoLongerThan(200, post.Title); entry.Published = post.DateCreated < DateTime.Today.AddYears(-100) ? DateTime.UtcNow : post.DateCreated; entry.Summary = post.HasExcerpt ? NoLongerThan(500, StripHtml(post.Excerpt.UncodedText)) : ""; entry.MetaDescription = post.HasExcerpt ? NoLongerThan(200, StripHtml(post.Excerpt.UncodedText)) : NoLongerThan(200, StripHtml(post.Content.UncodedText)); entry.Name = NoLongerThan(100, (post.PostUrl ?? post.PostName ?? post.ID).Trim('/')); // Ensure this post wasn't already imported var existing = repository.FindFirstOrDefault(new EntryByNameQuery(entry.Name)); if (existing != null) { yield return new TaskStep(progress, "Did NOT import post '{0}', because a post by this name already exists", entry.Name); continue; } var revision = entry.Revise(); revision.Author = authenticator.GetName(); revision.Body = post.Content.UncodedText; revision.Format = Formats.Html; revision.Reason = "Imported from BlogML"; foreach (BlogMLComment comment in post.Comments) { var newComment = entry.Comment(); newComment.AuthorEmail = NoLongerThan(100, comment.UserEMail); newComment.AuthorName = NoLongerThan(100, comment.UserName); newComment.AuthorUrl = NoLongerThan(100, comment.UserUrl); newComment.IsSpam = !comment.Approved; newComment.Posted = comment.DateCreated < DateTime.Today.AddYears(-100) ? DateTime.UtcNow : comment.DateCreated; newComment.Body = comment.Content.UncodedText; } foreach (BlogMLCategoryReference categoryRef in post.Categories) { var category = blog.Categories.FirstOrDefault(x => x.ID == categoryRef.Ref); if (category == null) continue; var tagName = new string( (category.Title?? string.Empty) .ToLowerInvariant() .Select(x => char.IsLetterOrDigit(x) ? x : '-') .ToArray()); if (string.IsNullOrEmpty(tagName)) continue; var existingTag = repository.FindFirstOrDefault(new SearchTagsByNameQuery(tagName)); if (existingTag == null) { existingTag = new Tag {Name = tagName}; repository.Add(existingTag); } existingTag.Add(entry); } repository.Add(entry); yield return new TaskStep(progress, "Imported post '{0}'", entry.Name); } } yield break; }