Ejemplo n.º 1
0
 public Comment(string content, User user, Discussion parentDiscussion)
 {
     this.content = content;
     this.publishDate = DateTime.Now;
     this.publisher = user;
     this.parentDiscussion = parentDiscussion;
 }
Ejemplo n.º 2
0
 public Discussion(string title, string content, User publisher, SubForum parentSubForum)
 {
     // TODO: Complete member initialization
     this.discussionId = discussionId;
     this.title = title;
     this.content = content;
     this.publishDate = DateTime.Now;
     this.publisher = publisher;
     this.comments = new List<Comment>();
     this.parentSubForum = parentSubForum;
 }
Ejemplo n.º 3
0
 public User(User oldUser)
 {
     this.memberID = oldUser.memberID;
     this.userName = oldUser.userName;
     this.password = oldUser.password;
     this.email = oldUser.email;
     this.friends = null;
     this.signature = oldUser.signature;
     this.isLoggedIn = oldUser.isLoggedIn;
     this.isConfirmed = oldUser.isConfirmed;
 }
        private int testGetResponsersForSingleUser()
        {
            {
                int testNum = 0;

                List<User> res;

                /* success tests */
                try
                {
                    this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                    Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", ADMIN_NAME, ADMIN_PSWD, Forum.RegPolicy.NONE);
                    this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                    SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                    User[] users = new User[10];
                    for(int i=0; i<10; i++)
                        users[i] = this.bridge.register(forum.forumId, "user"+i, "pswd"+i, "", "");

                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[5].userName);
                    AssertTrue(res.Count == 0);

                    for (int i = 0; i < 10; i++)
                        this.bridge.login(forum.forumId, users[i].userName, users[i].password);
                    Discussion[] discussions = new Discussion[30];
                    for (int i = 0; i < 30; i++)
                        discussions[i] = this.bridge.createNewDiscussion(users[i % 10].userName, users[i % 10].password, forum.forumId, subForum.subForumId, "discussion" + i, "no content");
                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[5].userName);
                    AssertTrue(res.Count == 0);

                    for (int i = 0; i < 10; i++)
                        this.bridge.createNewComment(users[i].userName, users[i].password, forum.forumId, subForum.subForumId, discussions[0].discussionId, "no content");

                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[0].userName);
                    AssertTrue(res.Count == 9); // 9- because it doesn't include user[0] (publisher)

                    testNum++;
                }
                catch { failMsg(testNum); }

                this.bridge.reset();

                /* failure tests */

                // wrong userName
                try
                {
                    this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                    Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", ADMIN_NAME, ADMIN_PSWD, Forum.RegPolicy.NONE);
                    this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                    SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                    User[] users = new User[10];
                    for (int i = 0; i < 10; i++)
                        users[i] = this.bridge.register(forum.forumId, "user" + i, "pswd" + i, "", "");

                    res = this.bridge.getResponsersForSingleUser("wrong user", ADMIN_PSWD, forum.forumId, users[5].userName);
                    failMsg(testNum);
                }
                catch { testNum++; }

                this.bridge.reset();

                // wrong password
                try
                {
                    this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                    Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", ADMIN_NAME, ADMIN_PSWD, Forum.RegPolicy.NONE);
                    this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                    SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                    User[] users = new User[10];
                    for (int i = 0; i < 10; i++)
                        users[i] = this.bridge.register(forum.forumId, "user" + i, "pswd" + i, "", "");

                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, "wrong pass", forum.forumId, users[5].userName);
                    failMsg(testNum);
                }
                catch { testNum++; }

                this.bridge.reset();

                // wrong forumId
                try
                {
                    this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                    Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", ADMIN_NAME, ADMIN_PSWD, Forum.RegPolicy.NONE);
                    this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                    SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                    User[] users = new User[10];
                    for (int i = 0; i < 10; i++)
                        users[i] = this.bridge.register(forum.forumId, "user" + i, "pswd" + i, "", "");

                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, 300000000, users[5].userName);
                    failMsg(testNum);
                }
                catch { testNum++; }

                this.bridge.reset();

                // wrong username of required user
                try
                {
                    this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                    Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", ADMIN_NAME, ADMIN_PSWD, Forum.RegPolicy.NONE);
                    this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                    SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                    User[] users = new User[10];
                    for (int i = 0; i < 10; i++)
                        users[i] = this.bridge.register(forum.forumId, "user" + i, "pswd" + i, "", "");

                    res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "wrong user");
                    failMsg(testNum);
                }
                catch { testNum++; }

                this.bridge.reset();

                return testNum;
            }
        }
Ejemplo n.º 5
0
 public Moderator(User user, modLevel level)
 {
     this.moderatorId = 0;
     this.user = user;
     this.level = level;
 }
        /* Large Scalabiliy - lots of comments and discussions */
        private int LargeScalability()
        {
            int testNum = 0;

            /* testGetNumOfCommentsSubForum */
            try
            {
                int res;

                const int DISCUSSIONS_NUMBER = 100;
                const int COMMENTS_NUMBER = 20;
                this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", "mngr", "mngrPswd", Forum.RegPolicy.NONE);
                this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                User user1 = this.bridge.register(forum.forumId, "user1", "pswd1", "", "");
                User user2 = this.bridge.register(forum.forumId, "user2", "pswd2", "", "");

                res = this.bridge.getNumOfCommentsSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, subForum.subForumId);
                AssertTrue(res == 0);

                user1 = this.bridge.login(forum.forumId, "user1", "pswd1");
                user2 = this.bridge.login(forum.forumId, "user2", "pswd2");
                Discussion[] discussions = new Discussion[DISCUSSIONS_NUMBER];
                for (int i = 0; i < DISCUSSIONS_NUMBER; i++)
                    discussions[i] = this.bridge.createNewDiscussion("user1", "pswd1", forum.forumId, subForum.subForumId, "discussion" + i, "no content");
                res = this.bridge.getNumOfCommentsSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, subForum.subForumId);
                AssertTrue(res == DISCUSSIONS_NUMBER);

                for (int i = 1; i <= COMMENTS_NUMBER; i++)
                {
                    this.bridge.createNewComment("user1", "pswd1", forum.forumId, subForum.subForumId, discussions[35].discussionId, "no content");
                    this.bridge.createNewComment("user2", "pswd2", forum.forumId, subForum.subForumId, discussions[55].discussionId, "no content");
                    this.bridge.createNewComment("user2", "pswd2", forum.forumId, subForum.subForumId, discussions[75].discussionId, "no content");
                }
                res = this.bridge.getNumOfCommentsSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, subForum.subForumId);
                AssertTrue(res == COMMENTS_NUMBER * 3 + DISCUSSIONS_NUMBER);

                testNum++;
            }
            catch { failMsg(testNum++); }

            this.bridge.reset();

            ///* getNumOfCommentsSingleUser */
            try
            {
                int res;

                const int DISCUSSIONS_NUMBER = 10;
                const int COMMENTS_NUMBER = 25;
                this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", "mngr", "mngrPswd", Forum.RegPolicy.NONE);
                this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                User user1 = this.bridge.register(forum.forumId, "user1", "pswd1", "", "");
                User user2 = this.bridge.register(forum.forumId, "user2", "pswd2", "", "");

                res = this.bridge.getNumOfCommentsSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, user1.userName);
                AssertTrue(res == 0);

                user1 = this.bridge.login(forum.forumId, "user1", "pswd1");
                user2 = this.bridge.login(forum.forumId, "user2", "pswd2");
                Discussion[] discussions1 = new Discussion[DISCUSSIONS_NUMBER];
                Discussion[] discussions2 = new Discussion[DISCUSSIONS_NUMBER];
                for (int i = 0; i < DISCUSSIONS_NUMBER; i++)
                {
                    discussions1[i] = this.bridge.createNewDiscussion(user1.userName, user1.password, forum.forumId, subForum.subForumId, "discussion" + i, "no content");
                    discussions2[i] = this.bridge.createNewDiscussion(user2.userName, user2.password, forum.forumId, subForum.subForumId, "discussion" + i, "no content");
                }
                res = this.bridge.getNumOfCommentsSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, user1.userName);
                AssertTrue(res == DISCUSSIONS_NUMBER);
                res = this.bridge.getNumOfCommentsSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, user2.userName);
                AssertTrue(res == DISCUSSIONS_NUMBER);

                for (int i = 1; i <= COMMENTS_NUMBER; i++)
                {
                    this.bridge.createNewComment(user1.userName, user1.password, forum.forumId, subForum.subForumId, discussions1[DISCUSSIONS_NUMBER- 3].discussionId, "no content");
                    this.bridge.createNewComment(user2.userName, user2.password, forum.forumId, subForum.subForumId, discussions2[DISCUSSIONS_NUMBER - 5].discussionId, "no content");
                    this.bridge.createNewComment(user2.userName, user2.password, forum.forumId, subForum.subForumId, discussions2[DISCUSSIONS_NUMBER - 9].discussionId, "no content");
                }
                res = this.bridge.getNumOfCommentsSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, user1.userName);
                AssertTrue(res == DISCUSSIONS_NUMBER + COMMENTS_NUMBER);
                res = this.bridge.getNumOfCommentsSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, user2.userName);
                AssertTrue(res == DISCUSSIONS_NUMBER + 2 * COMMENTS_NUMBER);

                testNum++;
            }
            catch { failMsg(testNum++); }

            this.bridge.reset();

            ///* getResponsersForSingleUser */
            try
            {
                List<User> res;

                const int USERS_NUMBER = 10;
                const int DISCUSSSION_NEMBER = 25;
                this.bridge.superUserLogin(SU_NAME, SU_PSWD);
                Forum forum = this.bridge.createNewForum(SU_NAME, SU_PSWD, "forum1", "mngr", "mngrPswd", Forum.RegPolicy.NONE);
                this.bridge.login(forum.forumId, ADMIN_NAME, ADMIN_PSWD);
                SubForum subForum = this.bridge.createNewSubForum(ADMIN_NAME, ADMIN_PSWD, forum.forumId, "subForum1");
                User[] users = new User[USERS_NUMBER];
                for (int i = 0; i < USERS_NUMBER; i++)
                    users[i] = this.bridge.register(forum.forumId, "user" + i, "pswd" + i, "", "");

                res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[5].userName);
                AssertTrue(res.Count == 0);

                for (int i = 0; i < USERS_NUMBER; i++)
                    this.bridge.login(forum.forumId, users[i].userName, users[i].password);
                Discussion[] discussions = new Discussion[DISCUSSSION_NEMBER];
                for (int i = 0; i < DISCUSSSION_NEMBER; i++)
                    discussions[i] = this.bridge.createNewDiscussion(users[i % USERS_NUMBER].userName, users[i % USERS_NUMBER].password, forum.forumId, subForum.subForumId, "discussion" + i, "no content");
                res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[5].userName);
                AssertTrue(res.Count == 0);

                for (int i = 0; i < USERS_NUMBER; i++)
                    this.bridge.createNewComment(users[i].userName, users[i].password, forum.forumId, subForum.subForumId, discussions[0].discussionId, "no content");

                res = this.bridge.getResponsersForSingleUser(ADMIN_NAME, ADMIN_PSWD, forum.forumId, users[0].userName);
                AssertTrue(res.Count == USERS_NUMBER - 1); //  (USERS_NUMBER - 1) - because it doesn't include user[0] (publisher)

                testNum++;
            }
            catch { failMsg(testNum++); }

            this.bridge.reset();

            return testNum;
        }
Ejemplo n.º 7
0
 internal List<User> getResponsersForSingleUser(User user)
 {
     List<User> responsers = new List<User>();
     foreach (Discussion d in discussions)
     {
         if(d.publisher.userName == user.userName)
             responsers.AddRange(d.getResponsersForSingleUser(user));
     }
     return responsers;
 }
Ejemplo n.º 8
0
 internal int getNumOfCommentsSingleUser(User user)
 {
     int result = 0;
     foreach (Discussion d in discussions)
     {
         result += d.getNumOfCommentsSingleUser(user);
     }
     return result;
 }
Ejemplo n.º 9
0
        internal Discussion createNewDiscussion(string title, string content, User user, ForumGeneratorContext db, HashSet<string> stopWords)
        {
            List<string> keyWords = parseKeyWords(content, stopWords);
            if (keyWords != null && keyWords.Count > 0)
            {
                if (isClassifies())
                {
                    checkRelevantContent(keyWords);
                }
                else
                    this.vocabulary = TextClassifier.addToVocabulary(keyWords, this.vocabulary);
            }

            Discussion newDiscussion = new Discussion(title, content, user, this);
            this.discussions.Add(newDiscussion);
            db.Discussions.Add(newDiscussion);
            db.SaveChanges();

            return newDiscussion;
        }
Ejemplo n.º 10
0
 internal Comment createNewComment(string content, User user, ForumGeneratorContext db)
 {
     content = content.Replace("/","//");
     Comment newComment = new Comment(content, user, this);
     //lock (db)
     //{
         this.comments.Add(newComment);
         db.Comments.Add(newComment);
         db.SaveChanges();
     //}
     return newComment;
 }
Ejemplo n.º 11
0
 internal List<User> getResponsersForSingleUser(User user)
 {
     List<User> responsers = new List<User>();
     foreach (Comment c in comments)
     {
         if (c.publisher != user)
             responsers.Add(c.publisher);
     }
     return responsers;
 }
Ejemplo n.º 12
0
        internal int getNumOfCommentsSingleUser(User user)
        {
            int result = 0;
            foreach (Comment c in comments)
            {
                if (c.publisher == user)
                    result++;
            }
            /* count the first comment, which is a discussion */
            if (this.publisher == user)
                result++;

            return result;
        }
Ejemplo n.º 13
0
        internal User register(string userName, string password, string email, string signature, ForumGeneratorContext db)
        {
            // Check if userName is already exist
            if (userExists(userName))
                throw new UnauthorizedAccessException(ForumGeneratorDefs.EXIST_USERNAME);
            else
            {
                // userName does not exist - create new User
                //lock (db)
                //{
                    User newUser = new User(userName, password, email, signature, this);

                    // RegistrationPolicy handling
                    switch (this.registrationPolicy)
                    {
                        case RegPolicy.NONE:
                            newUser.isConfirmed = true;
                            break;
                        case RegPolicy.ADMIN_CONFIRMATION:
                            newUser.isConfirmed = false;
                            break;
                        case RegPolicy.MAIL_ACTIVATION:
                            var fromAddress = new MailAddress("*****@*****.**", "Nimbus - Forum Generator");
                            var toAddress = new MailAddress(email, userName);
                            const string fromPassword = "******";
                            string subject = "Nimbus - Registration Confirmation Mail";
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("<HTML>Hey,");
                            sb.AppendLine("We've just got your registration. Please use <a href=\"http://localhost:56068/confirmation?forumId=" + forumId + "&userName="******"\">this link</a> to confirm your registration.");
                            sb.AppendLine("Thanks,");
                            sb.AppendLine("Nimbus Forum Generator</HTML>");
                            string body = sb.ToString();

                            var smtp = new SmtpClient
                                       {
                                           Host = "smtp.gmail.com",
                                           Port = 587,
                                           EnableSsl = true,
                                           DeliveryMethod = SmtpDeliveryMethod.Network,
                                           UseDefaultCredentials = false,
                                           Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                                       };
                            using (var message = new MailMessage(fromAddress, toAddress)
                                                 {
                                                     Subject = subject,
                                                     Body = body
                                                 })
                            {
                                smtp.Send(message);
                            }
                            break;
                    }

                    this.members.Add(newUser);
                    db.Users.Add(newUser);
                    db.SaveChanges();

                    return newUser;
               // }
            }
        }