Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }