public void CanAddXmlProcessor()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

			reader.Processors.Add(new MockProcessor());
		}
Beispiel #2
0
        public void CanAddXmlProcessor()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

            reader.Processors.Add(new MockProcessor());
        }
        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);
        }
		public void DerivedProcessorMustInitializeBase()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

			reader.Processors.Add(new MockProcessorDerived());

			while (reader.Read()) { }
		}
Beispiel #5
0
        public void AllwaysReportFullEndElements()
        {
            string             xml    = "<root/>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
            string             output = ReadToEnd(reader);

            WriteIfDebugging(output);

            Assert.AreEqual("<root></root>", output);
        }
Beispiel #6
0
        public void DerivedProcessorMustInitializeBase()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

            reader.Processors.Add(new MockProcessorDerived());

            while (reader.Read())
            {
            }
        }
		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);
		}
Beispiel #8
0
        public void DerivedProcessorCannotInitializeNullPredicate()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

            reader.Processors.Add(new MockProcessorDerivedNullPredicate());

            while (reader.Read())
            {
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public void CanChainReader()
        {
            string                  xml       = "<root>foo</root>";
            XmlProcessorReader      reader    = new XmlProcessorReader(GetReader(xml));
            SkipReaderMockProcessor processor = new SkipReaderMockProcessor();

            reader.Processors.Add(processor);

            string output = ReadToEnd(reader);

            WriteIfDebugging(output);
            Assert.AreEqual(1, processor.Calls);
        }
		public void CanChainReader()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			SkipReaderMockProcessor processor = new SkipReaderMockProcessor();

			reader.Processors.Add(processor);

			string output = ReadToEnd(reader);

			WriteIfDebugging(output);
			Assert.AreEqual(1, processor.Calls);
		}
		public void XmlProcessorCalledOnEachReadAndAttributes()
		{
			string xml = "<root id='1'>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			MockProcessor processor = new MockProcessor();

			reader.Processors.Add(processor);

			string output = ReadToEnd(reader);

			WriteIfDebugging(output);
			Assert.AreEqual(4, processor.Calls);
		}
Beispiel #13
0
        public void CanChainMutatingReader()
        {
            string             xml       = "<root>foo</root>";
            XmlProcessorReader reader    = new XmlProcessorReader(GetReader(xml));
            XmlProcessor       processor = new MutateMockProcessor();

            reader.Processors.Add(processor);

            string output = ReadToEnd(reader);

            WriteIfDebugging(output);
            Assert.AreEqual("<Root>foo</Root>", output);
        }
Beispiel #14
0
        public void CanChainMutatingProcessors()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

            reader.Processors.Add(new MutateMockProcessor());
            reader.Processors.Add(new AddNamespaceMutateMockProcessor());

            string output = ReadToEnd(reader);

            WriteIfDebugging(output);
            Assert.AreEqual("<clarius:Root xmlns:clarius=\"http://clariusconsulting.net/kzu\">foo</clarius:Root>", output);
        }
Beispiel #15
0
        public void XmlProcessorCalledOnEachReadAndAttributes()
        {
            string             xml       = "<root id='1'>foo</root>";
            XmlProcessorReader reader    = new XmlProcessorReader(GetReader(xml));
            MockProcessor      processor = new MockProcessor();

            reader.Processors.Add(processor);

            string output = ReadToEnd(reader);

            WriteIfDebugging(output);
            Assert.AreEqual(4, processor.Calls);
        }
		public void ActionCalledIfPredicateTrue()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			int actionCalls = 0;

			reader.Processors.Add(new PredicateActionXmlProcessor(
				delegate(XmlReader predicateReader) { return predicateReader.NodeType == XmlNodeType.Text; },
				delegate { actionCalls++; }
				)
			);

			while (reader.Read()) { }

			Assert.AreEqual(1, actionCalls);
		}
		public void PredicateTrueAndActionCalledForEachRead()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			int predicateCalls = 0;
			int actionCalls = 0;

			reader.Processors.Add(new PredicateActionXmlProcessor(
				delegate { predicateCalls++; return true; },
				delegate { actionCalls++; }
				)
			);

			while (reader.Read()) { }

			Assert.AreEqual(3, predicateCalls);
			Assert.AreEqual(3, actionCalls);
		}
Beispiel #18
0
        public void ActionCalledIfPredicateTrue()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
            int actionCalls           = 0;

            reader.Processors.Add(new PredicateActionXmlProcessor(
                                      delegate(XmlReader predicateReader) { return(predicateReader.NodeType == XmlNodeType.Text); },
                                      delegate { actionCalls++; }
                                      )
                                  );

            while (reader.Read())
            {
            }

            Assert.AreEqual(1, actionCalls);
        }
        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);
        }
Beispiel #20
0
        public void PredicateTrueAndActionCalledForEachRead()
        {
            string             xml    = "<root>foo</root>";
            XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
            int predicateCalls        = 0;
            int actionCalls           = 0;

            reader.Processors.Add(new PredicateActionXmlProcessor(
                                      delegate { predicateCalls++; return(true); },
                                      delegate { actionCalls++; }
                                      )
                                  );

            while (reader.Read())
            {
            }

            Assert.AreEqual(3, predicateCalls);
            Assert.AreEqual(3, actionCalls);
        }
		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);
		}
		public void CanChainMutatingProcessors()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

			reader.Processors.Add(new MutateMockProcessor());
			reader.Processors.Add(new AddNamespaceMutateMockProcessor());

			string output = ReadToEnd(reader);

			WriteIfDebugging(output);
			Assert.AreEqual("<clarius:Root xmlns:clarius=\"http://clariusconsulting.net/kzu\">foo</clarius:Root>", output);
		}
		public void AllwaysReportFullEndElements()
		{
			string xml = "<root/>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			string output = ReadToEnd(reader);

			WriteIfDebugging(output);

			Assert.AreEqual("<root></root>", output);
		}
		public void CanChainMutatingReader()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			XmlProcessor processor = new MutateMockProcessor();

			reader.Processors.Add(processor);

			string output = ReadToEnd(reader);

			WriteIfDebugging(output);
			Assert.AreEqual("<Root>foo</Root>", output);
		}
		public void DerivedProcessorCannotInitializeNullAction()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

			reader.Processors.Add(new MockProcessorDerivedNullAction());

			while (reader.Read()) { }
		}
		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);
		}