public void IntegerSettingDefinition_ConvertFromString_ReturnsInteger() { var definition = new IntegerSettingDefinition("test", "desc", 0); Assert.Equal(0, definition.ConvertFromString("0")); Assert.Equal(-101, definition.ConvertFromString("-101")); Assert.Equal(101, definition.ConvertFromString("101")); }
public void IntegerSettingDefinition_Constructor_PopulatesProperties() { var definition = new IntegerSettingDefinition("test", "desc", 100, SettingScopeEnum.Application); Assert.Equal("test", definition.Name); Assert.Equal("desc", definition.Description); Assert.Equal("100", definition.DefaultValue); Assert.Equal(SettingScopeEnum.Application, definition.Scope); }
public void BaseSettingValue_Constructor_TakesContainerAndDefinition() { var definition = new IntegerSettingDefinition("test", "desc", 0); var container = new CascadeSettingsContainer(); var settingValue = new SettingValue <int>(container, definition); Assert.Equal(container, settingValue.SettingsContainer); Assert.Equal(definition, settingValue.Definition); }
public void BaseSettingValue_Value_RaisesExceptionIfNotConvertible() { var definition = new IntegerSettingDefinition("key1", "desc", 0); var source = new CustomDataSource(); var container = new CascadeSettingsContainer(); container.AddSource(source); var settingValue = new SettingValue <int>(container, definition); source.Data["key1"] = "text"; Assert.Throws <InvalidOperationException>(() => settingValue.Value); }
public void BaseSettingValue_Value_ReturnsEffectiveValue() { var definition = new IntegerSettingDefinition("key1", "desc", 0); var source = new CustomDataSource(); var container = new CascadeSettingsContainer(); container.AddSource(source); var settingValue = new SettingValue <int>(container, definition); source.Data["key1"] = "100"; Assert.Equal(100, settingValue.Value); }
public void DefaultSettingsSource_GetValue_ReturnsDefaultValues() { var bool1Def = new BoolSettingDefinition("key1", "desc", true); var bool2Def = new BoolSettingDefinition("key2", "desc", false); var int1Def = new IntegerSettingDefinition("key3", "desc", 1); var int2Def = new IntegerSettingDefinition("key4", "desc", 0); var source = new DefaultSettingsSource(new ISettingDefinition[] { bool1Def, bool2Def, int1Def, int2Def }); Assert.AreEqual("True", source.GetValue("key1")); Assert.AreEqual("False", source.GetValue("key2")); Assert.AreEqual("1", source.GetValue("key3")); Assert.AreEqual("0", source.GetValue("key4")); }
public void DefaultSettingsSource_Constructor_CreateDefinitionDictionary() { var bool1Def = new BoolSettingDefinition("key1", "desc", true); var bool2Def = new BoolSettingDefinition("key2", "desc", false); var int1Def = new IntegerSettingDefinition("key3", "desc", 1); var int2Def = new IntegerSettingDefinition("key4", "desc", 0); var source = new DefaultSettingsSource(new ISettingDefinition[] { bool1Def, bool2Def, int1Def, int2Def }); Assert.IsNotNull(source.SettingDefinitions); Assert.AreEqual(4, source.SettingDefinitions.Count); Assert.AreEqual(bool1Def, source.SettingDefinitions["key1"]); Assert.AreEqual(bool2Def, source.SettingDefinitions["key2"]); Assert.AreEqual(int1Def, source.SettingDefinitions["key3"]); Assert.AreEqual(int2Def, source.SettingDefinitions["key4"]); }