Ejemplo n.º 1
0
        public void Preprocess_WhenReaderIsNull_Throws()
        {
            var preprocessor = new XmlPreprocessor();
            var writer       = XmlWriter.Create(new StringBuilder());

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

            Assert.Throws <ArgumentNullException>(() => preprocessor.Preprocess(reader, null));
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 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);
        }