Exemple #1
0
 public XmlDiff(XmlInput control, XmlInput test,
                DiffConfiguration diffConfiguration)
 {
     _diffConfiguration = diffConfiguration;
     controlInput = control;
     testInput = test;
 }
Exemple #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();
     }
 }
Exemple #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;
        }
 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();
     }
 }
 public void HashCodeEqualsHashCodeOfInput()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(INPUT.GetHashCode(), input.GetHashCode());
 }
 public void EqualsSelf()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(input, input);
 }
 public void NotEqualsNull()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(false, input.Equals(null));
 }
 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;
 }
Exemple #11
0
 private XPathNavigator GetNavigator(XmlInput forXmlInput)
 {
     XPathDocument xpathDocument =
         new XPathDocument(forXmlInput.CreateXmlReader());
     return xpathDocument.CreateNavigator();
 }
Exemple #12
0
 private XPathNodeIterator GetNodeIterator(XmlInput forXmlInput)
 {
     XPathNavigator xpathNavigator = GetNavigator(forXmlInput);
     return xpathNavigator.Select(_xPathExpression);
 }
Exemple #13
0
 public bool XPathExists(XmlInput forInput)
 {
     XPathNodeIterator iterator = GetNodeIterator(forInput);
     return (iterator.Count > 0);
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #21
0
 public static void AssertXPathExists(string anXPathExpression, XmlInput inXml)
 {
     XPath xpath = new XPath(anXPathExpression);
     True(xpath.XPathExists(inXml));
 }
Exemple #22
0
 public static void AssertXPathEvaluatesTo(string anXPathExpression, XmlInput inXml,
                                           string expectedValue)
 {
     XPath xpath = new XPath(anXPathExpression);
     Equal(expectedValue, xpath.EvaluateXPath(inXml));
 }
Exemple #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());
 }
 public void NotEqualsADifferentClass()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(false, input.Equals(INPUT));
 }
Exemple #25
0
 public static void AssertXmlEquals(XmlInput controlInput, XmlInput testInput)
 {
     AssertXmlEquals(new XmlDiff(controlInput, testInput));
 }
 public void EqualsCopyOfSelf()
 {
     XmlInput input = new XmlInput(INPUT);
     Assert.Equal(new XmlInput(INPUT), input);
 }
Exemple #27
0
 public static void AssertXmlIdentical(XmlInput controlInput, XmlInput testInput)
 {
     AssertXmlIdentical(new XmlDiff(controlInput, testInput));
 }
Exemple #28
0
 public Validator(XmlInput input) :
     this(input.CreateXmlReader())
 {
 }
 public static XmlInputXPathAssertionWrapper AppliedTo(this string xPath, XmlInput original)
 {
     return new XmlInputXPathAssertionWrapper(original, xPath);
 }