Exemplo n.º 1
0
        public void GetCommentTest()
        {
            if (File.Exists("\\XML_Data\\PostsDB.xml"))
            {
                File.Delete("\\XML_Data\\PostsDB.xml");
                File.Delete("\\XML_Data\\CommentsDB.xml");
            }
            IForumRepository xmlRepo = new ForumXmlRepository("\\XML_Data\\PostsDB.xml", "\\XML_Data\\CommentsDB.xml");

            xmlRepo.AddComment(new Comment(1, 1, commentBody1));
            xmlRepo.AddComment(new Comment(2, 1, commentBody2));

            IComment comment = xmlRepo.GetComment(1);

            Assert.IsNotNull(comment);
            Assert.AreEqual <string>(comment.Body, commentBody1);
            Assert.AreEqual <string>(xmlRepo.GetComment(2).Body, commentBody2);
            Assert.IsNull(xmlRepo.GetComment(3));
        }
Exemplo n.º 2
0
        public void DeleteCommentTest()
        {
            if (File.Exists("\\XML_Data\\PostsDB.xml"))
            {
                File.Delete("\\XML_Data\\PostsDB.xml");
                File.Delete("\\XML_Data\\CommentsDB.xml");
            }
            IForumRepository xmlRepo = new ForumXmlRepository("\\XML_Data\\PostsDB.xml", "\\XML_Data\\CommentsDB.xml");

            xmlRepo.AddComment(new Comment(1, 1, commentBody1));
            xmlRepo.AddComment(new Comment(2, 1, commentBody2));

            Assert.IsTrue(xmlRepo.DeleteComment(1));

            List <IComment> comments = xmlRepo.GetAllComments().ToList <IComment>();

            Assert.AreEqual(comments.Count, 1);

            Assert.IsNotNull(xmlRepo.GetComment(2));
            Assert.IsNull(xmlRepo.GetComment(1));
        }