Exemple #1
0
        public void CascadeSettingsContainer_Constructor_CreatesEmptySources()
        {
            CascadeSettingsContainer container = new CascadeSettingsContainer();

            Assert.NotNull(container.Sources);
            Assert.Equal(0, container.Sources.Count);
            Assert.Equal(SettingScopeEnum.User, container.EffectiveScope);
        }
        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);
        }
Exemple #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);
        }
        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);
        }
Exemple #6
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));
        }
Exemple #7
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
        }
Exemple #8
0
        public void CascadeSettingsContainer_GetEffectiveValue_ReturnsNullIfNoSources()
        {
            CascadeSettingsContainer container = new CascadeSettingsContainer();

            Assert.Null(container.GetEffectiveValue("somekey"));
        }