In Test/System.Net:
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 24 Dec 2009 15:24:13 +0000 (15:24 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 24 Dec 2009 15:24:13 +0000 (15:24 -0000)
2009-12-24  Sebastien Pouliot  <sebastien@ximian.com>

* CookieContainerTest.cs: Split many tests into smaller test
cases. Add test cases for DefaultPerDomainCookieLimit and
DefaultCookieLimit. Remove all [Category ("NotWorking")] since
everything works now.

In System.Net:
2009-12-24  Sebastien Pouliot  <sebastien@ximian.com>

* Cookie.cs: Re-work ToString to be useable in more cases. Fix
some issues found by Gendarme.
* CookieContainer.cs: Fix all NonWorking (and new) unit tests.
Implement removing oldest cookies when limits are reached.
* CookieCollection.cs: Move to generics internally. Fix sort to
be closer to MS implementation (but still not 100% identical).
Fix some issues found by Gendarme.

svn path=/trunk/mcs/; revision=148891

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/Cookie.cs
mcs/class/System/System.Net/CookieCollection.cs
mcs/class/System/System.Net/CookieContainer.cs
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/CookieContainerTest.cs

index da2cd79773d88a08dd982a736227993883ca7469..790e57c88c3093c05eb9b344b20e81748190cb3a 100644 (file)
@@ -1,3 +1,13 @@
+2009-12-24  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Cookie.cs: Re-work ToString to be useable in more cases. Fix
+       some issues found by Gendarme.
+       * CookieContainer.cs: Fix all NonWorking (and new) unit tests.
+       Implement removing oldest cookies when limits are reached.
+       * CookieCollection.cs: Move to generics internally. Fix sort to 
+       be closer to MS implementation (but still not 100% identical).
+       Fix some issues found by Gendarme.
+
 2009-12-21 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * WebConnectionGroup.cs:
index 02bd572f98d01db7aef2a8e3cbc48a76c6311197..e55289535fb69cf32dbfa0f5aca24262b4271bf8 100644 (file)
@@ -5,8 +5,9 @@
 //     Lawrence Pit (loz@cable.a2000.nl)
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //      Daniel Nauck    (dna(at)mono-project(dot)de)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// (c) Copyright 2004 Novell, Inc. (http://www.ximian.com)
+// Copyright (C) 2004,2009 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -48,11 +49,8 @@ namespace System.Net {
                Uri commentUri;
                bool discard;
                string domain;
-//             bool expired;
                DateTime expires;
-#if NET_2_0            
                bool httpOnly;
-#endif         
                string name;
                string path;
                string port;
@@ -70,11 +68,11 @@ namespace System.Net {
                {
                        expires = DateTime.MinValue;
                        timestamp = DateTime.Now;
-                       domain = "";
-                       name = "";
-                       val = "";
-                       comment = "";
-                       port = "";
+                       domain = String.Empty;
+                       name = String.Empty;
+                       val = String.Empty;
+                       comment = String.Empty;
+                       port = String.Empty;
                }
 
                public Cookie (string name, string value)
@@ -113,9 +111,19 @@ namespace System.Net {
 
                public string Domain {
                        get { return domain; }
-                       set { domain = value == null ? String.Empty : value; }
+                       set {
+                               if (String.IsNullOrEmpty (value)) {
+                                       domain = String.Empty;
+                                       ExactDomain = true;
+                               } else {
+                                       domain = value;
+                                       ExactDomain = (value [0] != '.');
+                               }
+                       }
                }
 
+               internal bool ExactDomain { get; set; }
+
                public bool Expired {
                        get { 
                                return expires <= DateTime.Now && 
@@ -132,20 +140,16 @@ namespace System.Net {
                        set { expires = value; }
                }
 
-#if NET_2_0    
-               public bool HttpOnly
-               {
+               public bool HttpOnly {
                        get { return httpOnly; }
                        set { httpOnly = value; }
                }
-#endif
 
                public string Name {
                        get { return name; }
                        set { 
-                               if (value == null || value.Length == 0) {
+                               if (String.IsNullOrEmpty (value))
                                        throw new CookieException ("Name cannot be empty");
-                               }                       
                                
                                if (value [0] == '$' || value.IndexOfAny (reservedCharsName) != -1) {
                                        // see CookieTest, according to MS implementation
@@ -159,14 +163,14 @@ namespace System.Net {
                }
 
                public string Path {
-                       get { return (path == null || path == "") ? String.Empty : path; }
+                       get { return (path == null) ? String.Empty : path; }
                        set { path = (value == null) ? String.Empty : value; }
                }
 
                public string Port {
                        get { return port; }
                        set { 
-                               if (value == null || value.Length == 0) {
+                               if (String.IsNullOrEmpty (value)) {
                                        port = String.Empty;
                                        return;
                                }
@@ -264,6 +268,11 @@ namespace System.Net {
                // see para 4.2.2 of RFC 2109 and para 3.3.4 of RFC 2965
                // see also bug #316017
                public override string ToString () 
+               {
+                       return ToString (null);
+               }
+
+               internal string ToString (Uri uri)
                {
                        if (name.Length == 0) 
                                return String.Empty;
@@ -278,10 +287,13 @@ namespace System.Net {
                        if (version == 0)
                                return result.ToString ();
 
-                       if (path != null && path.Length != 0)
+                       if (!String.IsNullOrEmpty (path))
                                result.Append ("; $Path=").Append (path);
-                               
-                       if (domain != null && domain.Length != 0)
+                       else if (uri != null)
+                               result.Append ("; $Path=/").Append (path);
+
+                       bool append_domain = (uri == null) || (uri.Host != domain);
+                       if (append_domain && !String.IsNullOrEmpty (domain))
                                result.Append ("; $Domain=").Append (domain);                   
        
                        if (port != null && port.Length != 0)
index 4c5b30f6d5f5248e40f84dc2e26d9f4d72de1146..a8fec602f23aa5488cc80b4dc6203ef298b392b7 100644 (file)
@@ -4,8 +4,9 @@
 // Authors:
 //     Lawrence Pit (loz@cable.a2000.nl)
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// (c) Copyright 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (C) 2004,2009 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -29,8 +30,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Globalization;
 using System.Runtime.Serialization;
 
@@ -42,23 +43,25 @@ namespace System.Net
 #else
        public class CookieCollection : ICollection, IEnumerable {
 #endif
-               sealed class CookieCollectionPathComparer : IComparer
-               {
-                       int IComparer.Compare (object p1, object p2)
+               // not 100% identical to MS implementation
+               sealed class CookieCollectionComparer : IComparer<Cookie> {
+                       public int Compare (Cookie x, Cookie y)
                        {
-                               Cookie c1 = p1 as Cookie;
-                               Cookie c2 = p2 as Cookie;
-
-                               if (c1 == null || c2 == null)
+                               if (x == null || y == null)
                                        return 0;
                                
-                               return (c2.Path.Length - c1.Path.Length);
+                               int c1 = x.Name.Length + x.Value.Length;
+                               int c2 = y.Name.Length + y.Value.Length;
+
+                               return (c1 - c2);
                        }
                }
-               
-               ArrayList list = new ArrayList (4);
 
-               internal ArrayList List {
+               static CookieCollectionComparer Comparer = new CookieCollectionComparer ();
+
+               List<Cookie> list = new List<Cookie> ();
+
+               internal IList<Cookie> List {
                        get { return list; }
                }
                // ICollection
@@ -74,17 +77,15 @@ namespace System.Net
                        get { return this; }
                }
 
-               public void CopyTo (Array array, int arrayIndex)
+               public void CopyTo (Array array, int index)
                {
-                       list.CopyTo (array, arrayIndex);
+                       (list as IList).CopyTo (array, index);
                }
 
-#if NET_2_0
                public void CopyTo (Cookie [] array, int index)
                {
                        list.CopyTo (array, index);
                }
-#endif
 
                // IEnumerable
                public IEnumerator GetEnumerator ()
@@ -113,12 +114,10 @@ namespace System.Net
                                list [pos] = cookie;
                }
 
-               internal void SortByPath ()
+               internal void Sort ()
                {
-                       if (list == null || list.Count == 0)
-                               return;
-
-                       list.Sort (new CookieCollectionPathComparer ());
+                       if (list.Count > 0)
+                               list.Sort (Comparer);
                }
                
                int SearchCookie (Cookie cookie)
@@ -128,7 +127,7 @@ namespace System.Net
                        string path = cookie.Path;
 
                        for (int i = list.Count - 1; i >= 0; i--) {
-                               Cookie c = (Cookie) list [i];
+                               Cookie c = list [i];
                                if (c.Version != cookie.Version)
                                        continue;
 
@@ -161,7 +160,7 @@ namespace System.Net
                                if (index < 0 || index >= list.Count)
                                        throw new ArgumentOutOfRangeException ("index");
 
-                               return (Cookie) list [index];
+                               return list [index];
                        }
                }
 
index d8a1222e407c992d24128e80acf12c3b3e900834..db816b82f55fb4decffec99bdf5849b40025b556 100644 (file)
@@ -4,10 +4,11 @@
 // Authors:
 //     Lawrence Pit (loz@cable.a2000.nl)
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
 // (c) Copyright 2004 Ximian, Inc. (http://www.ximian.com)
-//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -39,7 +40,6 @@ using System.Text;
 namespace System.Net 
 {
        [Serializable]
-       [MonoTODO ("Need to remove older/unused cookies if it reaches the maximum capacity")]
 #if NET_2_1
        public sealed class CookieContainer {
 #else
@@ -49,7 +49,6 @@ namespace System.Net
                public const int DefaultCookieLimit = 300;
                public const int DefaultPerDomainCookieLimit = 20;
 
-               int count;
                int capacity = DefaultCookieLimit;
                int perDomainCapacity = DefaultPerDomainCookieLimit;
                int maxCookieSize = DefaultCookieLengthLimit;
@@ -99,7 +98,7 @@ namespace System.Net
                // properties
                
                public int Count { 
-                       get { return count; }
+                       get { return (cookies == null) ? 0 : cookies.Count; }
                }
                
                public int Capacity {
@@ -137,7 +136,7 @@ namespace System.Net
                        if (cookie == null)
                                throw new ArgumentNullException ("cookie");
 
-                       if (cookie.Domain == "")
+                       if (cookie.Domain.Length == 0)
 #if NET_2_0
                                throw new ArgumentException ("Cookie domain not set.", "cookie.Domain");
 #else
@@ -155,37 +154,61 @@ namespace System.Net
                        if (cookies == null)
                                cookies = new CookieCollection ();
 
-                       if (count + 1 > capacity)
-                               throw new CookieException ("Capacity exceeded");
+                       if (cookies.Count >= capacity)
+                               RemoveOldest (null);
+
+                       // try to avoid counting per-domain
+                       if (cookies.Count >= perDomainCapacity) {
+                               if (CountDomain (cookie.Domain) >= perDomainCapacity)
+                                       RemoveOldest (cookie.Domain);
+                       }
 
-                       cookies.Add (cookie);
-                       count = cookies.Count;
+                       // clone the important parts of the cookie
+                       Cookie c = new Cookie (cookie.Name, cookie.Value);
+                       c.Path = (cookie.Path.Length == 0) ? "/" : cookie.Path;
+                       c.Domain = cookie.Domain;
+                       c.ExactDomain = cookie.ExactDomain;
+                       c.Version = cookie.Version;
+
+                       cookies.Add (c);
                        CheckExpiration ();
 
                }
 
+               int CountDomain (string domain)
+               {
+                       int count = 0;
+                       foreach (Cookie c in cookies) {
+                               if (CheckDomain (domain, c.Domain, true))
+                                       count++;
+                       }
+                       return count;
+               }
+
+               void RemoveOldest (string domain)
+               {
+                       int n = 0;
+                       DateTime oldest = DateTime.MaxValue;
+                       for (int i = 0; i < cookies.Count; i++) {
+                               Cookie c = cookies [i];
+                               if ((c.TimeStamp < oldest) && ((domain == null) || (domain == c.Domain))) {
+                                       oldest = c.TimeStamp;
+                                       n = i;
+                               }
+                       }
+                       cookies.List.RemoveAt (n);
+               }
+
                // Only needs to be called from AddCookie (Cookie) and GetCookies (Uri)
                void CheckExpiration ()
                {
                        if (cookies == null)
                                return;
 
-                       ArrayList removed = null;
                        for (int i = cookies.Count - 1; i >= 0; i--) {
                                Cookie cookie = cookies [i];
-                               if (cookie.Expired) {
-                                       if (removed == null)
-                                               removed = new ArrayList ();
-                                       removed.Add (i);
-                               }
-                       }
-
-                       if (removed != null) {
-                               // We went backwards above, so this works.
-                               ArrayList list = cookies.List;
-                               foreach (int n in removed) {
-                                       list.RemoveAt (n);
-                               }
+                               if (cookie.Expired)
+                                       cookies.List.RemoveAt (i);
                        }
                }
 
@@ -200,16 +223,16 @@ namespace System.Net
 
                void Cook (Uri uri, Cookie cookie)
                {
-                       if (cookie.Name == null || cookie.Name == "")
+                       if (String.IsNullOrEmpty (cookie.Name))
                                throw new CookieException ("Invalid cookie: name");
 
                        if (cookie.Value == null)
                                throw new CookieException ("Invalid cookie: value");
 
-                       if (uri != null && cookie.Domain == "")
+                       if (uri != null && cookie.Domain.Length == 0)
                                cookie.Domain = uri.Host;
 
-                       if (cookie.Version == 0 && (cookie.Path == null || cookie.Path == "")) {
+                       if (cookie.Version == 0 && String.IsNullOrEmpty (cookie.Path)) {
                                if (uri != null) {
                                        cookie.Path = uri.AbsolutePath;
                                } else {
@@ -217,7 +240,7 @@ namespace System.Net
                                }
                        }
 
-                       if (cookie.Port == "" && uri != null && !uri.IsDefaultPort) {
+                       if (cookie.Port.Length == 0 && uri != null && !uri.IsDefaultPort) {
                                cookie.Port = "\"" + uri.Port.ToString () + "\"";
                        }
                }
@@ -230,8 +253,10 @@ namespace System.Net
                        if (cookie == null)
                                throw new ArgumentNullException ("cookie");
 
-                       Cook (uri, cookie);
-                       AddCookie (cookie);
+                       if (!cookie.Expired) {
+                               Cook (uri, cookie);
+                               AddCookie (cookie);
+                       }
                }
 
                public void Add (Uri uri, CookieCollection cookies)
@@ -242,9 +267,11 @@ namespace System.Net
                        if (cookies == null)
                                throw new ArgumentNullException ("cookies");
 
-                       foreach (Cookie c in cookies) {
-                               Cook (uri, c);
-                               AddCookie (c);
+                       foreach (Cookie cookie in cookies) {
+                               if (!cookie.Expired) {
+                                       Cook (uri, cookie);
+                                       AddCookie (cookie);
+                               }
                        }
                }               
 
@@ -259,7 +286,9 @@ namespace System.Net
 
                        StringBuilder result = new StringBuilder ();
                        foreach (Cookie cookie in coll) {
-                               result.Append (cookie.ToString ());
+                               // don't include the domain since it can be infered from the URI
+                               // include empty path as '/'
+                               result.Append (cookie.ToString (uri));
                                result.Append ("; ");
                        }
 
@@ -269,26 +298,24 @@ namespace System.Net
                        return result.ToString ();
                }
 
-               static bool CheckDomain (string domain, string host)
+               static bool CheckDomain (string domain, string host, bool exact)
                {
-                       if (domain == String.Empty)
-                               return false;
-
-                       int hlen = host.Length;
-                       int dlen = domain.Length;
-                       if (hlen < dlen)
+                       if (domain.Length == 0)
                                return false;
 
-                       if (hlen == dlen)
-                               return (String.Compare (domain, host, true, CultureInfo.InvariantCulture) == 0);
+                       if (exact)
+                               return (String.Compare (host, domain, StringComparison.InvariantCultureIgnoreCase) == 0);
 
-                       if (domain [0] != '.') {
-                               domain = "." + domain;
-                               dlen++;
-                       }
-
-                       string subdomain = host.Substring (hlen - dlen);
-                       return (String.Compare (subdomain, domain, true, CultureInfo.InvariantCulture) == 0);
+                       // check for allowed sub-domains - without string allocations
+                       if (!host.EndsWith (domain, StringComparison.InvariantCultureIgnoreCase))
+                               return false;
+                       // mono.com -> www.mono.com is OK but supermono.com NOT OK
+                       if (domain [0] == '.')
+                               return true;
+                       int p = host.Length - domain.Length - 1;
+                       if (p < 0)
+                               return false;
+                       return (host [p] == '.');
                }
 
                public CookieCollection GetCookies (Uri uri)
@@ -303,10 +330,10 @@ namespace System.Net
 
                        foreach (Cookie cookie in cookies) {
                                string domain = cookie.Domain;
-                               if (!CheckDomain (domain, uri.Host))
+                               if (!CheckDomain (domain, uri.Host, cookie.ExactDomain))
                                        continue;
 
-                               if (cookie.Port != "" && cookie.Ports != null && uri.Port != -1) {
+                               if (cookie.Port.Length > 0 && cookie.Ports != null && uri.Port != -1) {
                                        if (Array.IndexOf (cookie.Ports, uri.Port) == -1)
                                                continue;
                                }
@@ -330,7 +357,7 @@ namespace System.Net
                                coll.Add (cookie);
                        }
 
-                       coll.SortByPath ();
+                       coll.Sort ();
                        return coll;
                }
 
@@ -340,120 +367,79 @@ namespace System.Net
                                throw new ArgumentNullException ("uri");
                        
                        if (cookieHeader == null)
-                               throw new ArgumentNullException ("cookieHeader");
+                               throw new ArgumentNullException ("cookieHeader");                       
                        
-                       ParseAndAddCookies (uri, cookieHeader);
-               }
-
-               // GetCookieValue, GetCookieName and ParseAndAddCookies copied from HttpRequest.cs
-               static string GetCookieValue (string str, int length, ref int i)
-               {
-                       if (i >= length)
-                               return null;
-
-                       int k = i;
-                       while (k < length && Char.IsWhiteSpace (str [k]))
-                               k++;
-
-                       int begin = k;
-                       while (k < length && str [k] != ';')
-                               k++;
-
-                       i = k;
-                       return str.Substring (begin, i - begin).Trim ();
-               }
-
-               static string GetCookieName (string str, int length, ref int i)
-               {
-                       if (i >= length)
-                               return null;
-
-                       int k = i;
-                       while (k < length && Char.IsWhiteSpace (str [k]))
-                               k++;
+                       if (cookieHeader.Length == 0)
+                               return;
+                       
+                       // Cookies must be separated by ',' (like documented on MSDN)
+                       string [] jar = cookieHeader.Split (',');
+                       foreach (string cookie in jar) {
+                               try {
+                                       Cookie c = Parse (cookie);
+
+                                       // add default values from URI if missing from the string
+                                       if (c.Path.Length == 0) {
+                                               c.Path = uri.AbsolutePath;
+                                       } else if (!uri.AbsolutePath.StartsWith (c.Path)) {
+                                               string msg = String.Format ("'Path'='{0}' is invalid with URI", c.Path);
+                                               throw new CookieException (msg);
+                                       }
 
-                       int begin = k;
-                       while (k < length && str [k] != ';' &&  str [k] != '=')
-                               k++;
+                                       if (c.Domain.Length == 0) {
+                                               c.Domain = uri.Host;
+                                               // don't consider domain "a.b.com" as ".a.b.com"
+                                               c.ExactDomain = true;
+                                       }
 
-                       i = k + 1;
-                       return str.Substring (begin, k - begin).Trim ();
+                                       Add (c);
+                               }
+                               catch (Exception e) {
+                                       string msg = String.Format ("Could not parse cookies for '{0}'.", uri);
+                                       throw new CookieException (msg, e);
+                               }
+                       }
                }
 
-               static string GetDir (string path)
+               static Cookie Parse (string s)
                {
-                       if (path == null || path == "")
-                               return "/";
-
-                       int last = path.LastIndexOf ('/');
-                       if (last == -1)
-                               return "/" + path;
-
-                       return path.Substring (0, last + 1);
-               }
-               
-               void ParseAndAddCookies (Uri uri, string header)
-               {
-                       if (header.Length == 0)
-                               return;
+                       string [] parts = s.Split (';');
+                       Cookie c = new Cookie ();
+                       for (int i = 0; i < parts.Length; i++) {
+                               string key, value;
+                               int sep = parts[i].IndexOf ('=');
+                               if (sep == -1) {
+                                       key = parts [i].Trim ();
+                                       value = String.Empty;
+                               } else {
+                                       key = parts [i].Substring (0, sep).Trim ();
+                                       value = parts [i].Substring (sep + 1).Trim ();
+                               }
 
-                       string [] name_values = header.Trim ().Split (';');
-                       int length = name_values.Length;
-                       Cookie cookie = null;
-                       int pos;
-                       CultureInfo inv = CultureInfo.InvariantCulture;
-                       bool havePath = false;
-                       bool haveDomain = false;
-
-                       for (int i = 0; i < length; i++) {
-                               pos = 0;
-                               string name_value = name_values [i].Trim ();
-                               string name = GetCookieName (name_value, name_value.Length, ref pos);
-                               if (name == null || name == "")
-                                       throw new CookieException ("Name is empty.");
-
-                               string value = GetCookieValue (name_value, name_value.Length, ref pos);
-                               if (cookie != null) {
-                                       if (!havePath && String.Compare (name, "$Path", true, inv) == 0 ||
-                                           String.Compare (name, "path", true, inv) == 0) {
-                                               havePath = true;
-                                               cookie.Path = value;
-                                               continue;
+                               switch (key.ToLowerInvariant ()) {
+                               case "path":
+                               case "$path":
+                                       if (c.Path.Length == 0)
+                                               c.Path = value;
+                                       break;
+                               case "domain":
+                               case "$domain":
+                                       if (c.Domain.Length == 0) {
+                                               c.Domain = value;
+                                               // here mono.com means "*.mono.com"
+                                               c.ExactDomain = false;
                                        }
-                                       
-                                       if (!haveDomain && String.Compare (name, "$Domain", true, inv) == 0 ||
-                                           String.Compare (name, "domain", true, inv) == 0) {
-                                               cookie.Domain = value;
-                                               haveDomain = true;
-                                               continue;
+                                       break;
+                               default:
+                                       if (c.Name.Length == 0) {
+                                               c.Name = key;
+                                               c.Value = value;
                                        }
-
-                                       if (!havePath)
-                                               cookie.Path = GetDir (uri.AbsolutePath);
-
-                                       if (!haveDomain)
-                                               cookie.Domain = uri.Host;
-
-                                       havePath = false;
-                                       haveDomain = false;
-                                       Add (cookie);
-                                       cookie = null;
+                                       break;
                                }
-                               cookie = new Cookie (name, value);
-                       }
-
-                       if (cookie != null) {
-                               if (!havePath)
-                                       cookie.Path = GetDir (uri.AbsolutePath);
-
-                               if (!haveDomain)
-                                       cookie.Domain = uri.Host;
-
-                               Add (cookie);
                        }
+                       return c;
                }
-
-       } // CookieContainer
-
-} // System.Net
+       }
+}
 
index 831078775d0700c853e488c8546ee9c886f442a4..75a0aa562c577facae3c48679d50d329028960c4 100644 (file)
@@ -1,3 +1,10 @@
+2009-12-24  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CookieContainerTest.cs: Split many tests into smaller test 
+       cases. Add test cases for DefaultPerDomainCookieLimit and
+       DefaultCookieLimit. Remove all [Category ("NotWorking")] since
+       everything works now.
+
 2009-10-23  Alexandre Gomes  <alexmipego@gmail.com>
 
        * WebClientTest.cs: Test for GetWebRequest overriding
index d96d0cb963addeeb47721a6a2a5cfdadcfdfb7b3..1dfd409b40e76ceda36c1b543527593f229d46d9 100644 (file)
@@ -4,8 +4,9 @@
 // Authors:
 //     Gonzalo Paniagua Javier (gonzalo@novell.com)
 //      Daniel Nauck    (dna(at)mono-project(dot)de)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// (c) Copyright 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (C) 2004,2009 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -14,11 +15,9 @@ using System.Reflection;
 
 using NUnit.Framework;
 
-namespace MonoTests.System.Net
-{
+namespace MonoTests.System.Net {
        [TestFixture]
-       public class CookieContainerTest
-       {
+       public class CookieContainerTest {
                [Test] // .ctor ()
                public void Constructor1 ()
                {
@@ -46,7 +45,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (0);
                                Assert.Fail ("#A1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
 #if NET_2_0
@@ -63,7 +63,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (-10);
                                Assert.Fail ("#B1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
 #if NET_2_0
@@ -81,7 +82,7 @@ namespace MonoTests.System.Net
                public void Constructor3 ()
                {
                        CookieContainer c;
-                       
+
                        c = new CookieContainer (100, 50, 1000);
                        Assert.AreEqual (100, c.Capacity, "#A1");
                        Assert.AreEqual (50, c.PerDomainCapacity, "#A2");
@@ -105,7 +106,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (0, 0, 100);
                                Assert.Fail ("#A1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
 #if NET_2_0
@@ -122,7 +124,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (-10, 0, 100);
                                Assert.Fail ("#B1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
 #if NET_2_0
@@ -145,7 +148,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (100, 50, 0);
                                Assert.Fail ("#A1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
 #if NET_2_0
@@ -162,7 +166,8 @@ namespace MonoTests.System.Net
                        try {
                                new CookieContainer (100, 50, -4);
                                Assert.Fail ("#B1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
 #if NET_2_0
@@ -186,7 +191,8 @@ namespace MonoTests.System.Net
                                new CookieContainer (432, 0, 1000);
                                Assert.Fail ("#B1");
 #if NET_2_0
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'PerDomainCapacity' has to be greater than
                                // '0' and less than '432'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
@@ -208,7 +214,8 @@ namespace MonoTests.System.Net
                                new CookieContainer (432, -1, 1000);
                                Assert.Fail ("#C1");
 #if NET_2_0
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'PerDomainCapacity' has to be greater than
                                // '0' and less than '432'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
@@ -230,7 +237,8 @@ namespace MonoTests.System.Net
                                new CookieContainer (432, 433, 1000);
                                Assert.Fail ("#C1");
 #if NET_2_0
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'PerDomainCapacity' has to be greater than
                                // '0' and less than '432'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
@@ -284,7 +292,8 @@ namespace MonoTests.System.Net
                        try {
                                c.Capacity = -5;
                                Assert.Fail ("#A1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'Capacity' has to be greater than '0' and
                                // less than '20'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
@@ -297,7 +306,8 @@ namespace MonoTests.System.Net
                        try {
                                c.Capacity = 0;
                                Assert.Fail ("#B1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'Capacity' has to be greater than '0' and
                                // less than '20'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
@@ -310,7 +320,8 @@ namespace MonoTests.System.Net
                        try {
                                c.Capacity = 5;
                                Assert.Fail ("#C1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                // 'Capacity' has to be greater than '0' and
                                // less than '20'
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
@@ -347,7 +358,8 @@ namespace MonoTests.System.Net
                        try {
                                c.MaxCookieSize = -5;
                                Assert.Fail ("#A1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
                                Assert.IsNotNull (ex.Message, "#A4");
@@ -358,7 +370,8 @@ namespace MonoTests.System.Net
                        try {
                                c.MaxCookieSize = -1;
                                Assert.Fail ("#B1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
                                Assert.IsNotNull (ex.Message, "#B4");
@@ -369,7 +382,8 @@ namespace MonoTests.System.Net
                        try {
                                c.MaxCookieSize = 0;
                                Assert.Fail ("#C1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
                                Assert.IsNull (ex.InnerException, "#C3");
                                Assert.IsNotNull (ex.Message, "#C4");
@@ -400,7 +414,8 @@ namespace MonoTests.System.Net
                        try {
                                c.PerDomainCapacity = -5;
                                Assert.Fail ("#A1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
                                Assert.IsNotNull (ex.Message, "#A4");
@@ -411,7 +426,8 @@ namespace MonoTests.System.Net
                        try {
                                c.PerDomainCapacity = 0;
                                Assert.Fail ("#B1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
                                Assert.IsNotNull (ex.Message, "#B4");
@@ -424,7 +440,8 @@ namespace MonoTests.System.Net
                        try {
                                c.PerDomainCapacity = (c.Capacity + 1);
                                Assert.Fail ("#C1");
-                       } catch (ArgumentOutOfRangeException ex) {
+                       }
+                       catch (ArgumentOutOfRangeException ex) {
                                Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
                                Assert.IsNull (ex.InnerException, "#C3");
                                Assert.IsNotNull (ex.Message, "#C4");
@@ -435,22 +452,48 @@ namespace MonoTests.System.Net
                [Test] // Add (Cookie)
                public void Add1 ()
                {
-                       Cookie cookie;
-                       CookieCollection cookies;
-
                        CookieContainer cc = new CookieContainer ();
-                       cookie = new Cookie ("Age", "28", string.Empty, "localhost");
+                       Cookie cookie = new Cookie ("Age", "28", string.Empty, "localhost");
+                       Assert.AreEqual ("Age", cookie.Name, "Name");
+                       Assert.AreEqual ("28", cookie.Value, "Value");
+                       Assert.AreEqual (String.Empty, cookie.Path, "Path");
+                       Assert.AreEqual ("localhost", cookie.Domain, "Domain");
+                       // does not survive the addition "cloning"
+                       cookie.Comment = "comment";
+                       cookie.CommentUri = new Uri ("http://localhost");
+                       cookie.Discard = true;
+                       cookie.Expires = DateTime.MaxValue;
+                       cookie.HttpOnly = true;
+                       cookie.Secure = true;
+                       // except version
+                       cookie.Version = 1;
+
                        cc.Add (cookie);
                        Assert.AreEqual (1, cc.Count, "#A1");
-                       cookies = cc.GetCookies (new Uri ("http://localhost/Whatever"));
+
+                       CookieCollection cookies = cc.GetCookies (new Uri ("http://localhost/Whatever"));
                        Assert.AreEqual (1, cookies.Count, "#A2");
+                       Assert.AreNotSame (cookie, cookies [0], "!same");
+
                        cookie = cookies [0];
-                       Assert.AreEqual ("Age", cookie.Name, "#A3");
-                       Assert.AreEqual ("28", cookie.Value, "#A4");
-#if false
-                       Assert.AreEqual ("/", cookie.Path, "#A5");
-#endif
-                       Assert.AreEqual ("localhost", cookie.Domain, "#A6");
+                       Assert.AreEqual ("Age", cookie.Name, "Clone-Name");
+                       Assert.AreEqual ("28", cookie.Value, "Clone-Value");
+                       // Path is not the same, nor default
+                       Assert.AreEqual ("/", cookie.Path, "Clone-Path");
+                       Assert.AreEqual ("localhost", cookie.Domain, "Clone-Domain");
+                       // other non-core properties have default values
+                       Assert.AreEqual (String.Empty, cookie.Comment, "Clone-Comment");
+                       Assert.IsNull (cookie.CommentUri, "Clone-CommentUri");
+                       Assert.IsFalse (cookie.Discard, "Clone-Discard");
+                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "Clone-Expires");
+                       Assert.IsFalse (cookie.HttpOnly, "Clone-HttpOnly");
+                       Assert.IsFalse (cookie.Secure, "Clone-Secure");
+                       // except version
+                       Assert.AreEqual (1, cookie.Version, "Clone-Version");
+
+                       cookies = cc.GetCookies (new Uri ("http://localhost/Whatever"));
+                       // the same Cookie instance returned for a second query
+                       Assert.AreSame (cookie, cookies [0], "!same-2");
                }
 
                [Test] // Add (Cookie)
@@ -461,7 +504,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add (cookie);
                                Assert.Fail ("#1");
-                       } catch (ArgumentException ex) {
+                       }
+                       catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
 #if NET_2_0
@@ -481,7 +525,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add ((CookieCollection) null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -497,7 +542,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add ((Uri) null, cookie);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -513,7 +559,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add (uri, (Cookie) null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -529,7 +576,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add ((Uri) null, cookies);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -545,7 +593,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.Add (uri, (CookieCollection) null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -582,7 +631,7 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
+               //              [Category ("NotWorking")]
                public void TestAddExpired_Cookie ()
                {
                        CookieContainer cc = new CookieContainer ();
@@ -646,7 +695,7 @@ namespace MonoTests.System.Net
                        Assert.IsFalse (cookie.Secure, "#C11");
 
                        Assert.AreEqual (2, cc.Count, "#D1");
-                       coll = cc.GetCookies (new Uri("http://contoso.com"));
+                       coll = cc.GetCookies (new Uri ("http://contoso.com"));
                        Assert.AreEqual (0, coll.Count, "#D1.1");
 
                        //not expired cookie
@@ -688,7 +737,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetCookieHeader1 ()
                {
                        CookieContainer cc;
@@ -711,14 +759,10 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void GetCookieHeader2 ()
+               public void GetCookieHeader2a ()
                {
-                       CookieContainer cc;
-                       Cookie cookie;
-
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("Country", "Belgium", "/path", "mono.com");
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("Country", "Belgium", "/path", "mono.com");
                        cc.Add (cookie);
                        cookie = new Cookie ("Age", "26", "/path", "dev.mono.com");
                        cc.Add (cookie);
@@ -727,9 +771,13 @@ namespace MonoTests.System.Net
                        Assert.AreEqual ("Country=Belgium", cc.GetCookieHeader (new Uri ("http://mono.com/path")), "#A2");
                        Assert.AreEqual ("", cc.GetCookieHeader (new Uri ("http://test.mono.com/path")), "#A3");
                        Assert.AreEqual ("", cc.GetCookieHeader (new Uri ("http://us.dev.mono.com/path")), "#A4");
+               }
 
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("Country", "Belgium", "/path", ".mono.com");
+               [Test]
+               public void GetCookieHeader2b ()
+               {
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("Country", "Belgium", "/path", ".mono.com");
                        cc.Add (cookie);
                        cookie = new Cookie ("Age", "26", "/path", ".dev.mono.com");
                        cc.Add (cookie);
@@ -741,12 +789,9 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetCookieHeader3 ()
                {
-                       CookieContainer cc;
-
-                       cc = new CookieContainer ();
+                       CookieContainer cc = new CookieContainer ();
                        cc.SetCookies (new Uri ("http://dev.test.mono.com/Whatever/Do"),
                                "Country=Belgium; path=/Whatever; domain=mono.com;" +
                                "Age=26; path=/Whatever; domain=test.mono.com," +
@@ -758,14 +803,10 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetCookieHeader4 ()
                {
-                       CookieContainer cc;
-                       Cookie cookie;
-
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("Height", "178", "/Whatever", "mono.com");
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("Height", "178", "/Whatever", "mono.com");
                        cc.Add (cookie);
                        cookie = new Cookie ("Town", "Brussels", "/Whatever", ".mono.com");
                        cc.Add (cookie);
@@ -783,18 +824,30 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void GetCookieHeader5 ()
+               public void GetCookieHeader5a ()
                {
-                       CookieContainer cc;
-                       Cookie cookie;
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("name1", "value1", "", "localhost");
+                       cookie.Comment = "Short name";
+                       cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
+                       cookie.Version = 1;
+                       cc.Add (cookie);
+                       Assert.AreEqual ("$Version=1; name1=value1; $Domain=localhost", cookie.ToString (), "#E0");
+                       Assert.AreEqual ("$Version=1; name1=value1; $Path=/",
+                               cc.GetCookieHeader (new Uri ("http://localhost/path/sub")), "#E1");
+               }
 
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("name1", "value1", "", "localhost");
+               [Test]
+               public void GetCookieHeader5b ()
+               {
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("name1", "value1");
+                       cookie.Domain = "localhost";
                        cookie.Comment = "Short name";
                        cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
                        cookie.Version = 1;
                        cc.Add (cookie);
+                       Assert.AreEqual ("$Version=1; name1=value1; $Domain=localhost", cookie.ToString (), "#E0");
                        Assert.AreEqual ("$Version=1; name1=value1; $Path=/",
                                cc.GetCookieHeader (new Uri ("http://localhost/path/sub")), "#E1");
                }
@@ -802,11 +855,8 @@ namespace MonoTests.System.Net
                [Test]
                public void GetCookieHeader6 ()
                {
-                       CookieContainer cc;
-                       Cookie cookie;
-
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("name1", "value1", "", "localhost");
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("name1", "value1", "", "localhost");
                        cookie.Comment = "Short name";
                        cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
                        cookie.Version = 0;
@@ -816,14 +866,10 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void GetCookieHeader7 ()
+               public void GetCookieHeader7a ()
                {
-                       CookieContainer cc;
-                       Cookie cookie;
-
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("name1", "value1", "/path", ".mono.com");
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("name1", "value1", "/path", ".mono.com");
                        cookie.Comment = "Short name";
                        cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
                        cookie.Version = 0;
@@ -838,9 +884,13 @@ namespace MonoTests.System.Net
                        Assert.AreEqual (string.Empty, cc.GetCookieHeader (new Uri ("http://live.mono.com/whatever")), "#A3");
                        Assert.AreEqual (string.Empty, cc.GetCookieHeader (new Uri ("http://gomono.com/path/sub")), "#A4");
                        Assert.AreEqual (string.Empty, cc.GetCookieHeader (new Uri ("http://mono.com/path/sub")), "#A5");
+               }
 
-                       cc = new CookieContainer ();
-                       cookie = new Cookie ("name1", "value1", "/path", "live.mono.com");
+               [Test]
+               public void GetCookieHeader7b ()
+               {
+                       CookieContainer cc = new CookieContainer ();
+                       Cookie cookie = new Cookie ("name1", "value1", "/path", "live.mono.com");
                        cookie.Comment = "Short name";
                        cookie.Expires = DateTime.Now.Add (new TimeSpan (3, 2, 5));
                        cookie.Version = 0;
@@ -866,7 +916,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.GetCookieHeader ((Uri) null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -914,22 +965,17 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void GetCookies2 ()
+               public void GetCookies2a ()
                {
-                       CookieContainer container;
-                       CookieCollection cookies;
-                       Cookie cookie;
-
-                       container = new CookieContainer ();
+                       CookieContainer container = new CookieContainer ();
                        container.Add (new Cookie ("Country", "Belgium", "/path", "mono.com"));
                        container.Add (new Cookie ("Age", "26", "/path", "dev.mono.com"));
 
-                       cookies = container.GetCookies (new Uri ("http://dev.mono.com/path/ok"));
+                       CookieCollection cookies = container.GetCookies (new Uri ("http://dev.mono.com/path/ok"));
                        Assert.IsNotNull (cookies, "#G1");
                        Assert.AreEqual (1, cookies.Count, "#G2");
 
-                       cookie = cookies [0];
+                       Cookie cookie = cookies [0];
                        Assert.AreEqual ("Age", cookie.Name, "#H1");
                        Assert.AreEqual ("26", cookie.Value, "#H2");
                        Assert.AreEqual ("/path", cookie.Path, "#H3");
@@ -952,18 +998,22 @@ namespace MonoTests.System.Net
                        cookies = container.GetCookies (new Uri ("http://us.dev.mono.com/path"));
                        Assert.IsNotNull (cookies, "#L1");
                        Assert.AreEqual (0, cookies.Count, "#L2");
+               }
 
-                       container = new CookieContainer ();
+               [Test]
+               public void GetCookies2b ()
+               {
+                       CookieContainer container = new CookieContainer ();
                        container.SetCookies (new Uri ("http://dev.test.mono.com/Whatever/Do"),
                                "Country=Belgium; path=/Whatever; domain=mono.com," +
                                "Age=26; path=/Whatever; domain=test.mono.com," +
                                "Weight=87; path=/Whatever/Do; domain=.mono.com;");
 
-                       cookies = container.GetCookies (new Uri ("http://dev.mono.com/Whatever/Do"));
+                       CookieCollection cookies = container.GetCookies (new Uri ("http://dev.mono.com/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#M1");
                        Assert.AreEqual (2, cookies.Count, "#M2");
 
-                       cookie = cookies [0];
+                       Cookie cookie = cookies [0];
                        Assert.AreEqual ("Weight", cookie.Name, "#N1");
                        Assert.AreEqual ("87", cookie.Value, "#N2");
                        Assert.AreEqual ("/Whatever/Do", cookie.Path, "#N3");
@@ -1012,8 +1062,12 @@ namespace MonoTests.System.Net
                        Assert.AreEqual ("Belgium", cookie.Value, "#S10");
                        Assert.AreEqual ("/Whatever", cookie.Path, "#S11");
                        Assert.AreEqual ("mono.com", cookie.Domain, "#S12");
+               }
 
-                       container = new CookieContainer ();
+               [Test]
+               public void GetCookies2c ()
+               {
+                       CookieContainer container = new CookieContainer ();
                        container.Add (new Cookie ("Height", "178", "/Whatever", "mono.com"));
                        container.Add (new Cookie ("Town", "Brussels", "/Whatever", ".mono.com"));
                        container.Add (new Cookie ("Income", "34445", "/Whatever/", ".test.mono.com"));
@@ -1023,11 +1077,11 @@ namespace MonoTests.System.Net
                                "Age=26; path=/Whatever/Do; domain=test.mono.com," +
                                "Weight=87; path=/");
 
-                       cookies = container.GetCookies (new Uri ("http://us.test.mono.com/Whatever/Do/Ok"));
+                       CookieCollection cookies = container.GetCookies (new Uri ("http://us.test.mono.com/Whatever/Do/Ok"));
                        Assert.IsNotNull (cookies, "#T1");
                        Assert.AreEqual (3, cookies.Count, "#T2");
 
-                       cookie = cookies [0];
+                       Cookie cookie = cookies [0];
                        Assert.AreEqual ("Age", cookie.Name, "#U1");
                        Assert.AreEqual ("26", cookie.Value, "#U2");
                        Assert.AreEqual ("/Whatever/Do", cookie.Path, "#U3");
@@ -1051,7 +1105,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.GetCookies (null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -1060,28 +1115,24 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
+               //              [Category ("NotWorking")]
                public void SetCookies ()
                {
-                       CookieContainer cc;
-                       CookieCollection cookies;
-                       Cookie cookie;
-
                        Uri uri = new Uri ("http://dev.test.mono.com/Whatever/Do/You");
 
                        DateTime now = DateTime.Now;
 
-                       cc = new CookieContainer ();
+                       CookieContainer cc = new CookieContainer ();
                        cc.SetCookies (uri, "Country=Belgium," +
                                "Age=26;   ; path=/Whatever/Do; domain=test.mono.com," +
                                "Weight=87; path=/; ");
                        Assert.AreEqual (3, cc.Count, "#A");
 
-                       cookies = cc.GetCookies (new Uri ("http://us.test.mono.com/Whatever/Do/Ok"));
+                       CookieCollection cookies = cc.GetCookies (new Uri ("http://us.test.mono.com/Whatever/Do/Ok"));
                        Assert.IsNotNull (cookies, "#B1");
                        Assert.AreEqual (1, cookies.Count, "#B2");
 
-                       cookie = cookies [0];
+                       Cookie cookie = cookies [0];
                        Assert.AreEqual (string.Empty, cookie.Comment, "#C:Comment");
                        Assert.IsNull (cookie.CommentUri, "#C:CommentUri");
                        Assert.IsFalse (cookie.Discard, "#C:Discard");
@@ -1103,99 +1154,119 @@ namespace MonoTests.System.Net
                        Assert.IsNotNull (cookies, "#D1");
                        Assert.AreEqual (2, cookies.Count, "#D2");
 
-                       cookie = cookies [0];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#E:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#E:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#E:Discard");
-                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#E:Domain");
-                       Assert.IsFalse (cookie.Expired, "#E:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#E:Expires");
+                       // our sorting is not 100% identical to MS implementation
+                       for (int i = 0; i < cookies.Count; i++) {
+                               cookie = cookies [i];
+                               switch (cookie.Name) {
+                               case "Weight":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#E:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#E:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#E:Discard");
+                                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#E:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#E:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#E:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#E:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#E:HttpOnly");
 #endif
-                       Assert.AreEqual ("Weight", cookie.Name, "#E:Name");
-                       Assert.AreEqual ("/", cookie.Path, "#E:Path");
-                       Assert.IsFalse (cookie.Secure, "#E:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#E:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#E:TimeStamp2");
-                       Assert.AreEqual ("87", cookie.Value, "#E:Value");
-                       Assert.AreEqual (0, cookie.Version, "#E:Version");
-
-                       cookie = cookies [1];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#F:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#F:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#F:Discard");
-                       Assert.AreEqual ("test.mono.com", cookie.Domain, "#F:Domain");
-                       Assert.IsFalse (cookie.Expired, "#F:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#F:Expires");
+                                       Assert.AreEqual ("Weight", cookie.Name, "#E:Name");
+                                       Assert.AreEqual ("/", cookie.Path, "#E:Path");
+                                       Assert.IsFalse (cookie.Secure, "#E:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#E:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#E:TimeStamp2");
+                                       Assert.AreEqual ("87", cookie.Value, "#E:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#E:Version");
+                                       break;
+                               case "Age":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#F:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#F:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#F:Discard");
+                                       Assert.AreEqual ("test.mono.com", cookie.Domain, "#F:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#F:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#F:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#F:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#F:HttpOnly");
 #endif
-                       Assert.AreEqual ("Age", cookie.Name, "#F:Name");
-                       Assert.AreEqual ("/Whatever/Do", cookie.Path, "#F:Path");
-                       Assert.IsFalse (cookie.Secure, "#F:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#F:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#F:TimeStamp2");
-                       Assert.AreEqual ("26", cookie.Value, "#F:Value");
-                       Assert.AreEqual (0, cookie.Version, "#F:Version");
+                                       Assert.AreEqual ("Age", cookie.Name, "#F:Name");
+                                       Assert.AreEqual ("/Whatever/Do", cookie.Path, "#F:Path");
+                                       Assert.IsFalse (cookie.Secure, "#F:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#F:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#F:TimeStamp2");
+                                       Assert.AreEqual ("26", cookie.Value, "#F:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#F:Version");
+                                       break;
+                               default:
+                                       Assert.Fail (cookie.Name);
+                                       break;
+                               }
+                       }
 
                        cookies = cc.GetCookies (uri);
                        Assert.IsNotNull (cookies, "#G1");
                        Assert.AreEqual (3, cookies.Count, "#G2");
 
-                       cookie = cookies [0];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#H:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#H:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#H:Discard");
-                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#H:Domain");
-                       Assert.IsFalse (cookie.Expired, "#H:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#H:Expires");
+                       // our sorting is not 100% identical to MS implementation
+                       for (int i = 0; i < cookies.Count; i++) {
+                               cookie = cookies [i];
+                               switch (cookie.Name) {
+                               case "Country":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#H:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#H:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#H:Discard");
+                                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#H:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#H:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#H:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#H:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#H:HttpOnly");
 #endif
-                       Assert.AreEqual ("Country", cookie.Name, "#H:Name");
-                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#H:Path");
-                       Assert.IsFalse (cookie.Secure, "#H:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#H:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#H:TimeStamp2");
-                       Assert.AreEqual ("Belgium", cookie.Value, "#H:Value");
-                       Assert.AreEqual (0, cookie.Version, "#H:Version");
-
-                       cookie = cookies [1];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#I:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#I:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#I:Discard");
-                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#I:Domain");
-                       Assert.IsFalse (cookie.Expired, "#I:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#I:Expires");
+                                       Assert.AreEqual ("Country", cookie.Name, "#H:Name");
+                                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#H:Path");
+                                       Assert.IsFalse (cookie.Secure, "#H:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#H:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#H:TimeStamp2");
+                                       Assert.AreEqual ("Belgium", cookie.Value, "#H:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#H:Version");
+                                       break;
+                               case "Weight":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#I:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#I:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#I:Discard");
+                                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#I:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#I:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#I:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#I:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#I:HttpOnly");
 #endif
-                       Assert.AreEqual ("Weight", cookie.Name, "#I:Name");
-                       Assert.AreEqual ("/", cookie.Path, "#I:Path");
-                       Assert.IsFalse (cookie.Secure, "#I:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#I:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#I:TimeStamp2");
-                       Assert.AreEqual ("87", cookie.Value, "#I:Value");
-                       Assert.AreEqual (0, cookie.Version, "#I:Version");
-
-                       cookie = cookies [2];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#J:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#J:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#J:Discard");
-                       Assert.AreEqual ("test.mono.com", cookie.Domain, "#J:Domain");
-                       Assert.IsFalse (cookie.Expired, "#J:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#J:Expires");
+                                       Assert.AreEqual ("Weight", cookie.Name, "#I:Name");
+                                       Assert.AreEqual ("/", cookie.Path, "#I:Path");
+                                       Assert.IsFalse (cookie.Secure, "#I:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#I:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#I:TimeStamp2");
+                                       Assert.AreEqual ("87", cookie.Value, "#I:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#I:Version");
+                                       break;
+                               case "Age":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#J:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#J:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#J:Discard");
+                                       Assert.AreEqual ("test.mono.com", cookie.Domain, "#J:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#J:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#J:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#J:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#J:HttpOnly");
 #endif
-                       Assert.AreEqual ("Age", cookie.Name, "#J:Name");
-                       Assert.AreEqual ("/Whatever/Do", cookie.Path, "#J:Path");
-                       Assert.IsFalse (cookie.Secure, "#J:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#J:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#J:TimeStamp2");
-                       Assert.AreEqual ("26", cookie.Value, "#J:Value");
-                       Assert.AreEqual (0, cookie.Version, "#J:Version");
+                                       Assert.AreEqual ("Age", cookie.Name, "#J:Name");
+                                       Assert.AreEqual ("/Whatever/Do", cookie.Path, "#J:Path");
+                                       Assert.IsFalse (cookie.Secure, "#J:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#J:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#J:TimeStamp2");
+                                       Assert.AreEqual ("26", cookie.Value, "#J:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#J:Version");
+                                       break;
+                               default:
+                                       Assert.Fail (cookie.Name);
+                                       break;
+                               }
+                       }
 
                        cc.SetCookies (uri, "Country=,A");
                        cookies = cc.GetCookies (uri);
@@ -1208,41 +1279,51 @@ namespace MonoTests.System.Net
                        Assert.IsNotNull (cookies, "#L1");
                        Assert.AreEqual (2, cookies.Count, "#L2");
 
-                       cookie = cookies [0];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#M:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#M:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#M:Discard");
-                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#M:Domain");
-                       Assert.IsFalse (cookie.Expired, "#M:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#M:Expires");
+                       // our sorting is not 100% identical to MS implementation
+                       for (int i = 0; i < cookies.Count; i++) {
+                               cookie = cookies [i];
+                               switch (cookie.Name) {
+                               case "Country":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#M:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#M:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#M:Discard");
+                                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#M:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#M:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#M:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#M:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#M:HttpOnly");
 #endif
-                       Assert.AreEqual ("Country", cookie.Name, "#M:Name");
-                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#M:Path");
-                       Assert.IsFalse (cookie.Secure, "#M:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#M:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#M:TimeStamp2");
-                       Assert.AreEqual (string.Empty, cookie.Value, "#M:Value");
-                       Assert.AreEqual (0, cookie.Version, "#M:Version");
-
-                       cookie = cookies [1];
-                       Assert.AreEqual (string.Empty, cookie.Comment, "#N:Comment");
-                       Assert.IsNull (cookie.CommentUri, "#N:CommentUri");
-                       Assert.IsFalse (cookie.Discard, "#N:Discard");
-                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#N:Domain");
-                       Assert.IsFalse (cookie.Expired, "#N:Expired");
-                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#N:Expires");
+                                       Assert.AreEqual ("Country", cookie.Name, "#M:Name");
+                                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#M:Path");
+                                       Assert.IsFalse (cookie.Secure, "#M:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#M:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#M:TimeStamp2");
+                                       Assert.AreEqual (string.Empty, cookie.Value, "#M:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#M:Version");
+                                       break;
+                               case "A":
+                                       Assert.AreEqual (string.Empty, cookie.Comment, "#N:Comment");
+                                       Assert.IsNull (cookie.CommentUri, "#N:CommentUri");
+                                       Assert.IsFalse (cookie.Discard, "#N:Discard");
+                                       Assert.AreEqual ("dev.test.mono.com", cookie.Domain, "#N:Domain");
+                                       Assert.IsFalse (cookie.Expired, "#N:Expired");
+                                       Assert.AreEqual (DateTime.MinValue, cookie.Expires, "#N:Expires");
 #if NET_2_0
-                       Assert.IsFalse (cookie.HttpOnly, "#N:HttpOnly");
+                                       Assert.IsFalse (cookie.HttpOnly, "#N:HttpOnly");
 #endif
-                       Assert.AreEqual ("A", cookie.Name, "#N:Name");
-                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#N:Path");
-                       Assert.IsFalse (cookie.Secure, "#N:Secure");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#N:TimeStamp1");
-                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#N:TimeStamp2");
-                       Assert.AreEqual (string.Empty, cookie.Value, "#N:Value");
-                       Assert.AreEqual (0, cookie.Version, "#N:Version");
+                                       Assert.AreEqual ("A", cookie.Name, "#N:Name");
+                                       Assert.AreEqual ("/Whatever/Do/You", cookie.Path, "#N:Path");
+                                       Assert.IsFalse (cookie.Secure, "#N:Secure");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds >= 0, "#N:TimeStamp1");
+                                       Assert.IsTrue ((cookie.TimeStamp - now).TotalMilliseconds < 1000, "#N:TimeStamp2");
+                                       Assert.AreEqual (string.Empty, cookie.Value, "#N:Value");
+                                       Assert.AreEqual (0, cookie.Version, "#N:Version");
+                                       break;
+                               default:
+                                       Assert.Fail (cookie.Name);
+                                       break;
+                               }
+                       }
                }
 
                [Test]
@@ -1260,7 +1341,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.SetCookies (new Uri ("http://www.contoso.com"), null);
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -1269,17 +1351,15 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void SetCookies_CookieHeader_Invalid ()
+               public void SetCookies_CookieHeader_Invalid_1 ()
                {
-                       CookieContainer cc;
-
                        // cookie format error
-                       cc = new CookieContainer ();
+                       CookieContainer cc = new CookieContainer ();
                        try {
                                cc.SetCookies (new Uri ("http://www.contoso.com"), "=lalala");
                                Assert.Fail ("#A1");
-                       } catch (CookieException ex) {
+                       }
+                       catch (CookieException ex) {
                                // An error has occurred when parsing Cookie
                                // header for Uri 'http://www.contoso.com/'
                                Assert.AreEqual (typeof (CookieException), ex.GetType (), "#A2");
@@ -1293,14 +1373,19 @@ namespace MonoTests.System.Net
                                Assert.IsNull (inner.InnerException, "#A7");
                                Assert.IsNotNull (inner.Message, "#A8");
                        }
+               }
 
+               [Test]
+               public void SetCookies_CookieHeader_Invalid_2 ()
+               {
                        // cookie path not part of URI path
-                       cc = new CookieContainer ();
+                       CookieContainer cc = new CookieContainer ();
                        try {
                                cc.SetCookies (new Uri ("http://dev.test.mono.com/Whatever"),
                                        "Age=26; path=/Whatever/Do; domain=test.mono.com");
                                Assert.Fail ("#B1");
-                       } catch (CookieException ex) {
+                       }
+                       catch (CookieException ex) {
                                // An error has occurred when parsing Cookie
                                // header for Uri 'http://dev.test.mono.com/Whatever'
                                Assert.AreEqual (typeof (CookieException), ex.GetType (), "#B2");
@@ -1325,7 +1410,8 @@ namespace MonoTests.System.Net
                        try {
                                cc.SetCookies (null, "Age=26; path=/Whatever; domain=test.mono.com");
                                Assert.Fail ("#1");
-                       } catch (ArgumentNullException ex) {
+                       }
+                       catch (ArgumentNullException ex) {
                                Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                Assert.IsNull (ex.InnerException, "#3");
                                Assert.IsNotNull (ex.Message, "#4");
@@ -1334,12 +1420,11 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void SetCookies_DomainMatchesHost ()
                {
                        CookieContainer cc = new CookieContainer ();
-
 #if NET_2_0
+                       // domains looks identical - but "domain=test.mono.com" means "*.test.mono.com"
                        cc.SetCookies (new Uri ("http://test.mono.com/Whatever/Do"),
                                "Age=26; path=/Whatever; domain=test.mono.com");
                        CookieCollection cookies = cc.GetCookies (new Uri ("http://test.mono.com/Whatever/Do"));
@@ -1373,7 +1458,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void SetCookies_Domain_Local ()
                {
                        CookieContainer cc;
@@ -1384,39 +1468,39 @@ namespace MonoTests.System.Net
                                "Age=26; path=/Whatever; domain=.local");
                        cookies = cc.GetCookies (new Uri ("http://localhost/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#A1");
-                       Assert.AreEqual (1, cookies.Count, "#A2");
+                       Assert.AreEqual (0, cookies.Count, "#A2");
                        cookies = cc.GetCookies (new Uri ("http://127.0.0.1/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#A3");
                        Assert.AreEqual (0, cookies.Count, "#A4");
                        cookies = cc.GetCookies (new Uri ("http://" + Dns.GetHostName () + "/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#A5");
-                       Assert.AreEqual (1, cookies.Count, "#A6");
+                       Assert.AreEqual (0, cookies.Count, "#A6");
 
                        cc = new CookieContainer ();
                        cc.SetCookies (new Uri ("http://127.0.0.1/Whatever/Do"),
                                "Age=26; path=/Whatever; domain=.local");
                        cookies = cc.GetCookies (new Uri ("http://localhost/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#B1");
-                       Assert.AreEqual (1, cookies.Count, "#B2");
+                       Assert.AreEqual (0, cookies.Count, "#B2");
                        cookies = cc.GetCookies (new Uri ("http://127.0.0.1/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#B3");
                        Assert.AreEqual (0, cookies.Count, "#B4");
                        cookies = cc.GetCookies (new Uri ("http://" + Dns.GetHostName () + "/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#B5");
-                       Assert.AreEqual (1, cookies.Count, "#B6");
+                       Assert.AreEqual (0, cookies.Count, "#B6");
 
                        cc = new CookieContainer ();
                        cc.SetCookies (new Uri ("http://" + Dns.GetHostName () + "/Whatever/Do"),
                                "Age=26; path=/Whatever; domain=.local");
                        cookies = cc.GetCookies (new Uri ("http://localhost/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#C1");
-                       Assert.AreEqual (1, cookies.Count, "#C2");
+                       Assert.AreEqual (0, cookies.Count, "#C2");
                        cookies = cc.GetCookies (new Uri ("http://127.0.0.1/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#C3");
                        Assert.AreEqual (0, cookies.Count, "#C4");
                        cookies = cc.GetCookies (new Uri ("http://" + Dns.GetHostName () + "/Whatever/Do"));
                        Assert.IsNotNull (cookies, "#C5");
-                       Assert.AreEqual (1, cookies.Count, "#C6");
+                       Assert.AreEqual (0, cookies.Count, "#C6");
                }
 
                [Test]
@@ -1452,5 +1536,35 @@ namespace MonoTests.System.Net
 
                        Assert.AreEqual (0, cookies.Count, "#C");
                }
+
+               [Test]
+               public void MoreThanDefaultDomainCookieLimit ()
+               {
+                       CookieContainer cc = new CookieContainer ();
+                       for (int i = 1; i <= CookieContainer.DefaultPerDomainCookieLimit; i++) {
+                               Cookie c = new Cookie (i.ToString (), i.ToString (), "/", "mono.com");
+                               cc.Add (c);
+                       }
+                       Assert.AreEqual (CookieContainer.DefaultPerDomainCookieLimit, cc.Count, "Count");
+                       Cookie c2 = new Cookie ("uho", "21", "/", "mono.com");
+                       cc.Add (c2);
+                       Assert.AreEqual (CookieContainer.DefaultPerDomainCookieLimit, cc.Count, "Count");
+                       // so one (yes '1' ;-) was removed
+               }
+
+               [Test]
+               public void MoreThanDefaultCookieLimit ()
+               {
+                       CookieContainer cc = new CookieContainer ();
+                       for (int i = 1; i <= CookieContainer.DefaultCookieLimit; i++) {
+                               Cookie c = new Cookie (i.ToString (), i.ToString (), "/", "www" + i.ToString () + ".mono.com");
+                               cc.Add (c);
+                       }
+                       Assert.AreEqual (CookieContainer.DefaultCookieLimit, cc.Count, "Count");
+                       Cookie c2 = new Cookie ("uho", "301", "/", "www301.mono.com");
+                       cc.Add (c2);
+                       Assert.AreEqual (CookieContainer.DefaultCookieLimit, cc.Count, "Count");
+                       // so one (yes '1' ;-) was removed
+               }
        }
 }