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 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); }