Exemple #1
0
        public static void VerifyTest(string actResult, string expResult)
        {
            XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff();
            diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder;

            XmlTextReader xrActual = new XmlTextReader(new StringReader(actResult));
            XmlTextReader xrExpected = new XmlTextReader(new StringReader(expResult));

            bool bResult = false;

            try
            {
                bResult = diff.Compare(xrActual, xrExpected);
            }
            catch (Exception e)
            {
                bResult = false;
                s_output.WriteLine("Exception thrown in XmlDiff compare!");
                s_output.WriteLine(e.ToString());
            }
            finally
            {
                if (xrActual != null) xrActual.Dispose();
                if (xrExpected != null) xrExpected.Dispose();
            }

            s_output.WriteLine("Expected : " + expResult);
            s_output.WriteLine("Actual : " + actResult);

            if (bResult)
                return;
            else
                Assert.True(false);
        }
Exemple #2
0
        public static bool CompareXml(Stream expectedStream, Stream actualStream, string xmldiffoptionvalue, DelayedWriteLogger logger)
        {
            bool bResult = false;

            // Default Diff options used by XSLT V2 driver.
            int defaultXmlDiffOptions = (int)(XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder);
            XmlDiff diff = new XmlDiff();

            if (xmldiffoptionvalue == null || xmldiffoptionvalue.Equals(string.Empty))
                diff.Option = (XmlDiffOption)defaultXmlDiffOptions;
            else
            {
                if (logger != null) logger.LogMessage("Custom XmlDiffOptions used. Value passed is " + xmldiffoptionvalue);
                diff.Option = (XmlDiffOption)Int32.Parse(xmldiffoptionvalue);
            }

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            try
            {
                bResult =
                   diff.Compare(new XmlTextReader(actualStream, XmlNodeType.Element, context),
                             new XmlTextReader(expectedStream, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                bResult = false;
                if (logger != null)
                {
                    logger.LogMessage("Exception thrown in XmlDiff compare!");
                    logger.LogXml(e.ToString());
                    throw;
                }
            }

            if (bResult)
                return true;

            if (logger != null)
            {
                logger.LogMessage("Mismatch in XmlDiff");
                logger.LogMessage("Actual result: ");
            }

            return false;
        }
Exemple #3
0
        public void VerifyResult(string actualFile, string baselineFile)
        {
            XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff();
            diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder;

            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            using (FileStream fsActual = new FileStream(actualFile, FileMode.Open, FileAccess.Read))
            {
                using (FileStream fsExpected = new FileStream(baselineFile, FileMode.Open, FileAccess.Read))
                {
                    XmlTextReader xrActual = new XmlTextReader(fsActual, XmlNodeType.Element, context);
                    XmlTextReader xrExpected = new XmlTextReader(fsExpected, XmlNodeType.Element, context);

                    bool bResult = false;

                    try
                    {
                        bResult = diff.Compare(xrActual, xrExpected);
                    }
                    catch (Exception e)
                    {
                        bResult = false;
                        s_output.WriteLine("Exception thrown in XmlDiff compare!");
                        s_output.WriteLine(e.ToString());
                    }
                    s_output.WriteLine("Actual result: ");
                    this.WriteFile(actualFile);

                    if (bResult)
                        return;
                    else
                    {
                        s_output.WriteLine("Mismatch in XmlDiff");
                        Assert.True(false);
                    }
                }
            }
        }
Exemple #4
0
        //VerifyResult which compares 2 arguments using XmlDiff.
        public void VerifyResult(string baseline, string outputFile)
        {
            bool bResult = false;
            FileStream fsExpected;

            baseline = FullFilePath(baseline);

            XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff();
            diff.Option = XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.IgnoreAttributeOrder | XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreWhitespace;
            XmlParserContext context = new XmlParserContext(new NameTable(), null, "", XmlSpace.None);

            fsExpected = new FileStream(baseline, FileMode.Open, FileAccess.Read, FileShare.Read);
            FileStream fsActual = new FileStream(outputFile, FileMode.Open, FileAccess.Read, FileShare.Read);

            _output.WriteLine("Verifying o/p with baseline result {0}...", baseline);
            try
            {
                bResult = diff.Compare(new XmlTextReader(fsActual, XmlNodeType.Element, context), new XmlTextReader(fsExpected, XmlNodeType.Element, context));
            }
            catch (Exception e)
            {
                // TO DO: Write exception msgs in ignore tags
                _output.WriteLine(e.ToString());
            }
            finally
            {
                fsExpected.Dispose();
                fsActual.Dispose();
            }
            if (!bResult)
            {
                // Write out the actual and expected o/p
                _output.WriteLine("Expected o/p: ");
                using (StreamReader sr = new StreamReader(new FileStream(baseline, FileMode.Open, FileAccess.Read)))
                {
                    string baseLine = sr.ReadToEnd();
                    _output.WriteLine(baseLine);
                }
                _output.WriteLine("Actual o/p: ");
                using (StreamReader sr = new StreamReader(new FileStream(outputFile, FileMode.Open, FileAccess.Read)))
                {
                    string output = sr.ReadToEnd();
                    _output.WriteLine(output);
                }

                using (StreamWriter sw = new StreamWriter(new FileStream("diff.xml", FileMode.Open, FileAccess.Read)))
                {
                    sw.WriteLine("<?xml-stylesheet href='diff.xsl' type='text/xsl'?>");
                    sw.WriteLine(diff.ToXml());
                }
            }

            if (bResult)
                return;
            else
            {
                _output.WriteLine("**** Baseline mis-matched ****");
                Assert.True(false);
            }
        }
Exemple #5
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver_Evidence
        //  -------------------------------------------------------------------------------------------------------------
        /*public int LoadXSL_Resolver_Evidence(String _strXslFile, XmlResolver xr, Evidence e)
        {
            _strXslFile = FullFilePath(_strXslFile);
            xslt = new XslCompiledTransform();

            switch (_nInputXsl)
            {
                case XslInputType.Reader:
                    switch (_readerType)
                    {
                        case ReaderType.XmlTextReader:
                            XmlReader trTemp = XmlReader.Create(_strXslFile);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlTextReader " + _strXslFile);
                                //xslt.Load(trTemp, xr, e); //Evidence is not supported on V2 XSLT Load
                                xslt.Load(trTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (trTemp != null)
                                    trTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlNodeReader:
                            XmlDocument docTemp = new XmlDocument();
                            docTemp.Load(_strXslFile);
                            XmlNodeReader nrTemp = new XmlNodeReader(docTemp);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlNodeReader " + _strXslFile);
                                //xslt.Load(nrTemp, xr, e); Evidence is not supported in V2 XSLT Load
                                xslt.Load(nrTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (nrTemp != null)
                                    nrTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlValidatingReader:
                        default:
                            XmlReaderSettings xrs = new XmlReaderSettings();
#pragma warning disable 0618
                            xrs.ProhibitDtd = false;
#pragma warning restore 0618
                            XmlReader vrTemp = null;
                            try
                            {
                                vrTemp = XmlReader.Create(_strXslFile, xrs);
                                _output.WriteLine("Loading style sheet as XmlValidatingReader " + _strXslFile);
                                //xslt.Load(vrTemp, xr, e); Evidence is not supported in V2 XSLT Load
                                xslt.Load(vrTemp, XsltSettings.TrustedXslt, xr);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (vrTemp != null)
                                    vrTemp.Dispose();
                            }
                            break;
                    }
                    break;

                case XslInputType.Navigator:
                    XmlReader xrLoad = XmlReader.Create(_strXslFile);
                    XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve);
                    xrLoad.Dispose();
                    _output.WriteLine("Loading style sheet as Navigator " + _strXslFile);
                    xslt.Load(xdTemp.CreateNavigator(), XsltSettings.TrustedXslt, xr);
                    break;
            }
            return 1;
        }*/

        //VerifyResult
        public void VerifyResult(string expectedValue)
        {
            XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff();
            xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement;

            StreamReader sr = new StreamReader(new FileStream("out.xml", FileMode.Open, FileAccess.Read));
            string actualValue = sr.ReadToEnd();
            sr.Dispose();

            //Output the expected and actual values
            _output.WriteLine("Expected : " + expectedValue);
            _output.WriteLine("Actual : " + actualValue);

            //Load into XmlTextReaders
            XmlTextReader tr1 = new XmlTextReader("out.xml");
            XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue));

            bool bResult = xmldiff.Compare(tr1, tr2);

            //Close the readers
            tr1.Dispose();
            tr2.Dispose();

            if (bResult)
                return;
            else
                Assert.True(false);
        }
Exemple #6
0
        public void OS11(object param0, object param1)
        {
            Init(param0.ToString(), param1.ToString());
            _xsl.Load(_xslFile);

            //Transform to Stream
            Stream stm1 = new FileStream("out1.xml", FileMode.Create, FileAccess.ReadWrite);
            _output.WriteLine("Transforming to Stream1 - 'out1.xml'");
            _xsl.Transform(_xmlFile, null, stm1);

            //Create an XmlWriter using OutputSettings
            Stream stm2 = new FileStream("out2.xml", FileMode.Create, FileAccess.ReadWrite);

            XmlWriterSettings os = _xsl.OutputSettings;
            XmlWriter xw = XmlWriter.Create(stm2, os);

            //Transform to XmlWriter
            _output.WriteLine("Transforming to XmlWriter over Stream2 with XSLT	OutputSettings - 'out2.xml'");
            _xsl.Transform(_xmlFile, null, xw);

            //Close the streams
            stm1.Dispose();
            stm2.Dispose();

            //XmlDiff the 2 Outputs.
            XmlDiff.XmlDiff diff = new XmlDiff.XmlDiff();
            XmlReader xr1 = XmlReader.Create("out1.xml");
            XmlReader xr2 = XmlReader.Create("out2.xml");

            //XmlDiff
            _output.WriteLine("Comparing the Stream Output and XmlWriter Output");
            Assert.True(diff.Compare(xr1, xr2));

            //Delete the temp files
            xr1.Dispose();
            xr2.Dispose();
            File.Delete("out1.xml");
            File.Delete("out2.xml");

            return;
        }
Exemple #7
0
 //[Variation(Desc = "Manually declared prefix-namespace pair is not reflected in the XElement serialization")]
 public void ManuallyDeclaredPrefixNamespacePairIsNotReflectedInTheXElementSerialization()
 {
     var element = XElement.Parse("<A/>");
     element.Add(new XAttribute(XNamespace.Xmlns + "p", "ns"));
     element.Add(new XElement("{ns}B", null));
     MemoryStream sourceStream = new MemoryStream();
     element.Save(sourceStream);
     sourceStream.Position = 0;
     // creating the following element with expected output so we can compare
     XElement target = XElement.Parse("<A xmlns:p=\"ns\"><p:B /></A>");
     MemoryStream targetStream = new MemoryStream();
     target.Save(targetStream);
     targetStream.Position = 0;
     XmlDiff diff = new XmlDiff();
     if (!diff.Compare(sourceStream, targetStream))
         throw new TestException(TestResult.Failed, "");
 }
Exemple #8
0
        // --------------------------------------------------------------------------------------------------------------
        //  LoadXSL_Resolver_Evidence
        //  -------------------------------------------------------------------------------------------------------------
        /*public int LoadXSL_Resolver_Evidence(String _strXslFile, XmlResolver xr, Evidence e)
        {
            _strXslFile = FullFilePath(_strXslFile);
#pragma warning disable 0618
            xslt = new XslTransform();
#pragma warning restore 0618

            switch (_nInput)
            {
                case InputType.Reader:
                    switch (_readerType)
                    {
                        case ReaderType.XmlTextReader:
                            XmlTextReader trTemp = new XmlTextReader(_strXslFile);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlTextReader {0}", _strXslFile);
                                xslt.Load(trTemp, xr, e);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (trTemp != null)
                                    trTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlNodeReader:
                            XmlDocument docTemp = new XmlDocument();
                            docTemp.Load(_strXslFile);
                            XmlNodeReader nrTemp = new XmlNodeReader(docTemp);
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlNodeReader {0}", _strXslFile);
                                xslt.Load(nrTemp, xr, e);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (nrTemp != null)
                                    nrTemp.Dispose();
                            }
                            break;

                        case ReaderType.XmlValidatingReader:
                        default:
#pragma warning disable 0618
                            XmlValidatingReader vrTemp = new XmlValidatingReader(new XmlTextReader(_strXslFile));
#pragma warning restore 0618
                            vrTemp.ValidationType = ValidationType.None;
                            vrTemp.EntityHandling = EntityHandling.ExpandEntities;
                            try
                            {
                                _output.WriteLine("Loading style sheet as XmlValidatingReader {0}", _strXslFile);
                                xslt.Load(vrTemp, xr, e);
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (vrTemp != null)
                                    vrTemp.Dispose();
                            }
                            break;
                    }
                    break;

                case InputType.Navigator:
#pragma warning disable 0618
                    XmlValidatingReader xrLoad = new XmlValidatingReader(new XmlTextReader(_strXslFile));
#pragma warning restore 0618
                    XPathDocument xdTemp = new XPathDocument(xrLoad, XmlSpace.Preserve);
                    xrLoad.Dispose();
                    _output.WriteLine("Loading style sheet as Navigator {0}", _strXslFile);
                    xslt.Load(xdTemp.CreateNavigator(), xr, e);
                    break;
            }
            return 1;
        }*/

        //VerifyResult
        public void VerifyResult(string expectedValue)
        {
            lock(s_outFileMemoryLock)
            {
                XmlDiff.XmlDiff xmldiff = new XmlDiff.XmlDiff();
                xmldiff.Option = XmlDiffOption.InfosetComparison | XmlDiffOption.IgnoreEmptyElement | XmlDiffOption.NormalizeNewline;
                
                string actualValue = File.ReadAllText(_strOutFile);
                
                //Output the expected and actual values
                _output.WriteLine("Expected : " + expectedValue);
                _output.WriteLine("Actual : " + actualValue);
                
                bool result;

                //Load into XmlTextReaders
                using (XmlTextReader tr1 = new XmlTextReader(_strOutFile))
                using (XmlTextReader tr2 = new XmlTextReader(new StringReader(expectedValue)))
                {
                    result = xmldiff.Compare(tr1, tr2);
                }

                Assert.True(result);
            }
        }
Exemple #9
0
        public bool CompareReader(XmlReader xrExpected, XmlDiffOption option)
        {
            bool bReturn = false;

            XmlReader xrActual = GetReader();

            XmlDiff diff = new XmlDiff();
            diff.Option = option;

            try
            {
                bReturn = diff.Compare(xrExpected, xrActual);
            }
            catch (Exception e)
            {
                CError.WriteLine(e);
            }
            finally
            {
                xrActual.Dispose();
                xrExpected.Dispose();
            }
            if (!bReturn)
            {
                CError.WriteLine("Mismatch in XmlDiff");
                CError.WriteLine("Actual o/p:");
                CError.WriteLine(this.GetString());
            }

            return bReturn;
        }