public void TestRepeatedWritesDifferentProperties() { RemoveSettings(); var configuration = SystemConfigurationHelper.GetExeConfiguration(); var expectedValue1 = CreateSettingValue(LocalMixedScopeSettings.PropertyApp1, SettingValue.Current); var expectedValue2 = CreateSettingValue(LocalMixedScopeSettings.PropertyApp2, SettingValue.Current); var values = new Dictionary <string, string>(); values[LocalMixedScopeSettings.PropertyApp1] = expectedValue1; SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(configuration, _settingsClass); Assert.AreEqual(1, values.Count); Assert.AreEqual(expectedValue1, values[LocalMixedScopeSettings.PropertyApp1]); values.Clear(); values[LocalMixedScopeSettings.PropertyApp2] = expectedValue2; SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(configuration, _settingsClass); Assert.AreEqual(2, values.Count); Assert.AreEqual(expectedValue1, values[LocalMixedScopeSettings.PropertyApp1]); Assert.AreEqual(expectedValue2, values[LocalMixedScopeSettings.PropertyApp2]); }
public void TestReadWriteValues_Xml() { Type settingsClass = typeof(LocalXmlSettings); SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); try { var values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(0, values.Count); values = new Dictionary <string, string>(); values[LocalXmlSettings.PropertyUser] = LocalXmlSettings.DefaultValueUser; values[LocalXmlSettings.PropertyApp] = LocalXmlSettings.DefaultValueApp; SystemConfigurationHelper.PutSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(1, values.Count); LocalXmlSettings settings = (LocalXmlSettings)ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); Assert.IsNull(ApplicationSettingsExtensions.GetSharedPropertyValue(settings, LocalXmlSettings.PropertyUser)); XmlDocument defaultDoc = new XmlDocument(); defaultDoc.LoadXml(LocalXmlSettings.DefaultValueApp); Assert.AreEqual(defaultDoc.DocumentElement.OuterXml, settings.App.DocumentElement.OuterXml); } finally { SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); } }
private void ValidateValuesInConfig(MigrationScope migrationScope, SettingValue settingValue) { var configuration = GetExeConfiguration(); var values = SystemConfigurationHelper.GetSettingsValues(configuration, _settingsClass); ValidateValues(values, migrationScope, settingValue); }
public void TestWriteEmptyString_Xml() { Type settingsClass = typeof(LocalXmlSettings); SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); try { var values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(0, values.Count); values = new Dictionary <string, string>(); values[LocalXmlSettings.PropertyApp] = ""; SystemConfigurationHelper.PutSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), settingsClass); Assert.AreEqual(1, values.Count); Assert.AreEqual("", values[LocalXmlSettings.PropertyApp]); //For xml values, empty string means "default". LocalXmlSettings settings = (LocalXmlSettings)ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); XmlDocument defaultDoc = new XmlDocument(); defaultDoc.LoadXml(LocalXmlSettings.DefaultValueApp); Assert.AreEqual(defaultDoc.DocumentElement.OuterXml, settings.App.DocumentElement.OuterXml); } finally { SystemConfigurationHelper.RemoveSettingsValues(SystemConfigurationHelper.GetExeConfiguration(), settingsClass); } }
public void TestWriteNull_String() { RemoveSettings(); var configuration = SystemConfigurationHelper.GetExeConfiguration(); var values = new Dictionary <string, string>(); values[LocalMixedScopeSettings.PropertyApp1] = "Test1"; values[LocalMixedScopeSettings.PropertyApp2] = "Test2"; SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), _settingsClass); Assert.AreEqual(2, values.Count); Assert.AreEqual("Test1", values[LocalMixedScopeSettings.PropertyApp1]); Assert.AreEqual("Test2", values[LocalMixedScopeSettings.PropertyApp2]); values = new Dictionary <string, string>(); values[LocalMixedScopeSettings.PropertyApp1] = null; values[LocalMixedScopeSettings.PropertyApp2] = null; //writing null essentially means to reset it to the default, which is equivalent to removing it. SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), _settingsClass); Assert.AreEqual(0, values.Count); var settings = (LocalMixedScopeSettings)ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); Assert.AreEqual(LocalMixedScopeSettings.PropertyApp1, settings.App1); Assert.AreEqual(LocalMixedScopeSettings.PropertyApp2, settings.App2); }
public void TestWriteEmptyString_String() { RemoveSettings(); var configuration = SystemConfigurationHelper.GetExeConfiguration(); var values = new Dictionary <string, string>(); values[LocalMixedScopeSettings.PropertyApp1] = "Test1"; values[LocalMixedScopeSettings.PropertyApp2] = "Test2"; SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), _settingsClass); Assert.AreEqual(2, values.Count); Assert.AreEqual("Test1", values[LocalMixedScopeSettings.PropertyApp1]); Assert.AreEqual("Test2", values[LocalMixedScopeSettings.PropertyApp2]); values = new Dictionary <string, string>(); values[LocalMixedScopeSettings.PropertyApp1] = ""; values[LocalMixedScopeSettings.PropertyApp2] = ""; SystemConfigurationHelper.PutSettingsValues(configuration, _settingsClass, values); values = SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), _settingsClass); Assert.AreEqual(2, values.Count); Assert.AreEqual("", values[LocalMixedScopeSettings.PropertyApp1]); Assert.AreEqual("", values[LocalMixedScopeSettings.PropertyApp2]); //For string values, empty string means empty string. var settings = (LocalMixedScopeSettings)ApplicationSettingsHelper.GetSettingsClassInstance(_settingsClass); Assert.AreEqual("", settings.App1); Assert.AreEqual("", settings.App2); }
/// <summary> /// Loads the settings values (both application and user scoped) for a given settings class. Only the shared profile /// is supported (application settings + default user settings). /// </summary> /// <param name="group">the settings class for which to retrieve the defaults</param> /// <param name="user">must be null or ""</param> /// <param name="instanceKey">must be null or ""</param> /// <returns>returns only those values that are different from the property defaults</returns> /// <exception cref="NotSupportedException">will be thrown if the user or instance key is specified</exception> public Dictionary <string, string> GetSettingsValues(SettingsGroupDescriptor group, string user, string instanceKey) { CheckUser(user); CheckInstanceKey(instanceKey); Type type = Type.GetType(group.AssemblyQualifiedTypeName, true); return(SystemConfigurationHelper.GetSettingsValues(_configuration, type)); }
private void ValidateLocalMixedScopeSettingsValuesInConfig(System.Configuration.Configuration configuration, SettingValue settingValue) { Type settingsClass = typeof(LocalMixedScopeSettings); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); settings.Reload(); SettingsProperty property = settings.Properties[LocalMixedScopeSettings.PropertyApp1]; string expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); var values = SystemConfigurationHelper.GetSettingsValues(configuration, settingsClass, SettingScope.Application); Assert.AreEqual(2, values.Count); property = settings.Properties[LocalMixedScopeSettings.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); values = SystemConfigurationHelper.GetSettingsValues(configuration, settingsClass, SettingScope.User); Assert.AreEqual(2, values.Count); property = settings.Properties[LocalMixedScopeSettings.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[LocalMixedScopeSettings.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, settingValue); actual = values[property.Name]; Assert.AreEqual(expected, actual); }
public void TestReadSettingsValues_NoneExist() { RemoveSettings(); Assert.AreEqual(0, SystemConfigurationHelper.GetSettingsValues(GetExeConfiguration(), _settingsClass).Count); }