Author: igorz
Date: 2006-12-07 09:43:19 -0500 (Thu, 07 Dec 2006)
New Revision: 69180

Modified:
   trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/ChangeLog
   trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/NunitWebTest.cs
   trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/XmlComparer.cs
Log:
2006-12-07  Igor Zelmanovich  <[EMAIL PROTECTED]>

        * XmlComparer.cs:
        * NunitWebTest.cs:      fixed HtmlComparer              



Modified: trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/ChangeLog  
2006-12-07 14:22:10 UTC (rev 69179)
+++ trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/ChangeLog  
2006-12-07 14:43:19 UTC (rev 69180)
@@ -1,3 +1,8 @@
+2006-12-07  Igor Zelmanovich  <[EMAIL PROTECTED]>
+
+       * XmlComparer.cs:
+       * NunitWebTest.cs:      fixed HtmlComparer              
+
 2006-10-30  Andrew Skiba  <[EMAIL PROTECTED]>
 
        * NunitWebTest.cs: fallback for HtmlCompare to the text diff

Modified: 
trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/NunitWebTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/NunitWebTest.cs    
2006-12-07 14:22:10 UTC (rev 69179)
+++ trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/NunitWebTest.cs    
2006-12-07 14:43:19 UTC (rev 69180)
@@ -86,19 +86,20 @@
 
                public static void AssertAreEqual (string origin, string 
derived, string msg)
                {
-                       bool test = false;
-                       try {
-                               test = HtmlComparer (origin, derived);
-                       }
-                       catch (Exception e) {
-                               //swallow e when there is XML error and fallback
-                               //to the text comparison
+                       bool test = false;
+                       try {
+                               test = HtmlComparer (origin, derived);
                        }
-                       if (!test) {
+                       catch (Exception e) {
+                               //swallow e when there is XML error and fallback
+                               //to the text comparison
+                               Assert.AreEqual (origin, derived, msg);
+                       }
+                       if (!test) {
                                Assert.AreEqual (_compareExpect, 
_compareActual, msg);
                        }
-               }
-
+               }
+
                private static bool HtmlComparer (string origin, string derived)
                {
                        XmlDocument or = new XmlDocument ();
@@ -122,46 +123,46 @@
                        _compareActual = comparer.Actual;
                        _compareExpect = comparer.Expected;
                        return c;
-               }
-
-               public string HtmltoXml (string html) //throws XmlException
-               {
-                       HtmlAgilityPack.HtmlDocument doc = new 
HtmlAgilityPack.HtmlDocument ();
-                       doc.LoadHtml (html.Trim (new char[] { '\r', '\n', ' ' 
})); // bug in HtmlAgilityPack
-
-                       StringBuilder fixedxml = new StringBuilder ();
-                       StringWriter sw = new StringWriter (fixedxml);
-
-                       StringBuilder tempxml = new StringBuilder ();
-                       StringWriter tsw = new StringWriter (tempxml);
-
-                       doc.OptionOutputAsXml = true;
-                       doc.Save (tsw);
-
-                       // fix style attribute
-                       // the reason is that style attribute name-value pairs 
come in different order
-                       // in .NET and GH
-                       // Here I will sort the values of style attribute
-                       XmlDocument tempDoc = new XmlDocument ();
-                       tempDoc.LoadXml (tempxml.ToString ());
-
-                       XmlNodeList allNodes = tempDoc.SelectNodes ("//*");
-                       foreach (XmlNode n in allNodes) {
-                               if (n.Attributes["style"] != null) {
-                                       string att = 
n.Attributes["style"].Value;
-                                       string[] style = att.Trim (new char[] { 
' ', ';' }).Split (';');
-
-                                       for (int styleIndex = 0; styleIndex < 
style.Length; styleIndex++) {
-                                               style[styleIndex] = 
FixStyleNameValue (style[styleIndex]);
-                                       }
-                                       Array.Sort (style);
-                                       n.Attributes["style"].Value = 
string.Join (";", style);
-                               }
-                       }
-                       tempDoc.Save (sw);
-                       return fixedxml.ToString ();
                }
 
+               public string HtmltoXml (string html) //throws XmlException
+               {
+                       HtmlAgilityPack.HtmlDocument doc = new 
HtmlAgilityPack.HtmlDocument ();
+                       doc.LoadHtml (html.Trim (new char[] { '\r', '\n', ' ' 
})); // bug in HtmlAgilityPack
+
+                       StringBuilder fixedxml = new StringBuilder ();
+                       StringWriter sw = new StringWriter (fixedxml);
+
+                       StringBuilder tempxml = new StringBuilder ();
+                       StringWriter tsw = new StringWriter (tempxml);
+
+                       doc.OptionOutputAsXml = true;
+                       doc.Save (tsw);
+
+                       // fix style attribute
+                       // the reason is that style attribute name-value pairs 
come in different order
+                       // in .NET and GH
+                       // Here I will sort the values of style attribute
+                       XmlDocument tempDoc = new XmlDocument ();
+                       tempDoc.LoadXml (tempxml.ToString ());
+
+                       XmlNodeList allNodes = tempDoc.SelectNodes ("//*");
+                       foreach (XmlNode n in allNodes) {
+                               if (n.Attributes["style"] != null) {
+                                       string att = 
n.Attributes["style"].Value;
+                                       string[] style = att.Trim (new char[] { 
' ', ';' }).Split (';');
+
+                                       for (int styleIndex = 0; styleIndex < 
style.Length; styleIndex++) {
+                                               style[styleIndex] = 
FixStyleNameValue (style[styleIndex]);
+                                       }
+                                       Array.Sort (style);
+                                       n.Attributes["style"].Value = 
string.Join (";", style);
+                               }
+                       }
+                       tempDoc.Save (sw);
+                       return fixedxml.ToString ();
+               }
+
                private string FixStyleNameValue(string nameValue)
                {
                        string [] nv = nameValue.Split(':');
@@ -182,23 +183,23 @@
                        if (_xmlIgnoreList == null)
                        {
                                _xmlIgnoreList = new XmlDocument();
-                               string xml;
-
-                               Stream source = Assembly.GetExecutingAssembly ()
-                                       .GetManifestResourceStream 
("HtmlCompare.nunitweb_config.xml");
-                               if (source == null) {
-                                       source = Assembly.GetExecutingAssembly 
()
-                                       .GetManifestResourceStream 
("nunitweb_config.xml");
-                               }
-                                                               
-                               try {
-                                       using (StreamReader sr = new 
StreamReader (source))
-                                               xml = sr.ReadToEnd ();
-                               }
-                               finally {
-                                       source.Close ();
-                               }
-                               
+                               string xml;
+
+                               Stream source = Assembly.GetExecutingAssembly ()
+                                       .GetManifestResourceStream 
("HtmlCompare.nunitweb_config.xml");
+                               if (source == null) {
+                                       source = Assembly.GetExecutingAssembly 
()
+                                       .GetManifestResourceStream 
("nunitweb_config.xml");
+                               }
+                                                               
+                               try {
+                                       using (StreamReader sr = new 
StreamReader (source))
+                                               xml = sr.ReadToEnd ();
+                               }
+                               finally {
+                                       source.Close ();
+                               }
+                               
                                _xmlIgnoreList.LoadXml (xml);
                        }
                        // Remove by Id or Name

Modified: 
trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/XmlComparer.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/XmlComparer.cs     
2006-12-07 14:22:10 UTC (rev 69179)
+++ trunk/mcs/class/System.Web/Test/mainsoft/MainsoftWebTest/XmlComparer.cs     
2006-12-07 14:43:19 UTC (rev 69180)
@@ -32,20 +32,20 @@
 
                public XmlComparer () : this (Flags.IgnoreAttribOrder)
                {
-               }
-
+               }
+
                public bool AreEqualAttribs (XmlAttributeCollection expected, 
XmlAttributeCollection actual)
                {
                        if (expected.Count != actual.Count)
                                return false;
                        for (int i=0; i<expected.Count; i++) {
-                               if ((flags & Flags.IgnoreAttribOrder) != 0) {
+                               if ((flags & Flags.IgnoreAttribOrder) != 0) {
                                        string ln = expected[i].LocalName;
                                        string ns = expected[i].NamespaceURI;
-                                       string val = expected[i].Value;
-                                       _expected = ns+":"+ln+"="+val;
-                                       XmlAttribute atr2 = actual[ln, ns];
-                                       _actual = atr2 == null ? "<<missing>>" 
: ns + ":" + ln + "=" + atr2.Value;
+                                       string val = expected[i].Value;
+                                       _expected = ns+":"+ln+"="+val;
+                                       XmlAttribute atr2 = actual[ln, ns];
+                                       _actual = atr2 == null ? "<<missing>>" 
: ns + ":" + ln + "=" + atr2.Value;
                                        if (atr2 == null || 
atr2.Value.Trim().ToLower() != val.Trim().ToLower())
                                                return false;
                                } else {
@@ -89,6 +89,9 @@
                        if (expected.Attributes != null && actual.Attributes != 
null) {
                                if (!AreEqualAttribs (expected.Attributes, 
actual.Attributes))
                                        return false;
+
+                               _actual = actual.OuterXml;
+                               _expected = expected.OuterXml;
                        }
                        else //one of nodes has no attrs
                                if (expected.Attributes != null || 
actual.Attributes != null)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to