Ejemplo n.º 1
0
        public void 刪除文章()
        {
            ForumDB db   = new ForumDB();
            Account user = db.getUser("teamD", "test");

            Assert.That(false, Is.EqualTo(db.deleteArticle(0)));

            db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", "pictures1");
            db.insertArticle("teamD", "測試新文章標題2", "測試摘要2", "測試文章內容2", "pictures1");
            db.insertArticle("teamD", "測試新文章標題3", "測試摘要3", "測試文章內容3", "pictures1");

            Assert.That(true, Is.EqualTo(db.deleteArticle(0)));
            Assert.That(2, Is.EqualTo(db.articles.Count));
            Assert.That("teamD", Is.EqualTo(db.articles[0].account));
            Assert.That("測試新文章標題2", Is.EqualTo(db.articles[0].title));
            Assert.That("測試摘要2", Is.EqualTo(db.articles[0].summary));
            Assert.That("測試文章內容2", Is.EqualTo(db.articles[0].content));
            Assert.That("pictures1", Is.EqualTo(db.articles[0].patterns));
            Assert.That("teamD", Is.EqualTo(db.articles[1].account));
            Assert.That("測試新文章標題3", Is.EqualTo(db.articles[1].title));
            Assert.That("測試摘要3", Is.EqualTo(db.articles[1].summary));
            Assert.That("測試文章內容3", Is.EqualTo(db.articles[1].content));
            Assert.That("pictures1", Is.EqualTo(db.articles[1].patterns));
            Assert.That(true, Is.EqualTo(db.deleteArticle(0)));
            Assert.That(1, Is.EqualTo(db.articles.Count));
            Assert.That("teamD", Is.EqualTo(db.articles[0].account));
            Assert.That("測試新文章標題3", Is.EqualTo(db.articles[0].title));
            Assert.That("測試摘要3", Is.EqualTo(db.articles[0].summary));
            Assert.That("測試文章內容3", Is.EqualTo(db.articles[0].content));
            Assert.That("pictures1", Is.EqualTo(db.articles[0].patterns));
            Assert.That(true, Is.EqualTo(db.deleteArticle(0)));
            Assert.That(0, Is.EqualTo(db.articles.Count));
        }
        public void 搜尋文章All_Action()
        {
            ForumDB db = new ForumDB();

            db.insertArticle("teamD", "文章標題aa", "測試摘要1a", "文章內容aa", "pictures");
            db.insertArticle("teamD", "文章標題aa2", "測試摘要1b", "文章內容aa3", "pictures");
            db.insertArticle("teamD", "文章標題bb", "測試摘要1c", "文章內容bb", "pictures");
            db.insertArticle("teamD", "文章標題bb22", "測試摘要2a", "文章內容bb33", "pictures");
            db.insertArticle("teamD", "文章標題ccc", "測試摘要2b", "文章內容ccc", "pictures");

            Action         action = new Action();
            List <Article> tmp    = action.searchArticleAll(db, "1");

            Assert.That("測試摘要1a", Is.EqualTo(tmp[0].summary));
            Assert.That("測試摘要1b", Is.EqualTo(tmp[1].summary));
            Assert.That("測試摘要1c", Is.EqualTo(tmp[2].summary));

            tmp = action.searchArticleAll(db, "2");
            Assert.That("文章標題aa2", Is.EqualTo(tmp[0].title));
            Assert.That("測試摘要2a", Is.EqualTo(tmp[1].summary));
            Assert.That("測試摘要2b", Is.EqualTo(tmp[2].summary));


            tmp = action.searchArticleAll(db, "a");
            Assert.That("測試摘要1a", Is.EqualTo(tmp[0].summary));
            Assert.That("文章標題aa2", Is.EqualTo(tmp[1].title));
            Assert.That("測試摘要2a", Is.EqualTo(tmp[2].summary));
        }
Ejemplo n.º 3
0
        public bool register(ForumDB db, string account, string password, string cofirmpass)
        {
            string[] special = { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "<", ">", "/" };
            for (int i = 0; i < special.Count(); i++)
            {
                if (account.Contains(special[i]))
                {
                    return(false);
                }
            }

            if (password.Count() < 6 || password.Count() > 16)
            {
                return(false);
            }

            if (password != cofirmpass)
            {
                return(false);
            }

            if (db.insertUser(account, password))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        internal string getArticleHeaderList(ForumDB db, int ArticleID)
        {
            string result;

            result = db.getTitle(ArticleID);
            return(result);
        }
        public void 編輯文章內容_Action()
        {
            ForumDB db = new ForumDB();

            Assert.That(true, Is.EqualTo(db.insertArticle("teamD", "文章標題", "測試摘要", "文章內容", "picture1")));
            Assert.That(true, Is.EqualTo(db.insertArticle("teamD", "文章標題22", "測試摘要22", "文章內容22", "picture1")));
            Action action = new Action();

            bool result = action.modifyArticleContent(db, 0, db.accounts[0], "更新文章內容", "替換文章內圖片");

            Assert.That(true, Is.EqualTo(result));
            Assert.That("文章標題", Is.EqualTo(db.articles[0].title));
            Assert.That("測試摘要", Is.EqualTo(db.articles[0].summary));
            Assert.That("更新文章內容", Is.EqualTo(db.articles[0].content));
            Assert.That("替換文章內圖片", Is.EqualTo(db.articles[0].patterns));

            result = action.modifyArticleContent(db, 0, db.accounts[0], "更新第二次文章內容", "第二次替換文章內圖片");
            Assert.That(true, Is.EqualTo(result));
            Assert.That("文章標題", Is.EqualTo(db.articles[0].title));
            Assert.That("測試摘要", Is.EqualTo(db.articles[0].summary));
            Assert.That("更新第二次文章內容", Is.EqualTo(db.articles[0].content));
            Assert.That("第二次替換文章內圖片", Is.EqualTo(db.articles[0].patterns));

            result = action.modifyArticleContent(db, 1, db.accounts[0], "更新文章內容22", "替換第二篇文章內圖片");
            Assert.That(true, Is.EqualTo(result));
            Assert.That("文章標題22", Is.EqualTo(db.articles[1].title));
            Assert.That("測試摘要22", Is.EqualTo(db.articles[1].summary));
            Assert.That("更新文章內容22", Is.EqualTo(db.articles[1].content));
            Assert.That("替換第二篇文章內圖片", Is.EqualTo(db.articles[1].patterns));
        }
Ejemplo n.º 6
0
        public void 驗證使用者()
        {
            ForumDB db   = new ForumDB();
            Account user = db.getUser("teamD", "test");

            Assert.That("teamD", Is.EqualTo(user.getName()));
            Assert.That(0, Is.EqualTo(user.getID()));
        }
        public void 註冊新用戶_第二字密碼不符_Action()
        {
            ForumDB db       = new ForumDB();
            Action  Register = new Action();
            bool    result   = Register.register(db, "1234567", "1234567", "12345678");

            Assert.That(false, Is.EqualTo(result));
        }
Ejemplo n.º 8
0
        public void 插入新文章失敗()
        {
            ForumDB db = new ForumDB();

            Assert.That(false, Is.EqualTo(db.insertArticle("123", "測試新文章標題", "測試摘要", "測試文章內容", "picture1")));
            Assert.That(false, Is.EqualTo(db.insertArticle("test222", "測試新文章標題", "測試摘要", "測試文章內容", "picture1")));
            Assert.That(false, Is.EqualTo(db.insertArticle("teamB", "測試新文章標題", "測試摘要", "測試文章內容", "picture1")));
        }
        public void 註冊新用戶_密碼長度不合_Action()
        {
            ForumDB db       = new ForumDB();
            Action  Register = new Action();
            bool    result   = Register.register(db, "123", "123", "123");

            Assert.That(false, Is.EqualTo(result));
        }
        public void 登入失敗_Action()
        {
            ForumDB db      = new ForumDB();
            Action  action  = new Action();
            bool    isLogin = action.signin(db, "teamA", "1234");

            Assert.That(false, Is.EqualTo(isLogin));
        }
Ejemplo n.º 11
0
        public void 讀取文章列表()
        {
            ForumDB db = new ForumDB();

            db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", "測試文章內圖片");
            Assert.That("測試新文章標題", Is.EqualTo(db.getTitle(0)));
            Assert.That("None", Is.EqualTo(db.getTitle(1)));
        }
        public void 登入_Action()
        {
            ForumDB db      = new ForumDB();
            Action  action  = new Action();
            bool    isLogin = action.signin(db, "teamD", "test");

            Assert.That(true, Is.EqualTo(isLogin));
        }
Ejemplo n.º 13
0
        public void 讀取文章圖片()
        {
            ForumDB db = new ForumDB();

            db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", "測試文章內圖片");
            Assert.That("測試文章內圖片", Is.EqualTo(db.articles[0].patterns));
            Assert.That(0, Is.EqualTo(db.articles[0].articleID));
        }
        public void 取得積分()
        {
            ForumDB db       = new ForumDB();
            Action  GetScore = new Action();

            db.insertArticle("teamD", "Test", "Test", "Test", "Test");
            GetScore.addComment(db, db.accounts[0], db.articles[0], "Comment_Test");
            Assert.That(1, Is.EqualTo(db.accounts[0].score));
        }
Ejemplo n.º 15
0
        public void 插入新使用者()
        {
            ForumDB db        = new ForumDB();
            bool    isSuccess = db.insertUser("test", "1234");

            Assert.That(true, Is.EqualTo(isSuccess));
            Assert.That("test", Is.EqualTo(db.accounts[1].name));
            Assert.That("1234", Is.EqualTo(db.accounts[1].password));
        }
        public void 新增文章_Action()
        {
            ForumDB db     = new ForumDB();
            Action  action = new Action();

            db.insertArticle("teamD", "測試標題", "測試摘要22", "測試內容", "測試圖片");
            Assert.That("測試標題", Is.EqualTo(db.getTitle(0)));
            Assert.That("測試內容", Is.EqualTo(db.getArticle(0)));
            Assert.That("測試內容", Is.EqualTo(action.addArticle(db, db.accounts[0], "測試標題", "測試摘要", "測試內容")));
        }
        public void 取得文章標題_更新日期_Action()
        {
            ForumDB db    = new ForumDB();
            Action  Title = new Action();

            db.insertArticle("teamD", "For_Test", "測試摘要", "Hello world", "pictures");
            string result = Title.getArticleHeaderList(db, 1);

            Assert.That(DateTime.Now.ToLongDateString().ToString(), Is.EqualTo(db.articles[0].time));
        }
        public void 註冊新用戶_Action()
        {
            ForumDB db       = new ForumDB();
            Action  Register = new Action();
            bool    result   = Register.register(db, "newaccount", "newpass", "newpass");

            Assert.That(true, Is.EqualTo(result));
            Assert.That("newaccount", Is.EqualTo(db.accounts[1].name));
            Assert.That("newpass", Is.EqualTo(db.accounts[1].password));
        }
        public void 取得文章標題_Action()
        {
            ForumDB db    = new ForumDB();
            Action  Title = new Action();

            db.insertArticle("teamD", "For_Test", "測試摘要", "Hello world", "pictures");
            string result = Title.getArticleHeaderList(db, 0);

            Assert.That("For_Test", Is.EqualTo(result));
        }
        public void 登出_Action()
        {
            ForumDB db      = new ForumDB();
            Action  action  = new Action();
            bool    isLogin = action.signin(db, "teamD", "test");

            Assert.That(true, Is.EqualTo(action.loggedin));
            action.signout(db);
            Assert.That(null, Is.EqualTo(action.user));
            Assert.That(false, Is.EqualTo(action.loggedin));
        }
        public void 向文章中插入圖片失败_Action()
        {
            ForumDB db = new ForumDB();

            Assert.That(true, Is.EqualTo(db.insertArticle("teamD", "文章標題", "測試摘要", "文章內容", "")));
            Action action = new Action();

            bool result = action.insert_Patterns_into_Article(db, 0, null);

            Assert.That(false, Is.EqualTo(result));
            Assert.That("", Is.EqualTo(db.articles[0].patterns));
        }
        public void 刪除評論_Action()
        {
            ForumDB db     = new ForumDB();
            Action  action = new Action();

            Assert.That(false, Is.EqualTo(action.deleteComment(db, 0, db.accounts[0])));
            db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", "");
            db.insertArticle("teamA", "測試新文章標題1", "測試摘要1", "測試文章內容1", "");
            db.insertComment("測試評論內容", "teamD", 0);
            Assert.That(true, Is.EqualTo(action.deleteComment(db, 0, db.accounts[0])));
            Assert.That(false, Is.EqualTo(action.deleteComment(db, 1, db.accounts[0])));
        }
Ejemplo n.º 23
0
        public void 讀取文章內容()
        {
            ForumDB db = new ForumDB();

            db.insertArticle("teamD", "測試新文章標題", "測試摘要", "測試文章內容", "測試文章內圖片");
            //Assert.That("測試文章內容", Is.EqualTo(db.getArticle(0)));
            Assert.That("teamD", Is.EqualTo(db.articles[0].account));
            Assert.That("測試新文章標題", Is.EqualTo(db.articles[0].title));
            Assert.That("測試文章內容", Is.EqualTo(db.articles[0].content));
            Assert.That("測試文章內圖片", Is.EqualTo(db.articles[0].patterns));
            Assert.That(0, Is.EqualTo(db.articles[0].articleID));
        }
        public void 刪除文章_Action()
        {
            ForumDB db = new ForumDB();

            Assert.That(true, Is.EqualTo(db.insertArticle("teamD", "bbb", "測試摘要", "ccc", "picture1")));
            Action delete = new Action();

            bool result = delete.deleteArticle(db, 0, db.accounts[0]);

            Assert.That(true, Is.EqualTo(result));
            // Assert.That(true, Is.EqualTo(result));
        }
Ejemplo n.º 25
0
 public bool insert_Patterns_into_Article(ForumDB db, int articleID, string patterns)
 {
     if (patterns == null)
     {
         return(false);
     }
     else
     {
         db.articles[articleID].patterns = patterns;
     }
     return(true);
 }
Ejemplo n.º 26
0
 public bool modifyArticleSummary(ForumDB db, int articleID, Account user, string summary)
 {
     if (articleID >= db.articles.Count)
     {
         return(false);
     }
     if (db.articles[articleID].account != (string)user.getName())
     {
         return(false);
     }
     db.articles[articleID].summary = summary;
     return(true);
 }
Ejemplo n.º 27
0
 public bool signin(ForumDB db, string account, string password)
 {
     user = db.getUser(account, password);
     if (user != null)
     {
         loggedin = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 28
0
 public string signout(ForumDB db)
 {
     if (loggedin)
     {
         loggedin = false;
         user     = null;
         return("log out ");
     }
     else
     {
         return("please log in firstly!");
     }
 }
        public void 非作者刪除文章_Action()
        {
            ForumDB db       = new ForumDB();
            Action  register = new Action();

            register.register(db, "hacker", "test123456", "test123456");
            Assert.That(true, Is.EqualTo(db.insertArticle("hacker", "bbb", "測試摘要", "ccc", "picture1")));
            Action delete = new Action();

            bool result = delete.deleteArticle(db, 0, db.accounts[0]);

            Assert.That(false, Is.EqualTo(result));
        }
        public void 新增评论_Action()
        {
            ForumDB db     = new ForumDB();
            Action  action = new Action();
            Article art    = new Article();

            db.insertArticle("teamD", "測試標題", "測試摘要", "測試內容", "picture1");
            db.insertComment("測試內容", "teamD", 0);
            List <Comment> match = db.getComment(0);

            Assert.That("測試內容", Is.EqualTo(match[0].getContent()));
            Assert.That("測試內容", Is.EqualTo(action.addComment(db, db.accounts[0], art, "測試內容")));
        }