Author: gert
Date: 2007-10-15 11:46:36 -0400 (Mon, 15 Oct 2007)
New Revision: 87517

Modified:
   trunk/mcs/class/System/System.Net/ChangeLog
   trunk/mcs/class/System/System.Net/WebRequest.cs
   trunk/mcs/class/System/Test/System.Net/ChangeLog
   trunk/mcs/class/System/Test/System.Net/WebRequestTest.cs
Log:
* WebRequestTest.cs: Fixed test for serialization ctor to match
1.0 profile change. Added trivial tests to argument null checks.
Added test for DefaultWebProxy. Fixed line endings.
* WebRequest.cs: Changed serialization ctor to throw NIE on 1.0
profile. Cache default proxy, but still allow it to be explicitly set 
to null.


Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2007-10-15 14:49:11 UTC (rev 
87516)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2007-10-15 15:46:36 UTC (rev 
87517)
@@ -1,3 +1,9 @@
+2007-10-15  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * WebRequest.cs: Changed serialization ctor to throw NIE on 1.0
+       profile. Cache default proxy, but still allow it to be explicitly set
+       to null.
+
 2007-10-14 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * WebRequest.cs: DefaultWebProxy allows a null value. Fixes bug #323668.

Modified: trunk/mcs/class/System/System.Net/WebRequest.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebRequest.cs     2007-10-15 14:49:11 UTC 
(rev 87516)
+++ trunk/mcs/class/System/System.Net/WebRequest.cs     2007-10-15 15:46:36 UTC 
(rev 87517)
@@ -45,6 +45,8 @@
        public abstract class WebRequest : MarshalByRefObject, ISerializable
        {
                static HybridDictionary prefixes = new HybridDictionary ();
+               static bool isDefaultWebProxySet;
+               static IWebProxy defaultWebProxy;
                
                // Constructors
                
@@ -69,6 +71,9 @@
                
                protected WebRequest (SerializationInfo serializationInfo, 
StreamingContext streamingContext) 
                {
+#if ONLY_1_1
+                       throw GetMustImplement ();
+#endif
                }
 
                static Exception GetMustImplement ()
@@ -102,7 +107,7 @@
                }
 #endif
                
-               public virtual string ConnectionGroupName { 
+               public virtual string ConnectionGroupName {
                        get { throw GetMustImplement (); }
                        set { throw GetMustImplement (); }
                }
@@ -179,20 +184,24 @@
                
                public static IWebProxy DefaultWebProxy {
                        get {
-                               lock (lockobj) {
-                                       if (proxy == null)
-                                               proxy = GetDefaultWebProxy ();
-                                       return proxy;
+                               if (!isDefaultWebProxySet) {
+                                       lock (lockobj) {
+                                               if (defaultWebProxy == null)
+                                                       defaultWebProxy = 
GetDefaultWebProxy ();
+                                       }
                                }
+                               return defaultWebProxy;
                        }
                        set {
                                /* MS documentation states that a null value 
would cause an ArgumentNullException
-                                * but that's not the way it behaves
+                                * but that's not the way it behaves:
+                                * 
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=304724
                                if (value == null)
                                        throw new ArgumentNullException 
("WebRequest.DefaultWebProxy",
                                                        "null IWebProxy not 
allowed.");
                                */
-                               proxy = value;
+                               defaultWebProxy = value;
+                               isDefaultWebProxySet = true;
                        }
                }
                
@@ -220,7 +229,7 @@
                                p.BypassProxyOnLocal = (pe.BypassOnLocal == 
ProxyElement.BypassOnLocalValues.True);
 #endif
                        return p;
-               }               
+               }
 #endif
 
                // Methods
@@ -316,7 +325,7 @@
                        if (prefix == null)
                                throw new ArgumentNullException("prefix");
                        if (creator == null)
-                               throw new ArgumentNullException("creator");     
                
+                               throw new ArgumentNullException("creator");
                        
                        lock (prefixes.SyncRoot) {
                                string lowerCasePrefix = prefix.ToLower 
(CultureInfo.InvariantCulture);
@@ -342,7 +351,7 @@
                                        continue;
                                
                                if (!prefix.StartsWith (key))
-                                       continue;                               
        
+                                       continue;
                                        
                                longestPrefix = key.Length;
                                creator = (IWebRequestCreate) e.Value;

Modified: trunk/mcs/class/System/Test/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Net/ChangeLog    2007-10-15 14:49:11 UTC 
(rev 87516)
+++ trunk/mcs/class/System/Test/System.Net/ChangeLog    2007-10-15 15:46:36 UTC 
(rev 87517)
@@ -1,3 +1,9 @@
+2007-10-15  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * WebRequestTest.cs: Fixed test for serialization ctor to match
+       1.0 profile change. Added trivial tests to argument null checks.
+       Added test for DefaultWebProxy. Fixed line endings.
+
 2007-09-30  Gert Driesen  <[EMAIL PROTECTED]>
 
        * HttpListenerRequestTest.cs: Added test for HttpMethod.

Modified: trunk/mcs/class/System/Test/System.Net/WebRequestTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Net/WebRequestTest.cs    2007-10-15 
14:49:11 UTC (rev 87516)
+++ trunk/mcs/class/System/Test/System.Net/WebRequestTest.cs    2007-10-15 
15:46:36 UTC (rev 87517)
@@ -44,8 +44,16 @@
                [Test]
                public void SerializationConstructor ()
                {
+#if NET_2_0
                        NonAbstractWebRequest w = new NonAbstractWebRequest 
(null, new StreamingContext ());
                        Assert.IsNotNull (w);
+#else
+                       try {
+                               new NonAbstractWebRequest (null, new 
StreamingContext ());
+                               Assert.Fail ("#1");
+                       } catch (NotImplementedException) {
+                       }
+#endif
                }
 
                // properties (only test 'get'ter)
@@ -189,8 +197,8 @@
                }
 
        [Test]
-        public void All ()
-        {
+       public void All ()
+       {
                WebRequest req = WebRequest.Create ("http://www.contoso.com";);
                Assertion.Assert ("#1", req is HttpWebRequest);
                req = WebRequest.Create ("https://www.contoso.com";);
@@ -226,11 +234,97 @@
 
                try {
                        req = WebRequest.Create ("tcp://www.contoso.com");
-                       Assertion.Fail ("#11 should have failed with 
NotSupportedException");                   
-               } catch (NotSupportedException) {                       
-               }               
+                       Assertion.Fail ("#11 should have failed with 
NotSupportedException");
+               } catch (NotSupportedException) {
+               }
        }
-       
+
+       [Test]
+       public void Create_RequestUriString_Null ()
+       {
+               try {
+                       WebRequest.Create ((string) null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), 
ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNotNull (ex.ParamName, "#5");
+                       Assert.AreEqual ("requestUriString", ex.ParamName, 
"#6");
+               }
+       }
+
+       [Test]
+       public void CreateDefault_RequestUri_Null ()
+       {
+               try {
+                       WebRequest.CreateDefault ((Uri) null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), 
ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNotNull (ex.ParamName, "#5");
+                       Assert.AreEqual ("requestUri", ex.ParamName, "#6");
+               }
+       }
+
+#if NET_2_0
+       [Test]
+       public void DefaultWebProxy ()
+       {
+               WebProxy proxy = new WebProxy ("proxy.intern.com", 83);
+
+               WebRequest.DefaultWebProxy = proxy;
+               Assert.IsNotNull (WebRequest.DefaultWebProxy, "#A1");
+               Assert.AreSame (proxy, WebRequest.DefaultWebProxy, "#A2");
+
+               HttpWebRequest req = (HttpWebRequest) WebRequest.CreateDefault (
+                       new Uri ("http://www.mono-project.com";));
+               Assert.IsNotNull (req.Proxy, "#B1");
+               Assert.AreSame (proxy, req.Proxy, "#B2");
+
+               WebRequest.DefaultWebProxy = null;
+               Assert.IsNull (WebRequest.DefaultWebProxy, "#C1");
+               Assert.IsNotNull (req.Proxy, "#C2");
+               Assert.AreSame (proxy, req.Proxy, "#C3");
+
+               req = (HttpWebRequest) WebRequest.CreateDefault (
+                       new Uri ("http://www.mono-project.com";));
+               Assert.IsNull (req.Proxy, "#D");
+       }
+#endif
+
+       [Test]
+       public void RegisterPrefix_Creator_Null ()
+       {
+               try {
+                       WebRequest.RegisterPrefix 
("http://www.mono-project.com";, (IWebRequestCreate) null);
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), 
ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNotNull (ex.ParamName, "#5");
+                       Assert.AreEqual ("creator", ex.ParamName, "#6");
+               }
+       }
+
+       [Test]
+       public void RegisterPrefix_Prefix_Null ()
+       {
+               try {
+                       WebRequest.RegisterPrefix ((string) null, new 
TestWebRequestCreator ());
+                       Assert.Fail ("#1");
+               } catch (ArgumentNullException ex) {
+                       Assert.AreEqual (typeof (ArgumentNullException), 
ex.GetType (), "#2");
+                       Assert.IsNull (ex.InnerException, "#3");
+                       Assert.IsNotNull (ex.Message, "#4");
+                       Assert.IsNotNull (ex.ParamName, "#5");
+                       Assert.AreEqual ("prefix", ex.ParamName, "#6");
+               }
+       }
+
        internal class TestWebRequestCreator : IWebRequestCreate
        {
                internal TestWebRequestCreator () { }


Property changes on: trunk/mcs/class/System/Test/System.Net/WebRequestTest.cs
___________________________________________________________________
Name: svn:eol-style
   + CRLF

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

Reply via email to