예제 #1
0
        public void SetValueInt_NoOption_ThrowsException()
        {
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Creating list from database")).Repeat.Once();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Created list from database")).Repeat.Once();


            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("setsiteoption")).Return(reader);

            

            mocks.ReplayAll();

            SiteOptionList target = new SiteOptionList();
            try
            {
                target.SetValueInt(1, "test", "test", 1, creator, diag);
            }
            catch (SiteOptionNotFoundException)
            {
            }
        }
예제 #2
0
        public void SetValueInt_ChangesDefaultOption_ReturnsValidObject()
        {
            IDnaDiagnostics diag = mocks.DynamicMock<IDnaDiagnostics>();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Creating list from database")).Repeat.Once();
            diag.Stub(x => x.WriteTimedEventToLog("SiteOptionList", "Created list from database")).Repeat.Once();


            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetInt32("Type")).Return((int)SiteOption.SiteOptionType.Int);
            reader.Stub(x => x.GetString("Value")).Return("1");
            reader.Stub(x => x.GetString("Section")).Return("test");
            reader.Stub(x => x.GetString("Name")).Return("test");
            reader.Stub(x => x.GetInt32("SiteID")).Return(0);
            reader.Stub(x => x.GetString("description")).Return("test");


            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("setsiteoption")).Return(reader);

            

            mocks.ReplayAll();

            SiteOptionList target = new SiteOptionList();
            target.CreateFromDatabase(creator, diag);
            Assert.AreEqual(1, target.GetAllOptions().Count);
            Assert.AreEqual(1, target.GetAllOptionsDictionary().Count);
            Assert.AreEqual(SiteOption.SiteOptionType.Int, target.GetAllOptions()[0].OptionType);

            target.SetValueInt(1, "test", "test", 2, creator, diag);
            Assert.AreEqual(2, target.GetValueInt(1, "test", "test"));
        }