コード例 #1
0
        public void Define_WhenConstantAlreadyDefined_DoesNothing()
        {
            var preprocessor = new XmlPreprocessor();
            preprocessor.Define("CONSTANT");

            preprocessor.Define("CONSTANT");

            Assert.IsTrue(preprocessor.IsDefined("CONSTANT"));
        }
コード例 #2
0
        public void IsDefined_WhenConstantIsDefined_ReturnsTrue()
        {
            var preprocessor = new XmlPreprocessor();
            preprocessor.Define("CONSTANT");

            Assert.IsTrue(preprocessor.IsDefined("CONSTANT"));
        }
コード例 #3
0
        public void Preprocess_WhenPresetDefinesBeforeProcessing_UsesThem()
        {
            var preprocessor = new XmlPreprocessor();
            preprocessor.Define("CONSTANT");
            string input = "<root><?ifdef CONSTANT?>Text<?endif?></root>";

            string output = PreprocessString(preprocessor, input);

            Assert.AreEqual("<root>Text</root>", output);
        }
コード例 #4
0
        public void Define_WhenConstantIsNull_Throws()
        {
            var preprocessor = new XmlPreprocessor();

            Assert.Throws<ArgumentNullException>(() => preprocessor.Define(null));
        }
コード例 #5
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;
        }