public void CascadeSettingsContainer_GetEffectiveValue_EvaluatesSettingScope() { CascadeSettingsContainer container = new CascadeSettingsContainer(); var sourceA = container.AddSource(new CustomDataSource()); var sourceB = container.AddSource(new CustomDataSource()); sourceA.Data["key1"] = "value1A"; sourceB.Data["key1"] = "value2A"; sourceA.Scope = SettingScopeEnum.Application; sourceB.Scope = SettingScopeEnum.User; Assert.Equal("value2A", container.GetEffectiveValue("key1")); Assert.Equal("value2A", container.GetEffectiveValue("key1", SettingScopeEnum.User)); Assert.Equal("value1A", container.GetEffectiveValue("key1", SettingScopeEnum.Application)); }
public void CascadeSettingsContainer_GetEffectiveValue_ReturnsLastValueInSourcesOrder() { CascadeSettingsContainer container = new CascadeSettingsContainer(); var sourceA = container.AddSource(new CustomDataSource()); var sourceB = container.AddSource(new CustomDataSource()); sourceA.Data["key1"] = "value1A"; sourceB.Data["key1"] = "value1B"; sourceA.Data["key2"] = "value2A"; sourceB.Data["key3"] = "value3B"; Assert.Equal("value1B", container.GetEffectiveValue("key1")); Assert.Equal("value2A", container.GetEffectiveValue("key2")); Assert.Equal("value3B", container.GetEffectiveValue("key3")); Assert.Null(container.GetEffectiveValue("key4")); // unknown key }
public void CascadeSettingsContainer_AddSource_AddsToSourcesAndReturnsInstance() { var source = new CustomDataSource(); var container = new CascadeSettingsContainer(); var source1 = container.AddSource(source); Assert.True(container.Sources.Contains(source)); Assert.Equal(source, source1); }
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); }