Exemplo n.º 1
0
        public void RepoConstructorWithValidatorTest()
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\XML_Data\\PostsDB.xml"))
            {
                File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\XML_Data\\PostsDB.xml");
                File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\XML_Data\\CommentsDB.xml");
            }
            IForumRepository xmlRepo = new ForumXmlRepository(new ForumXMLValidator());

            Assert.IsNotNull(xmlRepo);
            Assert.IsTrue(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\XML_Data\\PostsDB.xml"));
            Assert.IsTrue(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\XML_Data\\CommentsDB.xml"));
        }
Exemplo n.º 2
0
        public void RepoConstructorWithParamsTest()
        {
            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");

            Assert.IsNotNull(xmlRepo);
            Assert.IsTrue(File.Exists("\\XML_Data\\PostsDB.xml"));
            Assert.IsTrue(File.Exists("\\XML_Data\\CommentsDB.xml"));
        }
Exemplo n.º 3
0
        public void AddPostTest()
        {
            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");

            Assert.IsTrue(xmlRepo.AddPost(new Post(1, postBody1)));
            Assert.IsTrue(xmlRepo.AddPost(new Post(2, postBody2)));

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

            Assert.AreEqual(posts.Count, 2);
        }
Exemplo n.º 4
0
        public void GetAllCommentsTest()
        {
            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));

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

            Assert.IsNotNull(comments);
            Assert.AreEqual(comments.Count, 2);
        }
Exemplo n.º 5
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));
        }