Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / System.Net.Http / Test / System.Net.Http / StreamContentTest.cs
index 9db2950a785dae36f91b3846959fb012b330bc1e..413e459526e155331dd378ae912f78f61e99554e 100644 (file)
@@ -175,6 +175,18 @@ namespace MonoTests.System.Net.Http
                        Assert.IsTrue (hit, "#10");
                }
 
+               [Test]
+               public void CopyToAsync_ClosedInput ()
+               {
+                       var stream = new MemoryStream (new byte[] { 1 });
+                       var content = new StreamContent (stream);
+                       Assert.IsTrue (content.LoadIntoBufferAsync ().Wait (3000), "#1");
+                       stream.Close ();
+
+                       var stream_out = new MemoryStream (10);
+                       Assert.IsTrue (content.CopyToAsync (stream_out).Wait (3000), "#2");
+               }
+
                [Test]
                public void Headers ()
                {
@@ -296,6 +308,21 @@ namespace MonoTests.System.Net.Http
                        }
                }
 
+               [Test]
+               public void Headers_Multi ()
+               {
+                       var sc = new StreamContent (MemoryStream.Null);
+                       var headers = sc.Headers;
+
+                       headers.Add ("Allow", "");
+                       headers.Add ("Allow", "a , b, c");
+
+                       Assert.AreEqual (3, headers.Allow.Count, "#1a");
+                       Assert.IsTrue (headers.Allow.SequenceEqual (
+                               new[] { "a", "b", "c" }
+                       ), "#1b");
+               }
+
                [Test]
                public void LoadIntoBuffer ()
                {
@@ -319,7 +346,7 @@ namespace MonoTests.System.Net.Http
                                Assert.IsTrue (sc.LoadIntoBufferAsync (50).Wait (200));
                                Assert.Fail ("#1");
                        } catch (AggregateException e) {
-                               Assert.IsInstanceOfType (typeof (HttpRequestException), e.InnerException, "#2");
+                               Assert.IsTrue (e.InnerException is HttpRequestException, "#2");
                        }
                }
 
@@ -366,5 +393,19 @@ namespace MonoTests.System.Net.Http
                        var res = sc.ReadAsStreamAsync ().Result;
                        Assert.AreEqual (77, res.ReadByte (), "#1");
                }
+
+               [Test]
+               public void ReadAsStreamAsync_ClosedInput ()
+               {
+                       var stream = new MemoryStream (new byte[] { 1 });
+                       var content = new StreamContent (stream);
+                       Assert.IsTrue (content.LoadIntoBufferAsync ().Wait (3000), "#1");
+                       stream.Close ();
+
+                       var stream_read = content.ReadAsStreamAsync ().Result;
+                       Assert.IsTrue (stream_read.CanSeek, "#2");
+                       Assert.AreEqual (0, stream_read.Position, "#3");        
+                       Assert.AreEqual (1, stream_read.Length, "#4");
+               }
        }
 }