Merge pull request #1921 from mattzink/master
[mono.git] / mcs / class / System.Net.Http / Test / System.Net.Http / HttpResponseMessageTest.cs
index feb94158b819dcd512c89f2426a82f16a62999b6..b13e8cae417b606b62d8428c031f39966c4faf1f 100644 (file)
@@ -29,6 +29,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Text.RegularExpressions;
 using NUnit.Framework;
 using System.Net.Http;
 using System.Net;
@@ -293,6 +294,56 @@ namespace MonoTests.System.Net.Http
                        Assert.AreEqual (3, i, "#10");
                }
 
+               [Test]
+               public void Headers_MultiValues ()
+               {
+                       var message = new HttpResponseMessage ();
+                       var headers = message.Headers;
+
+                       headers.Add ("Proxy-Authenticate", "x, y, z,i");
+                       headers.Add ("Upgrade", "HTTP/2.0, SHTTP/1.3, IRC, RTA/x11");
+                       headers.Add ("Via", "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
+                       headers.Add ("Warning", "199 Miscellaneous \"w\", 200 a \"b\"");
+
+                       Assert.AreEqual (4, headers.ProxyAuthenticate.Count, "#1a");
+                       Assert.IsTrue (headers.ProxyAuthenticate.SequenceEqual (
+                               new[] {
+                                       new AuthenticationHeaderValue ("x"),
+
+                                       new AuthenticationHeaderValue ("y"),
+                                       new AuthenticationHeaderValue ("z"),
+                                       new AuthenticationHeaderValue ("i")
+                               }
+                       ), "#1b");
+
+                       
+                       Assert.AreEqual (4, headers.Upgrade.Count, "#2a");
+                       Assert.IsTrue (headers.Upgrade.SequenceEqual (
+                               new[] {
+                                       new ProductHeaderValue ("HTTP", "2.0"),
+                                       new ProductHeaderValue ("SHTTP", "1.3"),
+                                       new ProductHeaderValue ("IRC"),
+                                       new ProductHeaderValue ("RTA", "x11")
+                               }
+                       ), "#2b");
+
+                       Assert.AreEqual (2, headers.Via.Count, "#3a");
+                       Assert.IsTrue (headers.Via.SequenceEqual (
+                               new[] {
+                                       new ViaHeaderValue ("1.0", "fred"),
+                                       new ViaHeaderValue ("1.1", "nowhere.com", null, "(Apache/1.1)")
+                               }
+                       ), "#2b");
+
+                       Assert.AreEqual (2, headers.Warning.Count, "#4a");
+                       Assert.IsTrue (headers.Warning.SequenceEqual (
+                               new[] {
+                                       new WarningHeaderValue (199, "Miscellaneous", "\"w\""),
+                                       new WarningHeaderValue (200, "a", "\"b\"")
+                               }
+                       ), "#4b");
+               }
+
                [Test]
                public void Header_BaseImplementation ()
                {
@@ -431,7 +482,9 @@ namespace MonoTests.System.Net.Http
                        headers.Connection.Add ("Close");
                        Assert.IsTrue (headers.ConnectionClose.Value, "#4");
 
-                       Assert.AreEqual ("StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: <null>, Headers:\r\n{\r\nConnection: Close\r\n}", message.ToString (), "#5");
+                       // .NET encloses the "Connection: Close" with two whitespaces.
+                       var normalized = Regex.Replace (message.ToString (), @"\s", "");
+                       Assert.AreEqual ("StatusCode:200,ReasonPhrase:'OK',Version:1.1,Content:<null>,Headers:{Connection:Close}", normalized, "#5");
                }
 
                [Test]