public void IsLike_WithOrWithoutKey()
        {
            var path = SettingPath.Parse("foo.bar");

            path.IsLike(SettingPath.Parse("foo.bar")).Verify().IsTrue();
            path.IsLike(SettingPath.Parse("foo.bar[baz]")).Verify().IsTrue();
            path.IsLike(SettingPath.Parse("foo.baz")).Verify().IsFalse();
        }
Exemple #2
0
        public void WeakId_NameWithKey_NameOnly()
        {
            var setting = new Setting
            {
                Name  = SettingPath.Parse("Setting1[0]"),
                Value = "Setting1-Value"
            };

            setting.WeakId.Verify().IsEqual("[Setting1]");
        }
Exemple #3
0
        public void WeakId_NameOnly_NameOnly()
        {
            var setting = new Setting
            {
                Name  = SettingPath.Parse("Setting1"),
                Value = "Value1"
            };

            setting.WeakId.Verify().IsEqual("[Setting1]");
        }
        private void DeleteSettingGroup(IGrouping <Setting, Setting> settingGroup, AppSettingsSection appSettings)
        {
            var settingWeakPath = settingGroup.Key.Name;
            var keys            = appSettings.Settings.AllKeys.Where(key => SettingPath.Parse(key).IsLike(settingWeakPath));

            foreach (var key in keys)
            {
                appSettings.Settings.Remove(key);
            }
        }
Exemple #5
0
        public void GetSettings_NameDoesNotExist_EmptyResult()
        {
            var store = new MemoryStore();

            var settings = store.ReadSettings(new Setting {
                Name = SettingPath.Parse("baz")
            }).ToList();

            settings.Count().Verify().IsEqual(0);
        }
        private void DeleteObsoleteSettings(IGrouping <Setting, Setting> settings)
        {
            var obsoleteNames =
                _connectionStringsSection
                .ConnectionStrings
                .Cast <ConnectionStringSettings>()
                .Where(x => SettingPath.Parse(x.Name).IsLike(settings.Key.Name))
                .ToList();

            obsoleteNames.ForEach(x => _connectionStringsSection.ConnectionStrings.Remove(x.Name));
        }
Exemple #7
0
        public void WeakId_WithTags_NameAndTags()
        {
            var setting = new Setting
            {
                Name  = SettingPath.Parse("Setting1"),
                Value = "Value1",
                Tags  = { { "Tag2", "TagValue2" }, { "Tag1", "TagValue1" } }
            };

            setting.WeakId.Verify().IsEqual("[Setting1, TagValue1, TagValue2]");
        }
        public override IEnumerable <Setting> ReadSettings(Setting setting)
        {
            var exeConfig = OpenExeConfiguration();
            var keys      = exeConfig.AppSettings.Settings.AllKeys.Like(setting);

            foreach (var key in keys)
            {
                yield return(new Setting
                {
                    Name = SettingPath.Parse(key),
                    Value = exeConfig.AppSettings.Settings[key].Value
                });
            }
        }
        public void ctor_CreateFromStringWithKey()
        {
            var path = SettingPath.Parse("foo.bar[baz]");

            path.Count.Verify().IsEqual(2);

            path.Namespace.Verify().IsEqual("foo");
            path.WeakName.Verify().IsEqual("bar");
            path.StrongName.Verify().IsEqual("bar[baz]");
            path.Key.Verify().IsEqual("baz");

            path.WeakFullName.Verify().IsEqual("foo.bar");
            path.StrongFullName.Verify().IsEqual("foo.bar[baz]");
        }
Exemple #10
0
        public void GetSettings_NameExists_OneSetting()
        {
            var store = new MemoryStore
            {
                { "foo", "bar" },
                { "baz", "qux" }
            };

            var settings = store.ReadSettings(new Setting {
                Name = SettingPath.Parse("baz")
            }).ToList();

            settings.Count.Verify().IsEqual(1);
            settings.First().Value.ToString().Verify().IsEqual("qux");
        }
Exemple #11
0
        public void Equals_SameSettingsWithoutTags_True()
        {
            var s1 = new Setting
            {
                Name  = SettingPath.Parse("S1"),
                Value = "V1"
            };
            var s2 = new Setting
            {
                Name  = SettingPath.Parse("S1"),
                Value = "V2"
            };
            var comparer = new WeakSettingComparer();

            comparer.Equals(s1, s2).Verify().IsTrue();
        }
Exemple #12
0
        public void GetSettings_NameAndKeyExist_TwoSettings()
        {
            var store = new MemoryStore
            {
                { "foo[a]", "bar" },
                { "foo[b]", "qux" },
                { "bar[b]", "qux" }
            };

            var settings = store.ReadSettings(new Setting {
                Name = SettingPath.Parse("foo")
            }).ToList();

            settings.Count().Verify().IsEqual(2);
            settings[0].Value.ToString().Verify().IsEqual("bar");
            settings[1].Value.ToString().Verify().IsEqual("qux");
        }
        public override IEnumerable <Setting> ReadSettings(Setting setting)
        {
            var connectionStringSettings =
                _connectionStringsSection
                .ConnectionStrings
                .Cast <ConnectionStringSettings>()
                .Like(x => x.Name, setting);

            foreach (var x in connectionStringSettings)
            {
                yield return(new Setting
                {
                    Name = SettingPath.Parse(x.Name),
                    Value = x.ConnectionString
                });
            }
        }
Exemple #14
0
        public void Equals_SameSettingsWithDifferentTags_False()
        {
            var s1 = new Setting
            {
                Name  = SettingPath.Parse("S1"),
                Value = "V1",
                Tags  = { { "Tag2", "T2" }, { "Tag1", "T1" } }
            };
            var s2 = new Setting
            {
                Name  = SettingPath.Parse("S1"),
                Value = "V2",
                Tags  = { { "Tag3", "T3" }, { "Tag1", "T1" } }
            };
            var comparer = new WeakSettingComparer();

            comparer.Equals(s1, s2).Verify().IsFalse();
        }
        public override IEnumerable <Setting> ReadSettings(Setting setting)
        {
            using (var connection = OpenConnection())
                using (var command = _settingCommandFactory.CreateSelectCommand(connection, setting))
                {
                    command.Prepare();

                    using (var settingReader = command.ExecuteReader())
                    {
                        while (settingReader.Read())
                        {
                            var result = new Setting
                            {
                                Name  = SettingPath.Parse((string)settingReader[nameof(Setting.Name)]),
                                Value = settingReader[nameof(Setting.Value)],
                                Tags  = new TagCollection(setting.Tags.ToDictionary(tag => tag.Key, tag => settingReader[tag.Key]))
                            };
                            yield return(result);
                        }
                    }
                }
        }
Exemple #16
0
        private static void ResetData()
        {
            var baseKey = Microsoft.Win32.Registry.CurrentUser;

            using (var subKey = baseKey.OpenSubKey(@"Software\SmartConfig", writable: true))
            {
                if (subKey != null && subKey.GetSubKeyNames().Contains("Test", StringComparer.OrdinalIgnoreCase))
                {
                    subKey.DeleteSubKeyTree("Test");
                }
            }

            foreach (var testSetting in TestSettingFactory.CreateTestSettings1())
            {
                var settingPath  = SettingPath.Parse(testSetting.Name);
                var registryPath = new RegistryPath(settingPath);
                var subKeyName   = Path.Combine(@"Software\SmartConfig\Test", registryPath.Namespace);
                using (var subKey = baseKey.CreateSubKey(subKeyName, writable: true))
                {
                    subKey.SetValue(registryPath.StrongName, testSetting.Value);
                }
            }
        }
        public override IEnumerable <Setting> ReadSettings(Setting setting)
        {
            var registryPath = new RegistryPath(setting.Name);

            var subKeyName = Path.Combine(_baseSubKeyName, registryPath.Namespace);

            using (
                var subKey = _baseKey.OpenSubKey(subKeyName, false) ??
                             throw new OpenOrCreateSubKeyException(_baseKey.Name, _baseSubKeyName, subKeyName)
                )
            {
                var valueNames = subKey.GetValueNames().Where(x => RegistryPath.Parse(x).IsLike(registryPath));

                foreach (var valueName in valueNames)
                {
                    yield return(new Setting
                    {
                        Name = SettingPath.Parse(valueName),
                        Value = subKey.GetValue(valueName)
                    });
                }
            }
        }
Exemple #18
0
 public static IEnumerable <T> Like <T>(this IEnumerable <T> values, Func <T, string> getName, Setting setting)
 {
     return(values.Where(x => SettingPath.Parse(getName(x)).IsLike(setting.Name)));
 }
Exemple #19
0
 public static IEnumerable <string> Like(this IEnumerable <string> names, Setting setting)
 {
     return(names.Where(k => SettingPath.Parse(k).IsLike(setting.Name)));
 }
 public void Equals_DifferentStrongPaths_False()
 {
     SettingPath.Parse("Foo[0]").IsLike(SettingPath.Parse("Bar[2]")).Verify().IsFalse();
 }
 public void Equals_StrongPathAndStrongPath_True()
 {
     SettingPath.Parse("Foo[0]").IsLike(SettingPath.Parse("Foo[2]")).Verify().IsTrue();
 }
 public void Add(string name, object value) => Data.Add(new Setting
 {
     Name  = SettingPath.Parse(name),
     Value = value
 });
        public static RegistryPath Parse(string value)
        {
            var settingUrn = SettingPath.Parse(value, DefaultDelimiter);

            return(new RegistryPath(settingUrn));
        }