Пример #1
0
        protected override void ProcessRecord()
        {
            try
            {
                if (_settingsReaders.Count > 0)
                {
                    var settingsLines = new List <string>();

                    foreach (var reader in _settingsReaders)
                    {
                        settingsLines.AddRange(reader.ReadSettings());
                    }
                    var settings = _parser.Parse(settingsLines, overrideSettingsReader.ReadSettings(), Section, Delimiter);

                    this.WriteObject(settings);
                }
            }
            catch (Exception e)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        e,
                        "ParsedSettings",
                        ErrorCategory.NotSpecified,
                        this)
                    );
            }
        }
        public void Reader_ReadSettings_NonEmptyTable_ReturnsCorrectlyFormattedLines()
        {
            var settings = new Hashtable
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "key3", "value3" },
            };
            var reader = new OverrideSettingsReader(settings, "TestSection");

            var readLines = reader.ReadSettings().ToList();

            Assert.AreEqual(4, readLines.Count);
            Assert.AreEqual("TestSection", readLines[0]);
            Assert.Contains("\tkey1\tvalue1", readLines);
            Assert.Contains("\tkey2\tvalue2", readLines);
            Assert.Contains("\tkey3\tvalue3", readLines);
        }
        public void Reader_ReadSettings_NullTable_ReturnsZeroLines()
        {
            var reader = new OverrideSettingsReader(null, "TestSection");

            Assert.AreEqual(0, reader.ReadSettings().Count());
        }