Exemplo n.º 1
0
        private void SetupAddFriendMocks(out MockRepository mocks, out ICacheManager cache, out IDnaDataReaderCreator readerCreator, out ICallingUser viewingUser, out ISite site, out IDnaDataReader reader, out IDnaDataReader reader2)
        {
            mocks = new MockRepository();
            cache = mocks.DynamicMock<ICacheManager>();
            readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            site = mocks.DynamicMock<ISite>();
            viewingUser = mocks.DynamicMock<ICallingUser>();
            
            // mock the response
            viewingUser.Stub(x => x.UserID).Return(1090497224);
            viewingUser.Stub(x => x.IsUserA(BBC.Dna.Users.UserTypes.Editor)).Return(false);
            viewingUser.Stub(x => x.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)).Return(false);

            reader = mocks.DynamicMock<IDnaDataReader>();
            reader2 = mocks.DynamicMock<IDnaDataReader>();

            AddFriendsListUserDatabaseRows(reader, "");

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            reader2.Stub(x => x.HasRows).Return(true);
            reader2.Stub(x => x.Read()).Return(true);

            readerCreator.Stub(x => x.CreateDnaDataReader("getdnauseridfromidentityusername")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("watchuserjournal")).Return(reader2);
            readerCreator.Stub(x => x.CreateDnaDataReader("deletewatchedusers")).Return(reader2);

            mocks.ReplayAll();
        }
Exemplo n.º 2
0
        private void CreateCommentForum(ICallingUser user, out CommentForum commentForum, out CommentInfo comment, out CommentInfo result)
        {
            string commentForumID = "good" + Guid.NewGuid().ToString();
            commentForum = CommentForumCreate(commentForumID);

            //set up test data
            comment = new CommentInfo { text = Guid.NewGuid().ToString().Substring(0, 10) };

            // Add the user
            _comments.CallingUser = user;

            result = _comments.CreateComment(commentForum, comment);//should pass successfully
            Assert.IsTrue(result != null);
            Assert.IsTrue(result.ID > 0);
            Assert.IsTrue(result.text == comment.text);
        }
        private void SetupBlockUnblockUserMocks(out MockRepository mocks, 
                                        out ICacheManager cache, 
                                        out IDnaDataReaderCreator readerCreator, 
                                        out ICallingUser viewingUser, 
                                        out ISite site, 
                                        out IDnaDataReader reader, 
                                        out IDnaDataReader reader2,
                                        int viewingUserId)
        {
            mocks = new MockRepository();
            cache = mocks.DynamicMock<ICacheManager>();
            readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            site = mocks.DynamicMock<ISite>();
            viewingUser = mocks.DynamicMock<ICallingUser>();

            // mock the response
            viewingUser.Stub(x => x.UserID).Return(viewingUserId);
            viewingUser.Stub(x => x.IsUserA(BBC.Dna.Users.UserTypes.Editor)).Return(false);
            viewingUser.Stub(x => x.IsUserA(BBC.Dna.Users.UserTypes.SuperUser)).Return(false);

            reader = mocks.DynamicMock<IDnaDataReader>();
            reader2 = mocks.DynamicMock<IDnaDataReader>();

            AddBlockedUserSubscriptionsListUserDatabaseRows(reader, "");

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);

            reader2.Stub(x => x.HasRows).Return(true);
            reader2.Stub(x => x.Read()).Return(true);

            readerCreator.Stub(x => x.CreateDnaDataReader("getdnauseridfromidentityusername")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("blockusersubscription")).Return(reader2);
            readerCreator.Stub(x => x.CreateDnaDataReader("unblockusersubscription")).Return(reader2);

            mocks.ReplayAll();
        }
Exemplo n.º 4
0
        private void SetupforumAndTestCharLimit(ICallingUser user, bool shouldAssertCharLimit)
        {
            try
            {
                SetCharLimitTo15ForSite();

                CommentForum commentForum;
                CommentInfo comment;
                CommentInfo result;
                CreateCommentForum(user, out commentForum, out comment, out result);

                //with some markup
                comment.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", Guid.NewGuid().ToString().Substring(0, 10));
                result = _comments.CreateComment(commentForum, comment);//should pass successfully
                Assert.IsTrue(result != null);
                Assert.IsTrue(result.ID > 0);
                Assert.IsTrue(result.text == comment.text);

                //string too large with html
                comment.text = String.Format("<div><b><i><u>{0}</u></i></b></div>", "stringtopad".PadRight(20));
                try
                {
                    result = _comments.CreateComment(commentForum, comment);
                }
                catch (ApiException ex)
                {
                    if (shouldAssertCharLimit)
                    {
                        Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit);
                    }
                    else
                    {
                        throw ex;
                    }
                }

                //string too large without html
                comment.text = String.Format("{0}", "stringtopad".PadRight(20));
                try
                {
                    result = _comments.CreateComment(commentForum, comment);
                }
                catch (ApiException ex)
                {
                    if (shouldAssertCharLimit)
                    {
                        Assert.IsTrue(ex.type == ErrorType.ExceededTextLimit);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            finally
            {
                RemoveCharLimitForSite();
            }
        }