public void CreateFromDatabase_ReadIsFalse_ReturnsEmptyObject() { 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(false); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader); mocks.ReplayAll(); SiteOptionList target = new SiteOptionList(); target.CreateFromDatabase(creator, diag); Assert.AreEqual(0, target.GetAllOptions().Count); Assert.AreEqual(0, target.GetAllOptionsDictionary().Count); }
public void CreateFromDatabase_AddsBoolOption_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 = GetBoolSiteOptionMockReader(); IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>(); creator.Stub(x => x.CreateDnaDataReader("getallsiteoptions")).Return(reader); mocks.ReplayAll(); SiteOptionList target = new SiteOptionList(); target.CreateFromDatabase(creator, diag); Assert.AreEqual(2, target.GetAllOptions().Count); Assert.AreEqual(2, target.GetAllOptionsDictionary().Count); Assert.AreEqual(SiteOption.SiteOptionType.Bool, target.GetAllOptions()[0].OptionType); Assert.IsTrue(target.GetAllOptions()[0].GetValueBool()); Assert.AreEqual(true, target.GetValueBool(1, "test", "test")); }
public void GetSiteOptionListForSite_DefaultOption_ReturnsCorrectList() { 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.Bool); reader.Stub(x => x.GetString("Value")).Return("0"); 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.Bool, target.GetAllOptions()[0].OptionType); List<SiteOption> actual = target.GetSiteOptionListForSite(1); Assert.AreEqual(1, actual.Count); Assert.AreEqual("test", actual[0].Name); Assert.IsTrue(actual[0].IsGlobal); }
public void SetValueBool_ChangesOption_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.Bool); 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(1); 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.Bool, target.GetAllOptions()[0].OptionType); target.SetValueBool(1, "test", "test", false, creator, diag); Assert.AreEqual(false, target.GetValueBool(1, "test", "test")); }