示例#1
0
        public void LoadMultiple02()
        {
            string content1 =
                @"
# [Category] SQL
# [Description] Database connection string
# [Editor] ConnectionStringEditor
settings$c1 <- 'DSN'
";
            string content2 =
                @"
# [Category] SQL
# [Description] Database connection string
# [Editor] ConnectionStringEditor
c1 <- 'DSN'
";

            foreach (var content in new string[] { content1, content2 })
            {
                using (var sr = new StreamReader(ToStream(content))) {
                    using (var css = new ConfigurationSettingsReader(sr)) {
                        var settings = css.LoadSettings();
                        settings.Should().HaveCount(1);

                        settings[0].Name.Should().Be("c1");
                        settings[0].Value.Should().Be("DSN");
                        settings[0].ValueType.Should().Be(ConfigurationSettingValueType.String);
                        settings[0].Category.Should().Be("SQL");
                        settings[0].Description.Should().Be("Database connection string");
                        settings[0].EditorType.Should().Be("ConnectionStringEditor");
                    }
                }
            }
        }
        public void Write01()
        {
            string content =
                @"# [Category] SQL
# [Description] Database connection string
# [Editor] ConnectionString
c1 <- 'DSN'

x <- 1
";
            IReadOnlyList <IConfigurationSetting> settings;
            var sr = new StreamReader(ToStream(content));

            using (var csr = new ConfigurationSettingsReader(sr)) {
                settings = csr.LoadSettings();
            }

            var stream = new MemoryStream();

            using (var csw = new ConfigurationSettingsWriter(new StreamWriter(stream))) {
                csw.SaveSettings(settings);

                stream.Seek(0, SeekOrigin.Begin);
                using (var r = new StreamReader(stream)) {
                    var s = r.ReadToEnd();
                    s.Should().StartWith(Resources.SettingsFileHeader);
                    s.Should().Contain(content);
                }
            }
        }
示例#3
0
        private void LoadAndWrite(string originalContent, string expectedContent)
        {
            IReadOnlyList <IConfigurationSetting> settings;
            var sr = new StreamReader(ToStream(originalContent));

            using (var csr = new ConfigurationSettingsReader(sr)) {
                settings = csr.LoadSettings();
            }

            var stream = new MemoryStream();

            using (var csw = new ConfigurationSettingsWriter(new StreamWriter(stream))) {
                csw.SaveSettings(settings);

                stream.Seek(0, SeekOrigin.Begin);
                using (var r = new StreamReader(stream)) {
                    var s = r.ReadToEnd();
                    s.Should().StartWith(Resources.SettingsFileHeader);
                    s.Should().Contain(expectedContent);
                }
            }
        }