Пример #1
0
 public XmlDiff(XmlInput control, XmlInput test,
                DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
     controlInput = control;
     testInput = test;
 }
Пример #2
0
 public string EvaluateXPath(XmlInput forXmlInput)
 {
     XPathNavigator xpathNavigator = GetNavigator(forXmlInput);
     XPathExpression xPathExpression = xpathNavigator.Compile(_xPathExpression);
     if (xPathExpression.ReturnType == XPathResultType.NodeSet)
     {
         return EvaluateXPath(xpathNavigator);
     }
     else
     {
         return xpathNavigator.Evaluate(xPathExpression).ToString();
     }
 }
Пример #3
0
        private XmlReader CreateXmlReader(XmlInput forInput)
        {
            XmlReader xmlReader = forInput.CreateXmlReader();

            if (xmlReader is XmlTextReader)
            {
                ((XmlTextReader) xmlReader).WhitespaceHandling = _diffConfiguration.WhitespaceHandling;
            }

            if (_diffConfiguration.UseValidatingParser)
            {
                var validatingReader = new XmlValidatingReader(xmlReader);
                validatingReader.ValidationEventHandler += (a,b) => { throw new XmlSchemaValidationException(); };
                return validatingReader;
            }

            return xmlReader;
        }
Пример #4
0
 public void StreamInputTranslatesToXmlReader()
 {
     MemoryStream stream = new MemoryStream();
     StreamWriter writer = new StreamWriter(stream, Encoding.Default);
     writer.WriteLine(INPUT);
     writer.Flush();
     stream.Seek(0, SeekOrigin.Begin);
     XmlInput input = new XmlInput(stream);
     string actual = ReadOuterXml(input.CreateXmlReader());
     try
     {
         Assert.Equal(expected, actual);
     }
     finally
     {
         writer.Close();
     }
 }
Пример #5
0
 public void HashCodeEqualsHashCodeOfInput()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(INPUT.GetHashCode(), input.GetHashCode());
 }
Пример #6
0
 public void EqualsSelf()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(input, input);
 }
Пример #7
0
 public void NotEqualsNull()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(false, input.Equals(null));
 }
Пример #8
0
 public void TextReaderInputTranslatesToXmlReader()
 {
     XmlInput input = new XmlInput(new StringReader(INPUT));
     string actual = ReadOuterXml(input.CreateXmlReader());
     Assert.Equal(expected, actual);
 }
 public XmlInputXsltAssertionWrapper(XmlInput original, XmlInput operation)
 {
     this.original = original;
     this.operation = operation;
 }
 public XmlInputXPathAssertionWrapper(XmlInput original, string xPath)
 {
     this.original = original;
     this.xPath = xPath;
 }
Пример #11
0
 private XPathNavigator GetNavigator(XmlInput forXmlInput)
 {
     XPathDocument xpathDocument =
         new XPathDocument(forXmlInput.CreateXmlReader());
     return xpathDocument.CreateNavigator();
 }
Пример #12
0
 private XPathNodeIterator GetNodeIterator(XmlInput forXmlInput)
 {
     XPathNavigator xpathNavigator = GetNavigator(forXmlInput);
     return xpathNavigator.Select(_xPathExpression);
 }
Пример #13
0
 public bool XPathExists(XmlInput forInput)
 {
     XPathNodeIterator iterator = GetNodeIterator(forInput);
     return (iterator.Count > 0);
 }
Пример #14
0
 public XmlDiff(XmlInput control, XmlInput test)
     : this(control, test, new DiffConfiguration())
 {
 }
 public static void ShouldNotBeXmlEqualTo(this XmlInput actual, XmlInput expected)
 {
     var diff = new XmlDiff(expected, actual);
     XmlAssertion.AssertXmlNotEquals(diff);
 }
 public static XmlInputXsltAssertionWrapper XsltTransformation(this XmlInput original, XmlInput xslt)
 {
     return new XmlInputXsltAssertionWrapper(original, xslt);
 }
        public void CompareExpectedXMLs()
        {
            Dictionary<string, string> expected = new Dictionary<string, string>();
            Dictionary<string, string> actual = new Dictionary<string, string>();

            RunReport(mValidTrxFile);
            
            XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
            xmlNamespaceManager.AddNamespace("prefix", "urn:model.allure.qatools.yandex.ru");

            DiffConfiguration diffConfiguration = new DiffConfiguration(String.Empty, false, WhitespaceHandling.None, true);
            
            FillCategoryToXmlMap("sample-output", expected);
            FillCategoryToXmlMap(mTargetDir, actual);

            if (expected.Keys.Count != actual.Keys.Count)
            {
                Assert.Fail("Expected {0} categories but found {1}.", expected.Keys.Count, actual.Keys.Count);
            }

            foreach (string category in actual.Keys)
            {
                if (!expected.ContainsKey(category))
                {
                    Assert.Fail("The category " + category + " was not expected.");
                }

                string expectedFile = expected[category];
                string actualFile = actual[category];

                string expectedFileText = File.ReadAllText(expectedFile);
                string actualFileText = File.ReadAllText(actualFile);

                XmlInput control = new XmlInput(expectedFileText);
                XmlInput test = new XmlInput(actualFileText);
                
                XmlDiff xmlDiff = new XmlDiff(control, test, diffConfiguration);
                    
                DiffResult diffResult = xmlDiff.Compare();
                if (!diffResult.Identical)
                {
                    string failureMessage = String.Format("The expected file {0} was different from the actual file {1}", expectedFile, actualFile);
                    failureMessage += Environment.NewLine;
                    failureMessage += "Expected XML: ";
                    failureMessage += expectedFileText;
                    failureMessage += Environment.NewLine;
                    failureMessage += "Actual XML: ";
                    failureMessage += actualFileText;
                    failureMessage += Environment.NewLine;
                    failureMessage += "Difference: ";
                    failureMessage += diffResult.Difference;

                    Assert.Fail(failureMessage);
                }
            }
        }
 public static void ShouldBeXmlIdenticalTo(this XmlInput actual, XmlInput expected)
 {
     XmlAssertion.AssertXmlIdentical(actual, expected);
 }
Пример #19
0
 public static void AssertXmlValid(XmlInput xmlInput)
 {
     Validator validator = new Validator(xmlInput);
     AssertXmlValid(validator);
 }
 public void ShouldResultIn(XmlInput expectedXml)
 {
     XmlAssertion.AssertXslTransformResults(operation, original, expectedXml);
 }
Пример #21
0
 public static void AssertXPathExists(string anXPathExpression, XmlInput inXml)
 {
     XPath xpath = new XPath(anXPathExpression);
     True(xpath.XPathExists(inXml));
 }
Пример #22
0
 public static void AssertXPathEvaluatesTo(string anXPathExpression, XmlInput inXml,
                                           string expectedValue)
 {
     XPath xpath = new XPath(anXPathExpression);
     Equal(expectedValue, xpath.EvaluateXPath(inXml));
 }
Пример #23
0
 public static void AssertXslTransformResults(XmlInput xslTransform, XmlInput xmlToTransform,
                                              XmlInput expectedResult)
 {
     Xslt xslt = new Xslt(xslTransform);
     XmlOutput output = xslt.Transform(xmlToTransform);
     AssertXmlEquals(expectedResult, output.AsXml());
 }
Пример #24
0
 public void NotEqualsADifferentClass()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(false, input.Equals(INPUT));
 }
Пример #25
0
 public static void AssertXmlEquals(XmlInput controlInput, XmlInput testInput)
 {
     AssertXmlEquals(new XmlDiff(controlInput, testInput));
 }
Пример #26
0
 public void EqualsCopyOfSelf()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(new XmlInput(INPUT), input);
 }
Пример #27
0
 public static void AssertXmlIdentical(XmlInput controlInput, XmlInput testInput)
 {
     AssertXmlIdentical(new XmlDiff(controlInput, testInput));
 }
Пример #28
0
 public Validator(XmlInput input) :
     this(input.CreateXmlReader())
 {
 }
 public static XmlInputXPathAssertionWrapper AppliedTo(this string xPath, XmlInput original)
 {
     return new XmlInputXPathAssertionWrapper(original, xPath);
 }