public void EmptySectionValueFieldReturnsNull() { UpdateSection("TestSection", typeof(DummySection).FullName, null); object configSection = SqlConfigurationManager.GetSection("TestSection", data); Assert.IsNull(configSection); }
public void SaveTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); //Assert that the database now has one record Assert.IsTrue(GetNumberofConfigSections() == 1); }
public void SaveAndGetTestConfiguration() { DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); DummySection configSection2 = SqlConfigurationManager.GetSection("TestSection", data) as DummySection; Assert.AreEqual(configSection2.Value, configSection.Value); }
public void RefreshConfiguration() { string sectionName = "TestSection"; DummySection configSection = new DummySection(); configSection.Value = 20; SqlConfigurationManager.SaveSection("TestSection", configSection, data); DateTime lastModDate1 = GetLastModDate(sectionName); System.Threading.Thread.Sleep(1000); SqlConfigurationManager.RefreshSection(sectionName, data); DateTime lastModDate2 = GetLastModDate(sectionName); Assert.IsFalse(lastModDate2.Equals(lastModDate1)); }
public void Setup() { string connectString = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true"; string getStoredProc = @"EntLib_GetConfig"; string setStoredProc = @"EntLib_SetConfig"; string refreshStoredProc = @"UpdateSectionDate"; string removeStoredProc = @"EntLib_RemoveSection"; this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc); SqlConfigurationSource.ResetImplementation(data, false); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); DummySection rwSection; rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 10; SqlConfigurationSourceImplementation configSourceImpl = new SqlConfigurationSourceImplementation(this.data, false); configSourceImpl.SaveSection(rwSection.Name, rwSection); rwConfiguration.Sections.Remove(externalSection); rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection()); rwSection.Name = externalSection; rwSection.Value = 20; configSourceImpl.SaveSection(rwSection.Name, rwSection); rwConfiguration.Sections.Remove(localSection2); rwConfiguration.Sections.Add(localSection2, rwSection = new DummySection()); rwSection.Name = localSection2; rwSection.Value = 30; configSourceImpl.SaveSection(rwSection.Name, rwSection); rwConfiguration.Save(); SqlConfigurationManager.RefreshSection(localSection, this.data); SqlConfigurationManager.RefreshSection(localSection2, this.data); SqlConfigurationManager.RefreshSection(externalSection, this.data); ConfigurationChangeSqlWatcher.ResetDefaultPollDelay(); updatedSectionsTally = new Dictionary <string, int>(0); }
public void TestInitialize() { string connectString = @"server=(local)\SQLExpress;database=Northwind;Integrated Security=true"; string getStoredProc = @"EntLib_GetConfig"; string setStoredProc = @"EntLib_SetConfig"; string removeStoredProc = @"EntLib_RemoveSection"; string refreshStoredProc = @"UpdateSectionDate"; this.data = new SqlConfigurationData(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc); configSystem = new SqlConfigurationSystem(connectString, getStoredProc, setStoredProc, refreshStoredProc, removeStoredProc); if (SqlConfigurationManager.InitializationState == SqlConfigurationManager.InitState.NotStarted) { SqlConfigurationManager.SetConfigurationSystem(configSystem, true); } ClearConfigs(); }
public void DifferentSqlConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); SqlConfigurationSource.ResetImplementation(data1, true); SystemConfigurationSource.ResetImplementation(true); bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); DummySection sysDummySerializableSection = systemSource.GetSection(localSection) as DummySection; SqlConfigurationSource otherSource = new SqlConfigurationSource( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); SqlConfigurationParameter parameter = new SqlConfigurationParameter( data1.ConnectionString, data1.GetStoredProcedure, data1.SetStoredProcedure, data1.RefreshStoredProcedure, data1.RemoveStoredProcedure); otherSource.Add(parameter, localSection, sysDummySerializableSection); DummySection otherDummySerializableSection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySerializableSection != null); Assert.IsTrue(otherDummySerializableSection != null); systemSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMachineConfiguration(); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = data1.ConnectionString; SqlConfigurationManager.SaveSection(rwSection.Name, rwSection, data1); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); }
public void InvalidSectionNameReturnsNull() { DummySection configSection2 = SqlConfigurationManager.GetSection("BadSection", data) as DummySection; Assert.IsNull(configSection2); }