Bug 15574. XML deserialization recursion: add array type to known_types?
[mono.git] / mcs / class / System.Net.Http / Test / System.Net.Http.Headers / HttpHeadersTest.cs
1 //
2 // HttpHeadersTest.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
6 //
7 // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using NUnit.Framework;
33 using System.Net.Http.Headers;
34 using System.Linq;
35
36 namespace MonoTests.System.Net.Http.Headers
37 {
38         [TestFixture]
39         public class HttpHeadersTest
40         {
41                 HttpHeaders headers;
42
43                 class HttpHeadersMock : HttpHeaders
44                 {
45                 }
46
47                 [SetUp]
48                 public void Setup ()
49                 {
50                         headers = new HttpHeadersMock ();
51                 }
52
53                 [Test]
54                 public void Add ()
55                 {
56                         headers.Add ("aa", "value");
57                         headers.Add ("aa", "value");
58                         headers.Add ("Expires", (string) null);
59                 }
60
61                 [Test]
62                 public void Add_InvalidArguments ()
63                 {
64                         try {
65                                 headers.Add (null, "value");
66                                 Assert.Fail ("#1");
67                         } catch (ArgumentException) {
68                         }
69
70                         try {
71                                 headers.Add ("", "value");
72                                 Assert.Fail ("#2");
73                         } catch (ArgumentException) {
74                         }
75                 }
76
77                 [Test]
78                 public void Clear ()
79                 {
80                         headers.Add ("aa", "value");
81                         headers.Clear ();
82                 }
83
84                 [Test]
85                 public void GetEnumerator ()
86                 {
87                         headers.Add ("aa", "value");
88                         int i = 0;
89                         foreach (var entry in headers) {
90                                 ++i;
91                                 Assert.AreEqual ("aa", entry.Key);
92                                 var values = entry.Value.ToList ();
93                                 Assert.AreEqual (1, values.Count);
94                                 Assert.AreEqual ("value", values[0]);
95                         }
96
97                         Assert.AreEqual (1, i, "#10");
98                 }
99
100                 [Test]
101                 public void GetValues ()
102                 {
103                         headers.Add ("aa", "v");
104                         headers.Add ("aa", "v");
105
106                         var r = headers.GetValues ("aa").ToList ();
107                         Assert.AreEqual ("v", r[0], "#1");
108                         Assert.AreEqual ("v", r[1], "#2");
109                 }
110
111                 [Test]
112                 public void GetValues_Invalid ()
113                 {
114                         try {
115                                 headers.GetValues (null);
116                                 Assert.Fail ("#1");
117                         } catch (ArgumentException) {
118                         }
119
120                         try {
121                                 headers.GetValues ("  ");
122                                 Assert.Fail ("#2");
123                         } catch (FormatException) {
124                         }
125
126                         try {
127                                 headers.GetValues ("x");
128                                 Assert.Fail ("#3");
129                         } catch (InvalidOperationException) {
130                         }
131                 }
132
133                 [Test]
134                 public void ToStringTest ()
135                 {
136                         headers.Add ("aa", "v");
137                         headers.Add ("aa", "v");
138                         headers.Add ("x", "v");
139
140                         Assert.AreEqual ("aa: v, v\r\nx: v\r\n", headers.ToString ());
141                 }
142         }
143 }