2 // ViaHeaderValueTest.cs
5 // Marek Safar <marek.safar@gmail.com>
7 // Copyright (C) 2011 Xamarin Inc (http://www.xamarin.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Collections;
31 using System.Collections.Generic;
32 using NUnit.Framework;
33 using System.Net.Http.Headers;
35 namespace MonoTests.System.Net.Http.Headers
38 public class ViaHeaderValueTest
41 public void Ctor_InvalidArguments ()
44 new ViaHeaderValue (null, "rb");
46 } catch (ArgumentException) {
50 new ViaHeaderValue (" ", null);
52 } catch (FormatException) {
56 new ViaHeaderValue ("a", null);
58 } catch (ArgumentException) {
62 new ViaHeaderValue ("a", "b", "::");
64 } catch (FormatException) {
68 new ViaHeaderValue ("a", "b", null, "(aaa");
70 } catch (FormatException) {
75 public void Ctor_ValidArguments ()
77 new ViaHeaderValue ("a", "b", null);
78 new ViaHeaderValue ("a", "b", null, null);
84 var value = new ViaHeaderValue ("ab", "x");
85 Assert.AreEqual (value, new ViaHeaderValue ("ab", "x"), "#1");
86 Assert.AreEqual (value, new ViaHeaderValue ("AB", "X"), "#2");
87 Assert.AreNotEqual (value, new ViaHeaderValue ("AA", "x"), "#3");
89 value = new ViaHeaderValue ("ab", "DD", "cc");
90 Assert.AreEqual (value, new ViaHeaderValue ("Ab", "DD", "cC"), "#4");
91 Assert.AreNotEqual (value, new ViaHeaderValue ("AB", "DD"), "#5");
92 Assert.AreNotEqual (value, new ViaHeaderValue ("Ab", "dd", "cc", "(c)"), "#6");
98 var res = ViaHeaderValue.Parse ("1.1 nowhere.com");
99 Assert.IsNull (res.ProtocolName, "#1");
100 Assert.AreEqual ("nowhere.com", res.ReceivedBy, "#2");
101 Assert.AreEqual ("1.1", res.ProtocolVersion, "#3");
102 Assert.AreEqual ("1.1 nowhere.com", res.ToString (), "#4");
104 res = ViaHeaderValue.Parse ("foo / 1.1 nowhere.com:43 ( lal ( a ) la ) ");
105 Assert.AreEqual ("foo", res.ProtocolName, "#10");
106 Assert.AreEqual ("1.1", res.ProtocolVersion, "#11");
107 Assert.AreEqual ("nowhere.com:43", res.ReceivedBy, "#12");
108 Assert.AreEqual ("( lal ( a ) la )", res.Comment, "#13");
109 Assert.AreEqual ("foo/1.1 nowhere.com:43 ( lal ( a ) la )", res.ToString (), "#14");
113 public void Parse_Invalid ()
116 ViaHeaderValue.Parse (null);
118 } catch (FormatException) {
122 ViaHeaderValue.Parse (" ");
124 } catch (FormatException) {
128 ViaHeaderValue.Parse ("a");
130 } catch (FormatException) {
134 ViaHeaderValue.Parse ("1 nowhere.com :43");
136 } catch (FormatException) {
141 public void Properties ()
143 var value = new ViaHeaderValue ("s", "p");
144 Assert.IsNull (value.ProtocolName, "#1");
145 Assert.AreEqual ("s", value.ProtocolVersion, "#2");
146 Assert.AreEqual ("p", value.ReceivedBy, "#3");
148 value = new ViaHeaderValue ("s", "rb", "name");
149 Assert.AreEqual ("name", value.ProtocolName, "#4");
150 Assert.AreEqual ("s", value.ProtocolVersion, "#5");
151 Assert.AreEqual ("rb", value.ReceivedBy, "#6");
153 value = new ViaHeaderValue ("s", "rb", "name", "(cmt)");
154 Assert.AreEqual ("name", value.ProtocolName, "#7");
155 Assert.AreEqual ("s", value.ProtocolVersion, "#8");
156 Assert.AreEqual ("rb", value.ReceivedBy, "#9");
157 Assert.AreEqual ("(cmt)", value.Comment, "#10");
161 public void TryParse ()
164 Assert.IsTrue (ViaHeaderValue.TryParse ("a b", out res), "#1");
165 Assert.AreEqual ("b", res.ReceivedBy, "#2");
166 Assert.AreEqual ("a", res.ProtocolVersion, "#3");
167 Assert.IsNull (res.Comment, "#4");
168 Assert.IsNull (res.ProtocolName, "#5");
172 public void TryParse_Invalid ()
175 Assert.IsFalse (ViaHeaderValue.TryParse ("", out res), "#1");
176 Assert.IsNull (res, "#2");