AddSubforum() public method

public AddSubforum ( string subforumName ) : System.Result
subforumName string
return System.Result
Esempio n. 1
0
        public void UserIntegration2()
        {
            ClientController cc1 = new ClientController();

            cc1.Login("admin", "admin");

            ClientController cc2 = new ClientController();
            cc2.Register("test2", "123456");
            cc2.Login("test2", "123456");

            ClientController cc3 = new ClientController();
            cc2.Register("test3", "123456");
            cc2.Login("test3", "123456");

            cc2.Post("Cars", "title1", "body1");

            Post[] posts = cc2.GetSubforum("Cars");
            Postkey tmp_postKey = null;
            for (int i = 0; i < posts.Length; i++)
            {
                if (posts[i].Title.Equals("title1"))
                    tmp_postKey = posts[i].Key;
            }

                //try to edit message not by the writer, admin or moderator
                Assert.AreEqual(Result.USER_NOT_FOUND, cc3.EditPost(tmp_postKey, "BadTitle", "BadBody"));

                //try to edit message by admin
                Assert.AreEqual(Result.OK, cc2.EditPost(tmp_postKey, "GoodTitle", "GoodBody"));

                ClientController cc4 = new ClientController();
                cc1.ReplaceAdmin("newAdmin", "newAdminpass"); //the newAdmin will create at the server

                //try to login with the new admin (the registeration was at the replaceAdmin)
                Assert.IsTrue(cc4.Login("newAdmin", "newAdmin"));

                //logic:
                //  if the old admin was just admin (with out any moderator of any subforum)
                //      then he will become regular member.
                //  if the old admin was moderator of any forum
                //      then he will be just the relevant forum moderator (and no admin).

                //try to create subform by non-admin
                Assert.AreEqual(Result.SECURITY_ERROR, cc1.AddSubforum("badbadForum"));

                //try to edit message by non-admin or non moderator
                //   Assert.AreEqual(Result.SECURITY_ERROR, cc1.EditPost("xxx", "yyy"));

                //try to remove non existing subforum (by admin)
                Assert.AreEqual(Result.SECURITY_ERROR, cc4.RemoveSubforum("Forums"));

                //try to remove subforum by non-admin
                Assert.AreEqual(Result.SECURITY_ERROR, cc1.RemoveSubforum("Cars"));
        }
Esempio n. 2
0
        public void UserIntegration1()
        {
            ClientController cc1 = new ClientController();

            cc1.Login("admin", "admin");

            ClientController cc2 = new ClientController();
            cc2.Register("test2", "123456");
            cc2.Login("test2", "123456");

            ClientController cc3 = new ClientController();
            cc2.Register("test3", "123456");
            cc2.Login("test3", "123456");

            //try to add moderator by non-admin
            Assert.AreEqual(Result.OK | Result.INSUFFICENT_PERMISSIONS, cc2.AddModerator("test2", "Cars"));

            cc1.AddModerator("test2", "Cars");

            //to this subforum has already moderator
            Assert.AreEqual(Result.OK, cc1.AddModerator("test2", "Cars"));

            cc2.Post("Cars", "msg2", "body2");
            cc3.Post("Cars", "msg3", "body3");

            //try to replace moderator by non-admin (see: cc2 is the contrller of userName test2)
            Assert.AreEqual(Result.OK | Result.INSUFFICENT_PERMISSIONS | Result.POLICY_REJECTED, cc2.ReplaceModerator("test3", "test2", "Cars"));

            cc1.ReplaceModerator("test3", "test2", "Cars");

            //try to edit message by non-moderator
              //  Assert.AreEqual(Result.SECURITY_ERROR, cc2.EditPost("hehe", "bebe"), "hellow evil world");

            //try to add subform by non-admin
            Assert.AreEqual(Result.INSUFFICENT_PERMISSIONS, cc2.AddSubforum("badSubForum"));

            //try to add subform by admin
            Assert.AreEqual(Result.OK, cc1.AddSubforum("bestForum"));
        }