Пример #1
0
        public void GetPostTest()
        {
            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.AddPost(new Post(1, postBody1));
            xmlRepo.AddPost(new Post(2, postBody2));

            IPost post = xmlRepo.GetPost(1);

            Assert.IsNotNull(post);
            Assert.AreEqual <string>(post.Body, postBody1);
            Assert.AreEqual <string>(xmlRepo.GetPost(2).Body, postBody2);
            Assert.IsNull(xmlRepo.GetPost(3));
        }
Пример #2
0
        public void DeletePostTest()
        {
            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.AddPost(new Post(1, postBody1));
            xmlRepo.AddPost(new Post(2, postBody2));

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

            List <IPost> posts = xmlRepo.GetAllPosts().ToList <IPost>();

            Assert.AreEqual(posts.Count, 1);

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