Exemple #1
0
 public DiffResult Compare()
 {
     if (_diffResult == null)
     {
         _diffResult = new DiffResult();
         XmlReader controlReader, testReader;
         controlReader = testReader = null;
         try {
             controlReader = CreateXmlReader(controlInput);
             testReader    = CreateXmlReader(testInput);
             if (!controlInput.Equals(testInput))
             {
                 Compare(_diffResult, controlReader, testReader);
             }
         } finally {
             try {
                 if (testReader != null)
                 {
                     testReader.Close();
                 }
             } finally {
                 if (controlReader != null)
                 {
                     controlReader.Close();
                 }
             }
         }
     }
     return(_diffResult);
 }
 public void CreateDiffResult()
 {
     _result = new DiffResult();
     _diff = new XmlDiff("<a/>", "<b/>");
     _majorDifference = new Difference(DifferenceType.ELEMENT_TAG_NAME_ID, XmlNodeType.Element, XmlNodeType.Element);
     _minorDifference = new Difference(DifferenceType.ATTR_SEQUENCE_ID, XmlNodeType.Comment, XmlNodeType.Comment);
 }
Exemple #3
0
        private void CheckNodeTypes(XmlNodeType controlNodeType,
                                    XmlNodeType testNodeType,
                                    DiffResult result,
                                    ReaderWithState control,
                                    ReaderWithState test)
        {
            ReaderWithState readerToAdvance = null;

            if (controlNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = control;
            }
            else if (testNodeType.Equals(XmlNodeType.XmlDeclaration))
            {
                readerToAdvance = test;
            }

            if (readerToAdvance != null)
            {
                DifferenceFound(DifferenceType.HAS_XML_DECLARATION_PREFIX_ID,
                                controlNodeType, testNodeType, result);
                readerToAdvance.Read();
                CompareNodes(result, control, test);
            }
            else
            {
                DifferenceFound(DifferenceType.NODE_TYPE_ID, controlNodeType,
                                testNodeType, result);
            }
        }
Exemple #4
0
        private void CompareAttributes(DiffResult result, int controlAttributeCount)
        {
            string controlAttrValue, controlAttrName;
            string testAttrValue, testAttrName;

            _controlReader.MoveToFirstAttribute();
            _testReader.MoveToFirstAttribute();
            for (int i = 0; i < controlAttributeCount; ++i)
            {
                controlAttrName = _controlReader.Name;
                testAttrName    = _testReader.Name;

                controlAttrValue = _controlReader.Value;
                testAttrValue    = _testReader.Value;

                if (!String.Equals(controlAttrName, testAttrName))
                {
                    DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID, result);

                    if (!_testReader.MoveToAttribute(controlAttrName))
                    {
                        DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
                    }
                    testAttrValue = _testReader.Value;
                }

                if (!String.Equals(controlAttrValue, testAttrValue))
                {
                    DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
                }

                _controlReader.MoveToNextAttribute();
                _testReader.MoveToNextAttribute();
            }
        }
Exemple #5
0
 public DiffResult Compare() {
     if (_diffResult == null) {
         _diffResult = new DiffResult();
         XmlReader controlReader, testReader;
         controlReader = testReader = null;
         try {
             controlReader = CreateXmlReader(controlInput);
             testReader = CreateXmlReader(testInput);
             if (!controlInput.Equals(testInput)) {
                 Compare(_diffResult, controlReader, testReader);
             }
         } finally {
             try {
                 if (testReader != null) {
                     testReader.Close();
                 }
             } finally {
                 if (controlReader != null) {
                     controlReader.Close();
                 }
             }
         }
     }
     return _diffResult;
 }
Exemple #6
0
 private void CheckEndElement(XmlReader reader, ref bool readResult, DiffResult result)
 {
     readResult = reader.Read();
     if (!readResult || reader.NodeType != XmlNodeType.EndElement)
     {
         DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
     }
 }
Exemple #7
0
 private void DifferenceFound(Difference difference, DiffResult result)
 {
     result.DifferenceFound(this, difference);
     if (!ContinueComparison(difference))
     {
         throw new FlowControlException(difference);
     }
 }
Exemple #8
0
 private void DifferenceFound(DifferenceType differenceType,
                              XmlNodeType controlNodeType,
                              XmlNodeType testNodeType,
                              DiffResult result)
 {
     DifferenceFound(new Difference(differenceType, controlNodeType, testNodeType),
                     result);
 }
Exemple #9
0
        private void CompareText(DiffResult result)
        {
            string controlText = _controlReader.Value;
            string testText    = _testReader.Value;

            if (!String.Equals(controlText, testText))
            {
                DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
            }
        }
Exemple #10
0
 public DiffResult Compare()
 {
     if (_diffResult == null) {
         _diffResult = new DiffResult();
         if (!_controlReader.Equals(_testReader)) {
             Compare(_diffResult);
         }
     }
     return _diffResult;
 }
Exemple #11
0
        private void CompareText(DiffResult result, ReaderWithState control,
                                 ReaderWithState test)
        {
            string controlText = control.Reader.Value;
            string testText    = test.Reader.Value;

            if (!String.Equals(controlText, testText))
            {
                DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
            }
        }
Exemple #12
0
 public DiffResult Compare()
 {
     if (_diffResult == null)
     {
         _diffResult = new DiffResult();
         if (!_controlReader.Equals(_testReader))
         {
             Compare(_diffResult);
         }
     }
     return(_diffResult);
 }
Exemple #13
0
        private void CompareAttributes(DiffResult result,
                                       XmlAttribute[] controlAttributes,
                                       XmlAttribute[] testAttributes)
        {
            ArrayList unmatchedTestAttributes = new ArrayList();

            unmatchedTestAttributes.AddRange(testAttributes);
            for (int i = 0; i < controlAttributes.Length; ++i)
            {
                bool   controlIsInNs   = IsNamespaced(controlAttributes[i]);
                string controlAttrName =
                    GetUnNamespacedNodeName(controlAttributes[i]);
                XmlAttribute testAttr = null;
                if (!controlIsInNs)
                {
                    testAttr = FindAttributeByName(testAttributes,
                                                   controlAttrName);
                }
                else
                {
                    testAttr = FindAttributeByNameAndNs(testAttributes,
                                                        controlAttrName,
                                                        controlAttributes[i]
                                                        .NamespaceURI);
                }

                if (testAttr != null)
                {
                    unmatchedTestAttributes.Remove(testAttr);
                    if (!_diffConfiguration.IgnoreAttributeOrder &&
                        testAttr != testAttributes[i])
                    {
                        DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID,
                                        result);
                    }

                    if (controlAttributes[i].Value != testAttr.Value)
                    {
                        DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
                    }
                }
                else
                {
                    DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID,
                                    result);
                }
            }
            foreach (XmlAttribute a in unmatchedTestAttributes)
            {
                DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
            }
        }
Exemple #14
0
        private void CheckEmptyOrAtEndElement(DiffResult result,
											  ref bool controlRead, ref bool testRead)
        {
            if (_controlReader.IsEmptyElement) {
                if (!_testReader.IsEmptyElement) {
                    CheckEndElement(_testReader, ref testRead, result);
                }
            } else {
                if (_testReader.IsEmptyElement) {
                    CheckEndElement(_controlReader, ref controlRead, result);
                }
            }
        }
Exemple #15
0
        private static void XmlEquals(XmlDiff xmlDiff, bool equalOrNot)
        {
            DiffResult diffResult = xmlDiff.Compare();

            if (equalOrNot)
            {
                NUnit.Framework.Assert.IsTrue(diffResult.Equal, diffResult.StringValue);
            }
            else
            {
                NUnit.Framework.Assert.IsFalse(diffResult.Equal, diffResult.StringValue);
            }
        }
Exemple #16
0
        private static void XmlIdentical(XmlDiff xmlDiff, bool identicalOrNot)
        {
            DiffResult diffResult = xmlDiff.Compare();

            if (identicalOrNot)
            {
                NUnit.Framework.Assert.IsTrue(diffResult.Identical, xmlDiff.OptionalDescription);
            }
            else
            {
                NUnit.Framework.Assert.IsFalse(diffResult.Identical, xmlDiff.OptionalDescription);
            }
        }
Exemple #17
0
 private void Compare(DiffResult result, XmlReader controlReader,
                      XmlReader testReader) {
     try {
         ReaderWithState control = new ReaderWithState(controlReader);
         ReaderWithState test = new ReaderWithState(testReader);
         do {
             control.Read();
             test.Read();
             Compare(result, control, test);
         } while (control.HasRead && test.HasRead) ;
     } catch (FlowControlException e) {       
         Console.Out.WriteLine(e.Message);
     }
 }        
Exemple #18
0
 private void Compare(DiffResult result, ref bool controlRead, ref bool testRead)
 {
     if (controlRead)
     {
         if (testRead)
         {
             CompareNodes(result);
             CheckEmptyOrAtEndElement(result, ref controlRead, ref testRead);
         }
         else
         {
             DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
         }
     }
 }
Exemple #19
0
        private void Compare(DiffResult result)
        {
            bool controlRead, testRead;

            try {
                do
                {
                    controlRead = _controlReader.Read();
                    testRead    = _testReader.Read();
                    Compare(result, ref controlRead, ref testRead);
                } while (controlRead && testRead);
            } catch (FlowControlException e) {
                Console.Out.WriteLine(e.Message);
            }
        }
Exemple #20
0
 private void Compare(DiffResult result, ReaderWithState control,
                      ReaderWithState test)
 {
     if (control.HasRead)
     {
         if (test.HasRead)
         {
             CompareNodes(result, control, test);
             CheckEmptyOrAtEndElement(result, control, test);
         }
         else
         {
             DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
         }
     }
 }
Exemple #21
0
 private void Compare(DiffResult result, XmlReader controlReader,
                      XmlReader testReader)
 {
     try {
         ReaderWithState control = new ReaderWithState(controlReader);
         ReaderWithState test    = new ReaderWithState(testReader);
         do
         {
             control.Read();
             test.Read();
             Compare(result, control, test);
         } while (control.HasRead && test.HasRead);
     } catch (FlowControlException e) {
         Console.Out.WriteLine(e.Message);
     }
 }
Exemple #22
0
        private void CompareNodes(DiffResult result)
        {
            XmlNodeType controlNodeType = _controlReader.NodeType;
            XmlNodeType testNodeType    = _testReader.NodeType;

            if (!controlNodeType.Equals(testNodeType))
            {
                CheckNodeTypes(controlNodeType, testNodeType, result);
            }
            else if (controlNodeType == XmlNodeType.Element)
            {
                CompareElements(result);
            }
            else if (controlNodeType == XmlNodeType.Text)
            {
                CompareText(result);
            }
        }
Exemple #23
0
 private void CheckEmptyOrAtEndElement(DiffResult result,
                                       ref bool controlRead, ref bool testRead)
 {
     if (_controlReader.IsEmptyElement)
     {
         if (!_testReader.IsEmptyElement)
         {
             CheckEndElement(_testReader, ref testRead, result);
         }
     }
     else
     {
         if (_testReader.IsEmptyElement)
         {
             CheckEndElement(_controlReader, ref controlRead, result);
         }
     }
 }
Exemple #24
0
 private void CheckEmptyOrAtEndElement(DiffResult result,
                                       ReaderWithState control,
                                       ReaderWithState test)
 {
     if (control.LastElementWasEmpty)
     {
         if (!test.LastElementWasEmpty)
         {
             CheckEndElement(test, result);
         }
     }
     else
     {
         if (test.LastElementWasEmpty)
         {
             CheckEndElement(control, result);
         }
     }
 }
Exemple #25
0
        private void CompareNodes(DiffResult result, ReaderWithState control,
                                  ReaderWithState test)
        {
            XmlNodeType controlNodeType = control.Reader.NodeType;
            XmlNodeType testNodeType    = test.Reader.NodeType;

            if (!controlNodeType.Equals(testNodeType))
            {
                CheckNodeTypes(controlNodeType, testNodeType, result,
                               control, test);
            }
            else if (controlNodeType == XmlNodeType.Element)
            {
                CompareElements(result, control, test);
            }
            else if (controlNodeType == XmlNodeType.Text)
            {
                CompareText(result, control, test);
            }
        }
Exemple #26
0
        private void CompareElements(DiffResult result, ReaderWithState control,
                                     ReaderWithState test)
        {
            string controlTagName = control.Reader.Name;
            string testTagName    = test.Reader.Name;

            if (!String.Equals(controlTagName, testTagName))
            {
                DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
            }
            else
            {
                XmlAttribute[] controlAttributes =
                    GetNonSpecialAttributes(control);
                XmlAttribute[] testAttributes = GetNonSpecialAttributes(test);
                if (controlAttributes.Length != testAttributes.Length)
                {
                    DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
                }
                CompareAttributes(result, controlAttributes, testAttributes);
            }
        }
Exemple #27
0
        private void CompareElements(DiffResult result)
        {
            string controlTagName = _controlReader.Name;
            string testTagName    = _testReader.Name;

            if (!String.Equals(controlTagName, testTagName))
            {
                DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
            }
            else
            {
                int controlAttributeCount = _controlReader.AttributeCount;
                int testAttributeCount    = _testReader.AttributeCount;
                if (controlAttributeCount != testAttributeCount)
                {
                    DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
                }
                else
                {
                    CompareAttributes(result, controlAttributeCount);
                }
            }
        }
Exemple #28
0
 private void CompareText(DiffResult result, ReaderWithState control, ReaderWithState test)
 {
     string controlText = control.Reader.Value;
       string testText = test.Reader.Value;
       if (!String.Equals(controlText, testText))
       {
     DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
       }
 }
Exemple #29
0
        private void DifferenceFound(DifferenceType differenceType,
									 XmlNodeType controlNodeType,
									 XmlNodeType testNodeType,
									 DiffResult result)
        {
            DifferenceFound(new Difference(differenceType, controlNodeType, testNodeType),
                            result);
        }
Exemple #30
0
 private void CheckEmptyOrAtEndElement(DiffResult result, ReaderWithState control, ReaderWithState test)
 {
     if (control.LastElementWasEmpty)
       {
     if (!test.LastElementWasEmpty)
     {
       CheckEndElement(test, result);
     }
       }
       else
       {
     if (test.LastElementWasEmpty)
     {
       CheckEndElement(control, result);
     }
       }
 }
Exemple #31
0
 private void DifferenceFound(DifferenceType differenceType, DiffResult result)
 {
     DifferenceFound(new Difference(differenceType), result);
 }
Exemple #32
0
 private void DifferenceFound(Difference difference, DiffResult result)
 {
     result.DifferenceFound(this, difference);
     if (!ContinueComparison(difference)) {
         throw new FlowControlException(difference);
     }
 }
Exemple #33
0
 private void DifferenceFound(DifferenceType differenceType, DiffResult result)
 {
     DifferenceFound(new Difference(differenceType), result);
 }
Exemple #34
0
 private void Compare(DiffResult result, ReaderWithState control, ReaderWithState test)
 {
     if (control.HasRead)
       {
     if (test.HasRead)
     {
       CompareNodes(result, control, test);
       CheckEmptyOrAtEndElement(result, control, test);
     }
     else
     {
       DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
     }
       }
 }
Exemple #35
0
 private void CompareNodes(DiffResult result, ReaderWithState control, ReaderWithState test)
 {
     XmlNodeType controlNodeType = control.Reader.NodeType;
       XmlNodeType testNodeType = test.Reader.NodeType;
       if (!controlNodeType.Equals(testNodeType))
       {
     CheckNodeTypes(controlNodeType, testNodeType, result, control, test);
       }
       else if (controlNodeType == XmlNodeType.Element)
       {
     CompareElements(result, control, test);
       }
       else if (controlNodeType == XmlNodeType.Text)
       {
     CompareText(result, control, test);
       }
 }
Exemple #36
0
 private void CompareElements(DiffResult result)
 {
     string controlTagName = _controlReader.Name;
     string testTagName = _testReader.Name;
     if (!String.Equals(controlTagName, testTagName)) {
         DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
     } else {
         int controlAttributeCount = _controlReader.AttributeCount;
         int testAttributeCount = _testReader.AttributeCount;
         if (controlAttributeCount != testAttributeCount) {
             DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
         } else {
             CompareAttributes(result, controlAttributeCount);
         }
     }
 }
Exemple #37
0
 private void Compare(DiffResult result)
 {
     bool controlRead, testRead;
     try {
         do {
             controlRead = _controlReader.Read();
             testRead = _testReader.Read();
             Compare(result, ref controlRead, ref testRead);
         } while (controlRead && testRead) ;
     } catch (FlowControlException e) {
         Console.Out.WriteLine(e.Message);
     }
 }
Exemple #38
0
 private void Compare(DiffResult result, ref bool controlRead, ref bool testRead)
 {
     if (controlRead) {
         if(testRead) {
             CompareNodes(result);
             CheckEmptyOrAtEndElement(result, ref controlRead, ref testRead);
         } else {
             DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
         }
     }
 }
Exemple #39
0
        private static void AssertXmlIdentical(XmlDiff xmlDiff, bool identicalOrNot)
        {
            DiffResult diffResult = xmlDiff.Compare();

            AssertEquals(xmlDiff.OptionalDescription, identicalOrNot, diffResult.Identical);
        }
Exemple #40
0
        private static void AssertXmlEquals(XmlDiff xmlDiff, bool equalOrNot)
        {
            DiffResult diffResult = xmlDiff.Compare();

            Assertion.AssertEquals(diffResult.StringValue, equalOrNot, diffResult.Equal);
        }
Exemple #41
0
 private void CompareElements(DiffResult result, ReaderWithState control, ReaderWithState test)
 {
     string controlTagName = control.Reader.Name;
       string testTagName = test.Reader.Name;
       if (!String.Equals(controlTagName, testTagName))
       {
     DifferenceFound(DifferenceType.ELEMENT_TAG_NAME_ID, result);
       }
       else
       {
     XmlAttribute[] controlAttributes = GetNonSpecialAttributes(control);
     XmlAttribute[] testAttributes = GetNonSpecialAttributes(test);
     if (controlAttributes.Length != testAttributes.Length)
     {
       DifferenceFound(DifferenceType.ELEMENT_NUM_ATTRIBUTES_ID, result);
     }
     CompareAttributes(result, controlAttributes, testAttributes);
       }
 }
Exemple #42
0
 private void CheckEndElement(XmlReader reader, ref bool readResult, DiffResult result)
 {
     readResult = reader.Read();
     if (!readResult || reader.NodeType != XmlNodeType.EndElement) {
         DifferenceFound(DifferenceType.CHILD_NODELIST_LENGTH_ID, result);
     }
 }
Exemple #43
0
 private void CompareNodes(DiffResult result)
 {
     XmlNodeType controlNodeType = _controlReader.NodeType;
     XmlNodeType testNodeType = _testReader.NodeType;
     if (!controlNodeType.Equals(testNodeType)) {
         CheckNodeTypes(controlNodeType, testNodeType, result);
     } else if (controlNodeType == XmlNodeType.Element) {
         CompareElements(result);
     } else if (controlNodeType == XmlNodeType.Text) {
         CompareText(result);
     }
 }
Exemple #44
0
        private void CheckNodeTypes(XmlNodeType controlNodeType, XmlNodeType testNodeType, DiffResult result)
        {
            XmlReader readerToAdvance = null;
            if (controlNodeType.Equals(XmlNodeType.XmlDeclaration)) {
                readerToAdvance = _controlReader;
            } else if (testNodeType.Equals(XmlNodeType.XmlDeclaration)) {
                readerToAdvance = _testReader;
            }

            if (readerToAdvance != null) {
                DifferenceFound(DifferenceType.HAS_XML_DECLARATION_PREFIX_ID,
                                controlNodeType, testNodeType, result);
                readerToAdvance.Read();
                CompareNodes(result);
            } else {
                DifferenceFound(DifferenceType.NODE_TYPE_ID, controlNodeType,
                                testNodeType, result);
            }
        }
Exemple #45
0
 private void CompareText(DiffResult result)
 {
     string controlText = _controlReader.Value;
     string testText = _testReader.Value;
     if (!String.Equals(controlText, testText)) {
         DifferenceFound(DifferenceType.TEXT_VALUE_ID, result);
     }
 }
Exemple #46
0
        private void CompareAttributes(DiffResult result, int controlAttributeCount)
        {
            string controlAttrValue, controlAttrName;
            string testAttrValue, testAttrName;

            _controlReader.MoveToFirstAttribute();
            _testReader.MoveToFirstAttribute();
            for (int i=0; i < controlAttributeCount; ++i) {

                controlAttrName = _controlReader.Name;
                testAttrName = _testReader.Name;

                controlAttrValue = _controlReader.Value;
                testAttrValue = _testReader.Value;

                if (!String.Equals(controlAttrName, testAttrName)) {
                    DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID, result);

                    if (!_testReader.MoveToAttribute(controlAttrName)) {
                        DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
                    }
                    testAttrValue = _testReader.Value;
                }

                if (!String.Equals(controlAttrValue, testAttrValue)) {
                    DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
                }

                _controlReader.MoveToNextAttribute();
                _testReader.MoveToNextAttribute();
            }
        }
Exemple #47
0
        private void CompareAttributes(DiffResult result, XmlAttribute[] controlAttributes, XmlAttribute[] testAttributes)
        {
            var unmatchedTestAttributes = new ArrayList();
              unmatchedTestAttributes.AddRange(testAttributes);
              for (int i = 0; i < controlAttributes.Length; ++i)
              {
            bool controlIsInNs = IsNamespaced(controlAttributes[i]);
            string controlAttrName = GetUnNamespacedNodeName(controlAttributes[i]);
            XmlAttribute testAttr = null;
            if (!controlIsInNs)
            {
              testAttr = FindAttributeByName(testAttributes, controlAttrName);
            }
            else
            {
              testAttr = FindAttributeByNameAndNs(testAttributes, controlAttrName, controlAttributes[i].NamespaceURI);
            }

            if (testAttr != null)
            {
              unmatchedTestAttributes.Remove(testAttr);
              if (!_diffConfiguration.IgnoreAttributeOrder && testAttr != testAttributes[i])
              {
            DifferenceFound(DifferenceType.ATTR_SEQUENCE_ID, result);
              }

              if (controlAttributes[i].Value != testAttr.Value)
              {
            DifferenceFound(DifferenceType.ATTR_VALUE_ID, result);
              }

            }
            else
            {
              DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
            }
              }
              foreach (XmlAttribute a in unmatchedTestAttributes)
              {
            DifferenceFound(DifferenceType.ATTR_NAME_NOT_FOUND_ID, result);
              }
        }