Exemple #1
0
        public void RatingCreate_ProcessPreMod_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName, ModerationServiceGroup= ModerationStatus.ForumStatus.PreMod };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

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

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);



            siteList.Stub(x => x.GetSiteOptionValueBool(siteId, "Moderation", "ProcessPreMod")).Return(true);
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.InvalidProcessPreModState, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }
Exemple #2
0
        public void RatingCreate_NotSecureWithOption_ReturnCorrectError()
        {
            string siteName = "h2g2";
            string uid = "uid";
            var text = "Here is my rating that is not posted securely";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

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

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            siteList.Stub(x => x.GetSiteOptionValueInt(0, "CommentForum", "EnforceSecurePosting")).Return(1);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.NotSecure, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }
Exemple #3
0
        public void RatingCreate_ValidInput_ReturnCorrectObject()
        {
            string siteName = "h2g2";
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum {Id = uid, SiteName = siteName};
            var ratingInfo = new RatingInfo {text = text, rating = 0};

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("postid")).Return(1);

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            site.Stub(x => x.SiteID).Return(1);
            siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1");
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            RatingInfo comment = reviews.RatingCreate(ratingForum, ratingInfo);

            Assert.IsNotNull(comment);
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate"));
        }
Exemple #4
0
        public void RatingCreate_AsPreMod_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test text";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum
                                  {
                                      Id = uid,
                                      SiteName = siteName,
                                      ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod
                                  };
            var ratingInfo = new RatingInfo {text = text, rating = 0};

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

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

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader);

            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            RatingInfo comment = reviews.RatingCreate(ratingForum, ratingInfo);

            Assert.IsNotNull(comment);
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate"));
        }
Exemple #5
0
        public void RatingCreate_UserAlreadyRated_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

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

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(true);
            readerUserRating.Stub(x => x.Read()).Return(true);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            site.Stub(x => x.SiteID).Return(1);
            siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1");
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.MultipleRatingByUser, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }