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

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

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

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

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

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

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

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

            while (reader.Read())
            {
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #11
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);
		}
예제 #12
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);
		}
예제 #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);
        }
예제 #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);
        }
예제 #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);
		}
예제 #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);
        }
예제 #19
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);
        }
예제 #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);
        }
예제 #21
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);
		}
예제 #22
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);
		}
예제 #23
0
		public void AllwaysReportFullEndElements()
		{
			string xml = "<root/>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));
			string output = ReadToEnd(reader);

			WriteIfDebugging(output);

			Assert.AreEqual("<root></root>", output);
		}
예제 #24
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);
		}
		public void DerivedProcessorCannotInitializeNullAction()
		{
			string xml = "<root>foo</root>";
			XmlProcessorReader reader = new XmlProcessorReader(GetReader(xml));

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

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