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}")); }
private void InitializePost() { string slug = RouteData.Values["slug"].ToString(); newPost = oldPost = _dataStore.GetPost(slug); if (oldPost == null) { RedirectToPage("/Index"); } }
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"); }
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); }
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_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); }
public IActionResult Edit(string id) { var post = _dataStore.GetPost(id); if (post == null) { return(RedirectToAction("Drafts")); } var viewModel = new EditViewModel { EditedPostModel = new EditedPostModel { Id = post.Id.ToString("N"), Title = post.Title, Body = post.Body, IsPublic = post.IsPublic, IsDeleted = post.IsDeleted } }; return(View(viewModel)); }
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); }
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 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); }
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 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); }
public void GetPost_PostDNE_ReturnsNull() { BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem()); Assert.Null(testDataStore.GetPost(12345)); }
public void GetPost_PostDNE_ReturnsNull() { BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem()); Assert.Null(testDataStore.GetPost("does-not-exist")); }