Exemplo n.º 1
0
        public void MatchSectionCount()
        {
            List <XmlMatch> match = PathExpressionParser.Parse("/configuration/configSections/section");

            int matchCount = 0;

            string xml = @"
<configuration>
  <configSections>
    <section name='foo' />
    <section name='bar' />
  </configSections>
</configuration>";

            XmlReaderSettings set = new XmlReaderSettings();

            set.IgnoreWhitespace = true;
            XmlProcessorReader reader = new XmlProcessorReader(XmlReader.Create(new StringReader(xml)));

            reader.Processors.Add(new XmlPathProcessor(match,
                                                       delegate { matchCount++; },
                                                       reader.NameTable));

            reader.ReadToEnd();

            Assert.AreEqual(2, matchCount);
        }
Exemplo n.º 2
0
        public void ProcessorReaderCanReadToEnd()
        {
            string             xml       = "<root>foo</root>";
            XmlProcessorReader reader    = new XmlProcessorReader(GetReader(xml));
            MockProcessor      processor = new MockProcessor();

            reader.Processors.Add(processor);
            reader.ReadToEnd();

            Assert.AreEqual(3, processor.Calls);
        }
Exemplo n.º 3
0
		public void ProcessorReaderCanReadToEnd()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			MockProcessor processor = new MockProcessor();

			reader.Processors.Add(processor);
			reader.ReadToEnd();

			Assert.AreEqual(3, processor.Calls);
		}
Exemplo n.º 4
0
        public void IntegrationTest()
        {
            // count(//section)
            int sectionCount = 0;
            // count(/configuration/configSections/section)
            int topLevelSectionCount = 0;
            // count(//*/@type)
            int typeCount = 0;
            // count(@type)
            int typeAttrCount = 0;
            // count(//add)
            int addCount = 0;
            // count(/configuration/runtime/r:assemblyBinding/r:dependentAssembly)
            int dependentAssemblyCount = 0;

            XmlProcessorReader reader = new XmlProcessorReader(XmlReader.Create("machine.config"));

            //reader.
            //    When().
            //    Do(action).
            //    Otherwise(action);

            reader.Processors.Add(new XmlPathProcessor("//section", delegate { sectionCount++; }, reader.NameTable));
            reader.Processors.Add(new XmlPathProcessor("/configuration/configSections/section", delegate { topLevelSectionCount++; }, reader.NameTable));
            reader.Processors.Add(new XmlPathProcessor("//*/@type", delegate { typeCount++; }, reader.NameTable));
            reader.Processors.Add(new XmlPathProcessor("@type", delegate { typeAttrCount++; }, reader.NameTable));
            reader.Processors.Add(new XmlPathProcessor("//add", delegate { addCount++; }, reader.NameTable));

            XmlNamespaceManager mgr = new XmlNamespaceManager(reader.NameTable);

            mgr.AddNamespace("r", "urn:schemas-microsoft-com:asm.v1");
            reader.Processors.Add(new XmlPathProcessor("/configuration/runtime/r:assemblyBinding/r:dependentAssembly", delegate { dependentAssemblyCount++; }, mgr));

            reader.ReadToEnd();

            Assert.AreEqual(70, sectionCount);
            Assert.AreEqual(19, topLevelSectionCount);
            Assert.AreEqual(12, addCount);
            Assert.AreEqual(10, dependentAssemblyCount);
            Assert.AreEqual(87, typeCount);
            Assert.AreEqual(87, typeAttrCount);
        }
Exemplo n.º 5
0
		public void IntegrationTest()
		{
			// count(//section)
			int sectionCount = 0;
			// count(/configuration/configSections/section)
			int topLevelSectionCount = 0;
			// count(//*/@type)
			int typeCount = 0;
			// count(@type)
			int typeAttrCount = 0;
			// count(//add)
			int addCount = 0;
			// count(/configuration/runtime/r:assemblyBinding/r:dependentAssembly)
			int dependentAssemblyCount = 0;

			XmlProcessorReader reader = new XmlProcessorReader(XmlReader.Create("machine.config"));
			
			//reader.
			//    When().
			//    Do(action).
			//    Otherwise(action);
			
			reader.Processors.Add(new XmlPathProcessor("//section", delegate { sectionCount++; }, reader.NameTable));
			reader.Processors.Add(new XmlPathProcessor("/configuration/configSections/section", delegate { topLevelSectionCount++; }, reader.NameTable));
			reader.Processors.Add(new XmlPathProcessor("//*/@type", delegate { typeCount++; }, reader.NameTable));
			reader.Processors.Add(new XmlPathProcessor("@type", delegate { typeAttrCount++; }, reader.NameTable));
			reader.Processors.Add(new XmlPathProcessor("//add", delegate { addCount++; }, reader.NameTable));

			XmlNamespaceManager mgr = new XmlNamespaceManager(reader.NameTable);
			mgr.AddNamespace("r", "urn:schemas-microsoft-com:asm.v1");
			reader.Processors.Add(new XmlPathProcessor("/configuration/runtime/r:assemblyBinding/r:dependentAssembly", delegate { dependentAssemblyCount++; }, mgr));

			reader.ReadToEnd();

			Assert.AreEqual(70, sectionCount);
			Assert.AreEqual(19, topLevelSectionCount);
			Assert.AreEqual(12, addCount);
			Assert.AreEqual(10, dependentAssemblyCount);
			Assert.AreEqual(87, typeCount);
			Assert.AreEqual(87, typeAttrCount);
		}
Exemplo n.º 6
0
		public void MatchSectionCount()
		{
			List<XmlMatch> match = PathExpressionParser.Parse("/configuration/configSections/section");

			int matchCount = 0;

			string xml = @"
<configuration>
  <configSections>
    <section name='foo' />
    <section name='bar' />
  </configSections>
</configuration>";

			XmlReaderSettings set = new XmlReaderSettings();
			set.IgnoreWhitespace = true;
			XmlProcessorReader reader = new XmlProcessorReader(XmlReader.Create(new StringReader(xml)));
			reader.Processors.Add(new XmlPathProcessor(match,
				delegate { matchCount++; },
				reader.NameTable));

			reader.ReadToEnd();

			Assert.AreEqual(2, matchCount);
		}