Esempio n. 1
0
        public void GetSiteTest_SiteNameExist_ReturnsValidObject()
        {
            var cache = mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("fetchsitedata")).Return(GetSiteListMockReader());
            creator.Stub(x => x.CreateDnaDataReader("getreviewforums")).Return(GetReviewForumsMockReader());
            creator.Stub(x => x.CreateDnaDataReader("getkeyarticlelist")).Return(GetKeyArticleListMockReader());
            creator.Stub(x => x.CreateDnaDataReader("getsitetopicsopenclosetimes")).Return(GetSiteOpenCloseTimesMockReader());
            creator.Stub(x => x.CreateDnaDataReader("GetTopicDetails")).Return(GetSiteTopicsMockReader());

            IDnaDataReader readerOptions = mocks.DynamicMock<IDnaDataReader>();
            readerOptions.Stub(x => x.Read()).Return(false);
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(readerOptions);
            mocks.ReplayAll();

            SiteList target = new SiteList(creator, diag, cache, null, null);
            ISite site = target.GetSite("h2g2");
            Assert.IsNotNull(site);
            Assert.AreEqual(1, site.SiteID);
            diag.AssertWasNotCalled(x => x.WriteWarningToLog("SiteList", "A Site doesn't exist with that site id. "));
        }
Esempio n. 2
0
        public void GetSiteTest_SiteNameNotExist_ReturnsNull()
        {
            var cache = mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetInt32("SiteID")).Return(1);
            reader.Stub(x => x["URLName"]).Return("h2g2");
            reader.Stub(x => x["config"]).Return("");
            reader.Stub(x => x.GetString("config")).Return("");
            reader.Stub(x => x.Exists("UseIdentitySignIn")).Return(true);
            reader.Stub(x => x.GetTinyIntAsInt("UseIdentitySignIn")).Return(1);
            reader.Stub(x => x.Exists("IsKidsSite")).Return(true);
            reader.Stub(x => x.GetTinyIntAsInt("IsKidsSite")).Return(1);
            reader.Stub(x => x.GetStringNullAsEmpty("")).Constraints(Is.Anything()).Return("");
            
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("fetchsitedata")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("getreviewforums")).Return(GetReviewForumsMockReader());
            creator.Stub(x => x.CreateDnaDataReader("getkeyarticlelist")).Return(GetKeyArticleListMockReader());
            creator.Stub(x => x.CreateDnaDataReader("getsitetopicsopenclosetimes")).Return(GetSiteOpenCloseTimesMockReader());
            creator.Stub(x => x.CreateDnaDataReader("GetTopicDetails")).Return(GetSiteTopicsMockReader()); 
            
            IDnaDataReader readerOptions = mocks.DynamicMock<IDnaDataReader>();
            readerOptions.Stub(x => x.Read()).Return(false);
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(readerOptions);

            mocks.ReplayAll();

            SiteList target = new SiteList(creator, diag, cache, null, null);
            Assert.IsNull(target.GetSite(""));
            diag.AssertWasCalled(x => x.WriteWarningToLog("SiteList", "A Site doesn't exist with that site name. "));
        }