Пример #1
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      = 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());
        }
Пример #2
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());
        }
Пример #3
0
        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);
        }