public void RatingsForumReadByUid_FromDbCorrectInput_ReturnsValidList() { var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var readerComments = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); string siteName = "h2g2"; string uid = ""; cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything()); site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod); 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(); reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName); readerComments.Stub(x => x.HasRows).Return(true); readerComments.Stub(x => x.Read()).Return(true).Repeat.Once(); readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1); readerCreator.Stub(x => x.CreateDnaDataReader("RatingForumreadbyuid")).Return(reader); readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumid")).Return(readerComments); 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); RatingForum forum = reviews.RatingForumReadByUID(uid, site); Assert.IsNotNull(forum); Assert.AreEqual(1, forum.ratingsList.TotalCount); Assert.AreEqual(1, forum.ratingsList.ratings.Count); readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("RatingForumreadbyuid")); }
public void RatingsForumReadByUid_CacheValid_ReturnsValidList() { DateTime lastUpdate = DateTime.Now.AddDays(1); string uid = "testUid"; var validForum = new RatingForum() {Id = uid}; var reviews = new Reviews(null, null, null, null); var siteList = mocks.DynamicMock<ISiteList>(); var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>(); var site = mocks.DynamicMock<ISite>(); var reader = mocks.DynamicMock<IDnaDataReader>(); var readerComments = mocks.DynamicMock<IDnaDataReader>(); var readerLastUpdate = mocks.DynamicMock<IDnaDataReader>(); var cacheManager = mocks.DynamicMock<ICacheManager>(); string siteName = "h2g2"; string cacheKey = reviews.RatingForumCacheKey(uid, 0); cacheManager.Stub(x => x.GetData(cacheKey + "|LASTUPDATED")).Return(lastUpdate); cacheManager.Stub(x => x.GetData(cacheKey)).Return(validForum); site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod); 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(); reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName); readerComments.Stub(x => x.HasRows).Return(true); readerComments.Stub(x => x.Read()).Return(true).Repeat.Once(); readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1); readerLastUpdate.Stub(x => x.HasRows).Return(true); readerLastUpdate.Stub(x => x.Read()).Return(true).Repeat.Once(); readerLastUpdate.Stub(x => x.GetDateTime("lastupdated")).Return(lastUpdate); readerCreator.Stub(x => x.CreateDnaDataReader("RatingForumreadbyuid")).Return(reader); readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumid")).Return(readerComments); readerCreator.Stub(x => x.CreateDnaDataReader("CommentforumGetLastUpdate")).Return(readerLastUpdate); siteList.Stub(x => x.GetSite(siteName)).Return(site); mocks.ReplayAll(); reviews = new Reviews(null, readerCreator, cacheManager, siteList); RatingForum forum = reviews.RatingForumReadByUID(uid, site); Assert.IsNotNull(forum); Assert.AreEqual(uid, forum.Id); readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("RatingForumreadbyuid")); readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingsreadbyforumid")); }