Exemplo n.º 1
0
 public XmlDiff(XmlInput control, XmlInput test,
                DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
     controlInput       = control;
     testInput          = test;
 }
Exemplo n.º 2
0
        public void CanConfigureNotToUseValidatingParser()
        {
            DiffConfiguration diffConfiguration = new DiffConfiguration(useValidatingParser: false);
              Assert.AreEqual(false, diffConfiguration.UseValidatingParser);
              System.Console.WriteLine("Use validating parser: " + diffConfiguration.UseValidatingParser.ToString());

              FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE,
                                               FileMode.Open, FileAccess.Read);
              FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE,
                                            FileMode.Open, FileAccess.Read);
              try
              {
            XmlDiff diff = new XmlDiff(new XmlInput(controlFileStream),
                                   new XmlInput(testFileStream),
                                   diffConfiguration);
            diff.Compare();
              }
              catch (XmlSchemaException e)
              {
            Assert.Fail("Unexpected validation failure: " + e.Message);
              }
              finally
              {
            controlFileStream.Close();
            testFileStream.Close();
              }
        }
 [Test] public void DefaultConfiguredWithGenericDescription() {
     DiffConfiguration diffConfiguration = new DiffConfiguration();
     Assert.AreEqual(DiffConfiguration.DEFAULT_DESCRIPTION, 
                            diffConfiguration.Description);
     
     Assert.AreEqual(DiffConfiguration.DEFAULT_DESCRIPTION, 
                            new XmlDiff("", "").OptionalDescription);
 }
 [Test] public void DefaultConfiguredWithWhitespaceHandlingAll() {
     DiffConfiguration diffConfiguration = new DiffConfiguration();
     Assert.AreEqual(WhitespaceHandling.All, diffConfiguration.WhitespaceHandling);
     
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespaceElement, false);
     PerformAssertion(xmlWithoutWhitespace, xmlWithoutWhitespaceElement, false);
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespace, false);
     PerformAssertion(xmlWithoutWhitespaceElement, xmlWithWhitespaceElement, false);
 }
Exemplo n.º 5
0
        public XmlDiff(XmlInput control, XmlInput test,
					   DiffConfiguration diffConfiguration)
        {
            _diffConfiguration =  diffConfiguration;
            _controlReader = CreateXmlReader(control);
            if (control.Equals(test)) {
                _testReader = _controlReader;
            } else {
                _testReader = CreateXmlReader(test);
            }
        }
 public void CanConfigureWhitespaceHandlingSignificant()
 {
     DiffConfiguration xmlUnitConfiguration =
         new DiffConfiguration (WhitespaceHandling.Significant);
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespaceElement,
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespace, xmlWithoutWhitespaceElement,
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespace,
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespaceElement, xmlWithWhitespaceElement,
                      true, xmlUnitConfiguration);
 }
Exemplo n.º 7
0
 public void CanConfigureWhitespaceHandlingSignificant()
 {
     DiffConfiguration xmlUnitConfiguration =
     new DiffConfiguration(whitespaceHandling: WhitespaceHandling.Significant, useValidatingParser: false);
       PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespaceElement,
                true, xmlUnitConfiguration);
       PerformAssertion(xmlWithoutWhitespace, xmlWithoutWhitespaceElement,
                true, xmlUnitConfiguration);
       PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespace,
                true, xmlUnitConfiguration);
       PerformAssertion(xmlWithoutWhitespaceElement, xmlWithWhitespaceElement,
                true, xmlUnitConfiguration);
 }
Exemplo n.º 8
0
 public XmlDiff(XmlInput control, XmlInput test,
                DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
     _controlReader     = CreateXmlReader(control);
     if (control.Equals(test))
     {
         _testReader = _controlReader;
     }
     else
     {
         _testReader = CreateXmlReader(test);
     }
 }
        public void DefaultConfiguredToUseValidatingParser()
        {
            DiffConfiguration diffConfiguration = new DiffConfiguration();
            Assertion.AssertEquals(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER,
                                   diffConfiguration.UseValidatingParser);

            FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE,
                                                     FileMode.Open, FileAccess.Read);
            FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE,
                                                  FileMode.Open, FileAccess.Read);
            try {
                XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream),
                                           new StreamReader(testFileStream));
                diff.Compare();
                Assertion.Fail("Expected validation failure");
            } catch (XmlSchemaException e) {
                string message = e.Message; // to prevent 'unused variable' compiler warning
            } finally {
                controlFileStream.Close();
                testFileStream.Close();
            }
        }
 public void DefaultConfiguredToUseValidatingParser() {
     DiffConfiguration diffConfiguration = new DiffConfiguration();
     Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER, 
                            diffConfiguration.UseValidatingParser);
     
     bool exception = false;
     using (FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE, 
                                                     FileMode.Open,
                                                     FileAccess.Read))
     using (FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE, 
                                                  FileMode.Open,
                                                  FileAccess.Read)) {
       try {
         XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream), 
                                    new StreamReader(testFileStream));
         diff.Compare();
       } catch (System.Exception) {
         // should be an XmlSchemaValidationException in .NET 2.0
         // and later
         exception = true;
       }
     }
     Assert.IsTrue(exception, "expected validation to fail");
 }
Exemplo n.º 11
0
        public void DefaultConfiguredToUseValidatingParser()
        {
            DiffConfiguration diffConfiguration = new DiffConfiguration();
              Assert.AreEqual(DiffConfiguration.DEFAULT_USE_VALIDATING_PARSER,
                             diffConfiguration.UseValidatingParser);

              using (FileStream controlFileStream = File.Open(ValidatorTests.VALID_FILE,
                                                      FileMode.Open,
                                                      FileAccess.Read))
              using (FileStream testFileStream = File.Open(ValidatorTests.INVALID_FILE,
                                                   FileMode.Open,
                                                   FileAccess.Read))
              {
            XmlDiff diff = new XmlDiff(new StreamReader(controlFileStream), new StreamReader(testFileStream));
            Assert.Throws<XmlSchemaValidationException>(delegate
            {
              diff.Compare();
            });
              }
        }
Exemplo n.º 12
0
 public XmlDiff(XmlInput control, XmlInput test, DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
       controlInput = control;
       testInput = test;
 }
Exemplo n.º 13
0
 private void PerformAssertion(string control, string test, bool assertion,
                           DiffConfiguration xmlUnitConfiguration)
 {
     XmlDiff diff = new XmlDiff(new XmlInput(control), new XmlInput(test),
                          xmlUnitConfiguration);
       PerformAssertion(diff, assertion);
 }
Exemplo n.º 14
0
 public XmlDiff(TextReader control, TextReader test, DiffConfiguration diffConfiguration)
     : this(new XmlInput(control), new XmlInput(test), diffConfiguration)
 {
 }
Exemplo n.º 15
0
 public XmlDiff(string control, string test, DiffConfiguration diffConfiguration)
     : this(new XmlInput(control), new XmlInput(test), diffConfiguration)
 {
 }
 [Test] public void CanConfigureWhitespaceHandlingNone() {
     DiffConfiguration xmlUnitConfiguration = 
         new DiffConfiguration(WhitespaceHandling.None);
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespaceElement, 
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespace, xmlWithoutWhitespaceElement, 
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespace, xmlWithWhitespace, 
                      true, xmlUnitConfiguration);
     PerformAssertion(xmlWithoutWhitespaceElement, xmlWithWhitespaceElement, 
                      true, xmlUnitConfiguration);
 }        
Exemplo n.º 17
0
        private void CheckXmlMapping(string hbm,params string[] stream)
        {
            NameTable nt = new NameTable();
            nt.Add("urn:nhibernate-mapping-2.2");
            var nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace("urn", "urn:nhibernate-mapping-2.2");
            XmlDocument doc = new XmlDocument(nt);
            doc.PreserveWhitespace = true;
            doc.LoadXml(internalStreams[stream[0]].ToString());
            XmlNode refChild = doc.SelectSingleNode("//urn:class",nsmgr);
            for (int i = 1; i < stream.Length; ++i)
            {
                XmlDocument docChild = new XmlDocument(nt);
                docChild.PreserveWhitespace = true;
                docChild.LoadXml(internalStreams[stream[i]].ToString());
                doc.SelectSingleNode("/urn:hibernate-mapping",nsmgr).AppendChild(doc.ImportNode(docChild.SelectSingleNode("//urn:class",nsmgr),true));
            }
            DiffConfiguration dc = new DiffConfiguration("test", true, WhitespaceHandling.None, true);
            XmlDiff diff = new XmlDiff(new XmlInput(doc.OuterXml)
                                       , new XmlInput(ResourceHelper.GetResource(hbm))
                                       ,dc
                                       );
            var res = diff.Compare();
            if (!res.Equal)
            {
                Console.WriteLine("Expected xml was:");
                Console.WriteLine(ResourceHelper.GetResource(hbm));
                Console.WriteLine("But was:");
                Console.WriteLine(doc.InnerXml);

            }
            Assert.IsTrue(res.Equal);
        }