public void 刪除評論() { ForumDB db = new ForumDB(); Account user = db.getUser("teamD", "test"); Assert.That(false, Is.EqualTo(db.deleteComment("teamD", 0))); db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", ""); db.insertArticle("teamD", "測試新文章標題2", "測試摘要2", "測試文章內容2", ""); db.insertArticle("teamA", "測試新文章標題3", "測試摘要3", "測試文章內容3", ""); db.insertComment("測試評論內容", "teamD", 0); db.insertComment("測試評論內容1", "teamD", 1); //db.insertComment("測試評論內容2", "teamD", 2); Assert.That(true, Is.EqualTo(db.deleteComment("teamD", 0))); Assert.That(true, Is.EqualTo(db.deleteComment("teamD", 1))); Assert.That(false, Is.EqualTo(db.deleteComment("teamA", 2))); }
public bool deleteComment(ForumDB db, int articleID, Account user) { // 判斷刪除文章是否為作者本人 if (articleID >= db.articles.Count) { return(false); } if (db.articles[articleID].account != (string)user.getName()) { return(false); } if (db.deleteComment((string)user.getName(), articleID)) { return(true); } else { return(false); } }