GetPost() public method

public GetPost ( Postkey postkey ) : Post
postkey Postkey
return ForumShared.SharedDataTypes.Post
Example #1
0
 public void AddPostServerTests()
 {
     DataManager target = new DataManager();
     target.CleanForumData();
     User user = new User("user", "user");
     target.AddUser(user);
     target.AddSubforum(new Subforum("subforumName"));
     Postkey pk = new Postkey("user", DateTime.Now);
     Post p = new Post(pk, "Post", "body", null, "subforumName");
     bool actual = target.AddPost(p, "subforumName");
     Post p2 = target.GetPost(pk);
     Assert.IsTrue(actual);
     Assert.AreEqual(p.Key.Time, p2.Key.Time);
     Assert.AreEqual(p.Key.Username, p2.Key.Username);
     Assert.AreEqual(p.Title, p2.Title);
     Assert.AreEqual(p.Body, p2.Body);
     target.RemoveSubforum("subforumName");
 }
Example #2
0
 public void AddReplyServerTests()
 {
     DataManager target = new DataManager(); // TODO: Initialize to an appropriate value
     target.CleanForumData();
     User user = new User("user", "user");
     target.AddUser(user);
     target.AddSubforum(new Subforum("subforumName"));
     Post post = new Post(new Postkey("user", DateTime.Now), "MainPost", "", null, "subforumName");
     Thread.Sleep(1000);
     Post reply = new Post(new Postkey("user", DateTime.Now), "ReplyToMainPost", "", post.Key, "subforumName");
     bool actualPost = target.AddPost(post, "subforumName");
     bool actualReply = target.AddReply(reply, post.Key);
     Post replyFromDB =  target.GetPost(reply.Key);
     Assert.IsTrue(actualPost);
     Assert.IsTrue(actualReply);
     Assert.AreEqual(reply.Key.Time, replyFromDB.Key.Time);
     Assert.AreEqual(reply.Key.Username, replyFromDB.Key.Username);
     Assert.AreEqual(reply.Title, replyFromDB.Title);
     Assert.AreEqual(reply.Body, replyFromDB.Body);
     Post postFromDB = target.GetPost(target.GetPost(reply.ParentPost).Key);
     Assert.AreEqual(post.Key.Time, postFromDB.Key.Time);
     Assert.AreEqual(post.Key.Username, postFromDB.Key.Username);
     Assert.AreEqual(post.Title, postFromDB.Title);
     Assert.AreEqual(post.Body, postFromDB.Body);
     target.RemoveSubforum("subforumName");
 }
Example #3
0
        public void RemovePostServerTests()
        {
            DataManager target = new DataManager(); // TODO: Initialize to an appropriate value
            target.CleanForumData();
            User user = new User("user", "user");
            target.AddUser(user);
            target.AddSubforum(new Subforum("subforumName"));
            Postkey pk = new Postkey("user", DateTime.Now);
            Thread.Sleep(1001);
            Postkey pk2 = new Postkey("user", DateTime.Now);
            target.AddPost(new Post(pk, "post-TEST", "", null, ""), "SubforumName");
            target.AddReply(new Post(pk2, "reply-TEST", "body", pk, "SubforumName"), pk);
            bool actual;
            actual = target.RemovePost(pk2);
            Assert.IsTrue(actual);
            try
            {
                Assert.IsNull(target.GetPost(pk2));
            }
            catch (Exception)
            {

                Assert.IsTrue(true);
            }
            target.RemoveSubforum("subforumName");
        }
Example #4
0
 public void EditPostServerTests()
 {
     DataManager target = new DataManager();
     target.CleanForumData();
     User user = new User("user", "user");
     target.AddUser(user);
     target.AddSubforum(new Subforum("subforumName"));
     Postkey pk = new Postkey("user", DateTime.Now);
     Thread.Sleep(1000);
     target.AddPost(new Post(pk, "Post", "", null, null), "subforumName");
     Post reply = new Post(new Postkey("user", DateTime.Now), "Reply", "", pk, null);
     Thread.Sleep(1000);
     reply.Body = "reply body";
     bool ans = target.AddReply(reply, pk);
     Post reply2 = new Post(new Postkey("user", DateTime.Now), "Reply2 - new Update", "", pk, null);
     reply2.Body = " reply 2 body";
     bool ans2 = target.EditPost(reply2, reply.Key);
     Assert.IsTrue(ans2); // Need to check with debugger the content of reply
     Post editedPost = target.GetPost(reply.Key);
     Assert.AreEqual(reply.Key.Time, editedPost.Key.Time);
     Assert.AreEqual(reply.Key.Username, editedPost.Key.Username);
     Assert.AreEqual(reply2.Title, editedPost.Title);
     Assert.AreEqual(reply2.Body, editedPost.Body);
     target.RemoveSubforum("subforumName");
 }