public void SavePost_SetIdTwoPosts_UniqueIds()
        {
            IFileSystem testFileSystem = new FakeFileSystem();
            var         testDataStore  = new BlogDataStore(testFileSystem);
            var         testPost1      = new Post
            {
                Slug     = "Test-Post-Slug",
                Title    = "Test Title",
                Body     = "Test contents",
                IsPublic = true,
                PubDate  = DateTime.UtcNow
            };
            var testPost2 = new Post
            {
                Slug     = "Test-Post-Slug",
                Title    = "Test Title",
                Body     = "Test contents",
                IsPublic = true,
                PubDate  = DateTime.UtcNow
            };

            testDataStore.SavePost(testPost1);
            testDataStore.SavePost(testPost2);

            Assert.NotNull(testPost1.Id);
            Assert.NotNull(testPost2.Id);
            Assert.NotEqual(testPost1.Id, testPost2.Id);
        }
        public void SavePost_SetIdTwoPosts_IncrementsId()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost1      = new Post
            {
                Slug     = "Test-Post-Slug",
                Title    = "Test Title",
                Body     = "Test contents",
                IsPublic = true,
                PubDate  = DateTime.UtcNow
            };
            Post testPost2 = new Post
            {
                Slug     = "Test-Post-Slug",
                Title    = "Test Title",
                Body     = "Test contents",
                IsPublic = true,
                PubDate  = DateTime.UtcNow
            };

            testDataStore.SavePost(testPost1);
            testDataStore.SavePost(testPost2);

            Assert.Equal(testPost2.Id, testPost1.Id + 1);
        }
        public void GetAllPosts_ReturnsList()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());
            Post          post1         = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTimeOffset.Now,
                LastModified = DateTimeOffset.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };
            Post post2 = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTimeOffset.Now,
                LastModified = DateTimeOffset.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };

            testDataStore.SavePost(post1);
            testDataStore.SavePost(post2);

            List <Post> posts = testDataStore.GetAllPosts();

            Assert.NotEmpty(posts);
        }
        public void GetDrafts_ShowDraftSummaries()
        {
            IFileSystem   fakeFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(fakeFileSystem);

            Post draftPost = new Post
            {
                Title    = "Draft Post",
                IsPublic = false,
                PubDate  = DateTime.UtcNow,
            };
            Post publishedPost = new Post
            {
                Title    = "Published Post",
                IsPublic = true,
                PubDate  = DateTime.UtcNow,
            };

            testDataStore.SavePost(draftPost);
            testDataStore.SavePost(publishedPost);

            DraftsModel testDraftsModel = new DraftsModel(testDataStore);

            testDraftsModel.OnGet();
            DraftSummaryModel testDraftSummaryModel = testDraftsModel.DraftSummaries.First();

            Assert.Equal(1, testDraftsModel.DraftSummaries.Count());
            Assert.Equal(draftPost.Id, testDraftSummaryModel.Id);
            Assert.Equal("Draft Post", testDraftSummaryModel.Title);
            Assert.Equal(draftPost.PubDate, testDraftSummaryModel.PublishTime);
            Assert.Equal(0, testDraftSummaryModel.CommentCount);
        }
        public IActionResult OnPostDeleteComment(Guid commentId, string id)
        {
            Post post = _dataStore.GetPost(id);

            Comment foundComment = _dataStore.FindComment(commentId, post);

            foundComment.IsPublic = false;

            _dataStore.SavePost(post);
            return(Redirect($"/Post/{id}/{post.Slug}"));
        }
        public void UpdatePost_PreviouslyPublishedDraftToPublished_TitleIsUpdated_UpdateSlug()
        {
            var testDataStore    = new BlogDataStore(new FakeFileSystem());
            var slugGenerator    = new SlugGenerator(testDataStore);
            var excerptGenerator = new ExcerptGenerator(140);

            var post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = false,
            };

            testDataStore.SavePost(post);

            var testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id.ToString("N"), true);

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal("Edited-Title", post.Slug);
        }
        public void UpdatePost_PreviouslyPublishedDraftToPublished_DoNotUpdatePubDate()
        {
            var testDataStore    = new BlogDataStore(new FakeFileSystem());
            var slugGenerator    = new SlugGenerator(testDataStore);
            var excerptGenerator = new ExcerptGenerator(140);

            var post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = false,
                PubDate  = new DateTimeOffset(new DateTime(1997, 7, 3), TimeSpan.Zero),
            };

            testDataStore.SavePost(post);

            var testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id.ToString("N"), true);

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal(new DateTimeOffset(new DateTime(1997, 7, 3), TimeSpan.Zero), post.PubDate);
        }
Exemple #8
0
        public void UpdatePost_ChangePost_UpdatesXMLFile()
        {
            IFileSystem   fakeFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(fakeFileSystem);

            Post oldPost = new Post
            {
                Slug     = "Old-Title",
                Title    = "Old Title",
                Body     = "Old body",
                IsPublic = true,
                Excerpt  = "Old excerpt"
            };

            Post newPost = new Post
            {
                Slug     = "New-Title",
                Title    = "New Title",
                Body     = "New body",
                IsPublic = true,
                Excerpt  = "New excerpt"
            };

            testDataStore.SavePost(oldPost);
            testDataStore.UpdatePost(newPost, oldPost);

            Assert.True(fakeFileSystem.FileExists($"BlogFiles\\New-Title.xml"));
            Post result = testDataStore.CollectPostInfo($"BlogFiles\\New-Title.xml");

            Assert.Equal(result.Slug, "New-Title");
            Assert.Equal(result.Title, "New Title");
            Assert.Equal(result.Body, "New body");
            Assert.True(result.IsPublic);
            Assert.Equal(result.Excerpt, "New excerpt");
        }
        public void SaveComment_SaveSimpleComment()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost       = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTimeOffset.Now,
                LastModified = DateTimeOffset.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };

            Comment testComment = new Comment
            {
                AuthorName = "Test name",
                Body       = "Test body",
                PubDate    = DateTimeOffset.Now,
                IsPublic   = true
            };

            testPost.Comments.Add(testComment);
            testDataStore.SavePost(testPost);

            string filePath = $"BlogFiles\\Posts\\{testPost.PubDate.UtcDateTime.ToString("s").Replace(":", "-")}_{testPost.Id}.xml";

            Assert.True(testFileSystem.FileExists(filePath));
            StringReader xmlFileContents = new StringReader(testFileSystem.ReadFileText(filePath));
            XDocument    doc             = XDocument.Load(xmlFileContents);

            Assert.True(doc.Root.Elements("Comments").Any());
        }
        public void Index_PostSummary_DoesNotIncludeDeletedComments()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());

            testDataStore.SavePost(new Post {
                Comments = new List <Comment> {
                    new Comment {
                        Body     = "Test comment 1",
                        IsPublic = true,
                    },
                    new Comment {
                        Body     = "Deleted comment 1",
                        IsPublic = false,
                    },
                },
                IsPublic = true,
                PubDate  = DateTimeOffset.Now,
            });

            IndexModel model = new IndexModel(testDataStore);

            model.OnGet();

            Assert.Equal(1, model.PostSummaries.Count());
            Assert.Equal(1, model.PostSummaries.First().CommentCount);
        }
Exemple #11
0
        public void CreateSlug_SlugExists_MultipleConflicts()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());

            testDataStore.SavePost(new Post {
                Slug = "test"
            });
            testDataStore.SavePost(new Post {
                Slug = "test-1"
            });
            SlugGenerator testSlugGenerator = new SlugGenerator(testDataStore);

            string slug = testSlugGenerator.CreateSlug("test");

            Assert.Equal("test-2", slug);
        }
Exemple #12
0
        public void SaveComment_SaveSimpleComment()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost       = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTime.Now,
                LastModified = DateTime.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };

            Comment testComment = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "Test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };

            testDataStore.SavePost(testPost);

            Assert.True(testFileSystem.FileExists("BlogFiles\\Test-slug.xml"));
            StringReader xmlFileContents = new StringReader(testFileSystem.ReadFileText("BlogFiles\\Test-slug.xml"));
            XDocument    doc             = XDocument.Load(xmlFileContents);

            Assert.True(doc.Root.Elements("Comments").Any());
        }
        public void GetPost_FindPostBySlug_ReturnsPost()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());
            var           comment       = new Comment
            {
                AuthorName = "Test name",
                Body       = "test body",
                PubDate    = DateTimeOffset.Now,
                IsPublic   = true
            };
            Post test = new Post
            {
                Slug         = "Test-Title",
                Title        = "Test Title",
                Body         = "Test body",
                PubDate      = DateTimeOffset.Now,
                LastModified = DateTimeOffset.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt",
            };

            test.Comments.Add(comment);
            testDataStore.SavePost(test);
            Post result = testDataStore.GetPost(test.Id);

            Assert.NotNull(result);
            Assert.Equal(result.Slug, "Test-Title");
            Assert.Equal(result.Body, "Test body");
            Assert.Equal(result.Title, "Test Title");
            Assert.NotNull(result.PubDate);
            Assert.NotNull(result.LastModified);
            Assert.True(result.IsPublic);
            Assert.Equal(result.Excerpt, "Test excerpt");
        }
Exemple #14
0
        public void UpdatePost_PublishedToDraft_TitleIsUpdated_DoNotUpdateSlug()
        {
            BlogDataStore    testDataStore    = new BlogDataStore(new FakeFileSystem());
            SlugGenerator    slugGenerator    = new SlugGenerator(testDataStore);
            ExcerptGenerator excerptGenerator = new ExcerptGenerator(140);

            Post post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = true,
            };

            testDataStore.SavePost(post);

            EditModel testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostSaveDraft(post.Id.ToString("N"));

            post = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.Equal("Title", post.Slug);
        }
        public void UpdatePost_TitleIsUpdated_UpdateSlug()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);

            Post oldPost = new Post
            {
                Slug     = "Old-Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now
            };

            Post newPost = new Post
            {
                Slug     = "New-Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now
            };

            testDataStore.SavePost(oldPost);
            newPost.Id = oldPost.Id;
            testDataStore.UpdatePost(newPost, true);

            Post result = testDataStore.CollectPostInfo($"BlogFiles\\Posts\\{newPost.PubDate.UtcDateTime.ToString("s").Replace(":","-")}_{newPost.Id}.xml");

            Assert.Equal("New-Title", result.Slug);
        }
Exemple #16
0
        public void UpdatePost_TitleIsUpdated_UpdateSlug()
        {
            IFileSystem      testFileSystem   = new FakeFileSystem();
            BlogDataStore    testDataStore    = new BlogDataStore(new FakeFileSystem());
            SlugGenerator    slugGenerator    = new SlugGenerator(testDataStore);
            ExcerptGenerator excerptGenerator = new ExcerptGenerator();

            Post post = new Post()
            {
                Slug     = "Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now,
            };

            testDataStore.SavePost(post);

            EditedPostModel editedPost = new EditedPostModel()
            {
                Title = "Edited Title",
            };

            EditModel model = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            model.OnPostPublish(post.Id, true);
            testDataStore.UpdatePost(post, post.IsPublic);

            Assert.True(testFileSystem.FileExists($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml"));
            Post result = testDataStore.CollectPostInfo($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml");

            Assert.Equal("Edited-Title", post.Slug);
        }
Exemple #17
0
        public void UpdatePost_TitleIsUpdated_UpdateSlug()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);

            Post oldPost = new Post
            {
                Slug     = "Old-Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now
            };

            Post newPost = new Post
            {
                Slug     = "New-Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now
            };

            testDataStore.SavePost(oldPost);
            testDataStore.UpdatePost(newPost, oldPost);

            Assert.True(testFileSystem.FileExists($"BlogFiles\\Posts\\{newPost.PubDate.ToFileTime()}_{newPost.Id}.xml"));
            Post result = testDataStore.CollectPostInfo($"BlogFiles\\Posts\\{newPost.PubDate.ToFileTime()}_{newPost.Id}.xml");

            Assert.False(testFileSystem.FileExists($"BlogFiles\\Posts\\{oldPost.PubDate.ToFileTime()}_{oldPost.Id}.xml"));
        }
Exemple #18
0
        public void UpdatePost_PublishedToPublished_TitleIsUpdated_UpdateSlug()
        {
            BlogDataStore    testDataStore    = new BlogDataStore(new FakeFileSystem());
            SlugGenerator    slugGenerator    = new SlugGenerator(testDataStore);
            ExcerptGenerator excerptGenerator = new ExcerptGenerator(140);

            Post post = new Post {
                Title    = "Title",
                Slug     = "Title",
                IsPublic = true,
                PubDate  = DateTimeOffset.Now,
            };

            testDataStore.SavePost(post);

            EditModel testEditModel = new EditModel(testDataStore, slugGenerator, excerptGenerator);

            testEditModel.PageContext = new PageContext();
            testEditModel.EditedPost  = new EditModel.EditedPostModel {
                Title   = "Edited Title",
                Excerpt = "Excerpt",
            };

            testEditModel.OnPostPublish(post.Id, true);

            post = testDataStore.GetPost(post.Id);

            Assert.Equal("Edited-Title", post.Slug);
        }
Exemple #19
0
        public void SavePost(Post post)
        {
            Post.Tags = Request.Form["Tags"][0].Replace(" ", "").Split(",").ToList();

            SlugGenerator slugGenerator = new SlugGenerator(_dataStore);

            Post.Slug = slugGenerator.CreateSlug(Post.Title);

            if (Post.Excerpt == null)
            {
                ExcerptGenerator excerptGenerator = new ExcerptGenerator();
                Post.Excerpt = excerptGenerator.CreateExcerpt(Post.Body, 140);
            }

            _dataStore.SavePost(Post);
            _blog.Posts.Add(Post);
        }
Exemple #20
0
        public IActionResult OnPostPublishComment()
        {
            string slug = RouteData.Values["slug"].ToString();

            Post = _dataStore.GetPost(slug);

            if (Post == null)
            {
                RedirectToPage("/Index");
            }
            else if (ModelState.IsValid)
            {
                Comment.IsPublic = true;
                Comment.UniqueId = Guid.NewGuid();
                Post.Comments.Add(Comment);
                _dataStore.SavePost(Post);
            }
            return(Page());
        }
Exemple #21
0
        public void SavePost_NoExcerptIsEntered_AutoGenerateExcerpt()
        {
            IFileSystem   fakeFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(fakeFileSystem);

            Post newPost = new Post
            {
                Title = "Title",
                Body  = "This is the body of my post",
            };

            testDataStore.SavePost(newPost);

            Assert.True(fakeFileSystem.FileExists($"BlogFiles\\Title.xml"));
            Post result = testDataStore.CollectPostInfo($"BlogFiles\\Title.xml");

            Assert.Equal(result.Body, "This is the body of my post");
            Assert.Equal(result.Excerpt, "This ");
        }
Exemple #22
0
        public void SavePost_SaveSimplePost()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost       = new Post {
                Slug  = "Test-Post-Slug",
                Title = "Test Title",
                Body  = "Test contents",
            };

            testDataStore.SavePost(testPost);

            Assert.True(testFileSystem.FileExists("BlogFiles\\Test-Post-Slug.xml"));
            Post result = testDataStore.GetPost("Test-Post-Slug");

            Assert.Equal("Test-Post-Slug", result.Slug);
            Assert.Equal("Test Title", result.Title);
            Assert.Equal("Test contents", result.Body);
        }
Exemple #23
0
        public void UpdatePost_ChangePost_DoesNotRemoveComments()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);

            Post oldPost = new Post
            {
                Slug     = "Old-Title",
                Title    = "Old Title",
                Body     = "Old body",
                IsPublic = true,
                Excerpt  = "Old excerpt"
            };
            Comment comment = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };
            Post newPost = new Post
            {
                Slug     = "New-Title",
                Title    = "New Title",
                Body     = "New body",
                IsPublic = true,
                Excerpt  = "New excerpt"
            };

            oldPost.Comments.Add(comment);
            testDataStore.SavePost(oldPost);
            newPost.Comments = oldPost.Comments;
            testDataStore.UpdatePost(newPost, oldPost);
            Post           result   = testDataStore.GetPost(newPost.Slug);
            List <Comment> comments = testDataStore.GetAllComments(newPost.Slug);

            Assert.True(testFileSystem.FileExists(@"BlogFiles\New-Title.xml"));
            Assert.False(testFileSystem.FileExists(@"BlogFiles\Old-Title.xml"));
            Assert.NotEmpty(comments);
        }
        public void GetAllComments_ReturnsList()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost       = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTimeOffset.Now,
                LastModified = DateTimeOffset.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };
            var comment1 = new Comment
            {
                AuthorName = "Test name",
                Body       = "test body",
                PubDate    = DateTimeOffset.Now,
                IsPublic   = true
            };
            var comment2 = new Comment
            {
                AuthorName = "Test name",
                Body       = "test body",
                PubDate    = DateTimeOffset.Now,
                IsPublic   = true
            };

            testPost.Comments.Add(comment1);
            testPost.Comments.Add(comment2);
            testDataStore.SavePost(testPost);

            string       text   = testFileSystem.ReadFileText($"BlogFiles\\Posts\\{testPost.PubDate.UtcDateTime.ToString("s").Replace(":","-")}_{testPost.Id}.xml");
            StringReader reader = new StringReader(text);

            XDocument      doc      = XDocument.Load(reader);
            List <Comment> comments = testDataStore.GetAllComments(doc);

            Assert.NotEmpty(comments);
        }
        public void SavePost_SaveSimplePost()
        {
            IFileSystem   testFileSystem = new FakeFileSystem();
            BlogDataStore testDataStore  = new BlogDataStore(testFileSystem);
            Post          testPost       = new Post
            {
                Slug     = "Test-Post-Slug",
                Title    = "Test Title",
                Body     = "Test contents",
                IsPublic = true
            };

            testPost.PubDate = DateTime.UtcNow;
            testDataStore.SavePost(testPost);

            Assert.True(testFileSystem.FileExists($"BlogFiles\\Posts\\{testPost.PubDate.UtcDateTime.ToString("s").Replace(":","-")}_{testPost.Id}.xml"));
            Post result = testDataStore.GetPost(testPost.Id);

            Assert.Equal("Test-Post-Slug", result.Slug);
            Assert.Equal("Test Title", result.Title);
            Assert.Equal("Test contents", result.Body);
        }
Exemple #26
0
        public void FindComment_SwitchIsPublicValue()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());
            Post          testPost      = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTime.Now,
                LastModified = DateTime.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };
            var comment1 = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };
            var comment2 = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };

            testPost.Comments.Add(comment1);
            testPost.Comments.Add(comment2);
            testDataStore.SavePost(testPost);

            Comment newcom = testDataStore.FindComment(comment1.UniqueId, testPost);

            Assert.Equal(testPost.Comments.Count, 2);
            Assert.Equal(newcom.UniqueId, comment1.UniqueId);
        }
Exemple #27
0
        public void GetAllComments_ReturnsList()
        {
            BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem());
            Post          testPost      = new Post
            {
                Slug         = "Test-slug",
                Title        = "Test title",
                Body         = "Test body",
                PubDate      = DateTime.Now,
                LastModified = DateTime.Now,
                IsPublic     = true,
                Excerpt      = "Test excerpt"
            };
            var comment1 = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };
            var comment2 = new Comment
            {
                AuthorName  = "Test name",
                AuthorEmail = "Test email",
                Body        = "test body",
                PubDate     = DateTime.Now,
                IsPublic    = true
            };

            testPost.Comments.Add(comment1);
            testPost.Comments.Add(comment2);
            testDataStore.SavePost(testPost);

            List <Comment> comments = testDataStore.GetAllComments(testPost.Slug);

            Assert.NotEmpty(comments);
        }
        public void DeletePost_MoveToTrash()
        {
            IFileSystem fakeFileSystem   = new FakeFileSystem();
            var         testDataStore    = new BlogDataStore(fakeFileSystem);
            var         markdownRenderer = new MarkdownRenderer();
            var         testPostModel    = new PostModel(testDataStore, markdownRenderer);

            testPostModel.PageContext = new PageContext();

            var post = new Post
            {
                Title     = "Title",
                Body      = "This is the body of my post",
                IsDeleted = false,
            };

            testDataStore.SavePost(post);

            testPostModel.OnPostDeletePost(post.Id.ToString("N"));
            var result = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.True(result.IsDeleted);
        }
Exemple #29
0
        public void UnDeletePost_MoveToIndex()
        {
            IFileSystem      fakeFileSystem   = new FakeFileSystem();
            BlogDataStore    testDataStore    = new BlogDataStore(fakeFileSystem);
            MarkdownRenderer markdownRenderer = new MarkdownRenderer();
            PostModel        testPostModel    = new PostModel(testDataStore, markdownRenderer);

            testPostModel.PageContext = new PageContext();

            Post post = new Post
            {
                Title     = "Title",
                Body      = "This is the body of my post",
                IsDeleted = true,
            };

            testDataStore.SavePost(post);

            testPostModel.OnPostUnDeletePost(post.Id.ToString("N"));
            Post result = testDataStore.GetPost(post.Id.ToString("N"));

            Assert.False(result.IsDeleted);
        }
        public IActionResult New(NewViewModel viewModel, string submitButton)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", viewModel));
            }

            var post = new BlogPost
            {
                Title        = viewModel.NewPost.Title,
                Body         = viewModel.NewPost.Body,
                LastModified = DateTimeOffset.Now,
                IsDeleted    = false,
            };

            if (submitButton == "Publish")
            {
                post.PubDate  = DateTimeOffset.Now;
                post.IsPublic = true;
            }

            if (Request != null)
            {
                _dataStore.SaveFiles(Request.Form.Files.ToList());
            }

            _dataStore.SavePost(post);

            if (submitButton == "Save Draft")
            {
                return(RedirectToAction("Drafts", "Admin"));
            }
            ;

            return(RedirectToAction("Blog", "Home"));
        }