Fix for #81066 plus test
authorMiguel de Icaza <miguel@gnome.org>
Fri, 9 Mar 2007 06:08:25 +0000 (06:08 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 9 Mar 2007 06:08:25 +0000 (06:08 -0000)
svn path=/trunk/mcs/; revision=73988

mcs/class/System/System.Net/WebClient.cs
mcs/class/System/System_test.dll.sources
mcs/class/System/Test/System.Net/WebClientTest.cs [new file with mode: 0644]

index 541ed801e001fac9c01ff3de5ec871f34e498c4d..afbfad8bc3e5c38b1a70db99ebe142b6e682aa55 100644 (file)
@@ -232,7 +232,7 @@ namespace System.Net
                        int cLength = (int) response.ContentLength;
                        int length = (cLength <= -1 || cLength > 8192) ? 8192 : cLength;
                        byte [] buffer = new byte [length];
-                       FileStream f = new FileStream (fileName, FileMode.CreateNew | FileMode.Truncate);
+                       FileStream f = new FileStream (fileName, FileMode.Create);
 
                        int nread = 0;
                        while ((nread = st.Read (buffer, 0, length)) != 0)
index ad175ecf611e41ad66e42a663ec5b55ec0cfc0d1..9834a89c08ba5494ea9bf02d2d90fa9df80c9f56 100644 (file)
@@ -184,6 +184,7 @@ System.Net/WebHeaderCollectionTest.cs
 System.Net/WebPermissionAttributeTest.cs
 System.Net/WebProxyTest.cs
 System.Net/WebRequestTest.cs
+System.Net/WebClientTest.cs
 System.Net.Configuration/ConnectionManagementSectionTest.cs
 System.Net.Configuration/HttpWebRequestElementTest.cs
 System.Net.Configuration/WebRequestModulesSectionTest.cs
diff --git a/mcs/class/System/Test/System.Net/WebClientTest.cs b/mcs/class/System/Test/System.Net/WebClientTest.cs
new file mode 100644 (file)
index 0000000..aa1e445
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// WebClientTest.cs - NUnit Test Cases for System.Net.WebClient
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Net;
+using System.Collections;
+using System.Runtime.Serialization;
+
+namespace MonoTests.System.Net {
+       [TestFixture]
+       public class WebClientTest {
+
+               [Test]
+               [Category ("InetAccess")]
+               public void DownloadTwice ()
+               {
+                       WebClient wc = new WebClient();
+                       string filename = Path.GetTempFileName();
+                       
+                       // A new, but empty file has been created. This is a test case
+                       // for bug 81005
+                       wc.DownloadFile("http://google.com/", filename);
+                       
+                       // Now, remove the file and attempt to download again.
+                       File.Delete(filename);
+                       wc.DownloadFile("http://google.com/", filename);
+
+                       // We merely want this to reach this point, bug 81066.
+               }
+       }
+       
+}