示例#1
0
        public void Preprocess_WhenReaderIsNull_Throws()
        {
            var preprocessor = new XmlPreprocessor();
            var writer       = XmlWriter.Create(new StringBuilder());

            Assert.Throws <ArgumentNullException>(() => preprocessor.Preprocess(null, writer));
        }
示例#2
0
        public void Preprocess_WhenWriterIsNull_Throws()
        {
            var preprocessor = new XmlPreprocessor();
            var reader       = XmlReader.Create(new StringReader(""));

            Assert.Throws <ArgumentNullException>(() => preprocessor.Preprocess(reader, null));
        }
示例#3
0
        private static string PreprocessString(XmlPreprocessor preprocessor, string xml)
        {
            using (var reader = XmlReader.Create(new StringReader(xml)))
            {
                var xmlOutput = new StringBuilder();
                using (var writer = XmlWriter.Create(xmlOutput, new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                }))
                {
                    preprocessor.Preprocess(reader, writer);
                }

                return(xmlOutput.ToString());
            }
        }
示例#4
0
        private Plugin PreprocessAndDeserialize(TextReader reader)
        {
            XmlPreprocessor preprocessor = new XmlPreprocessor();

            foreach (string constant in initialPreprocessorConstants)
            {
                preprocessor.Define(constant);
            }

            StringBuilder preprocessedXml = new StringBuilder();

            using (XmlReader xmlReader = XmlReader.Create(reader))
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(preprocessedXml))
                    preprocessor.Preprocess(xmlReader, xmlWriter);
            }

            var plugin = (Plugin)PluginXmlSerializer.Deserialize(new StringReader(preprocessedXml.ToString()));

            plugin.Validate();
            return(plugin);
        }