2 // HttpListenerPrefixCollectionTest.cs
3 // - Unit tests for System.Net.HttpListenePrefixCollection
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
33 using HLPC=System.Net.HttpListenerPrefixCollection;
35 namespace MonoTests.System.Net {
38 [Ignore ("The class System.Net.HttpListenerPrefixCollection - is not supported")]
40 public class HttpListenerPrefixCollectionTest {
42 // NL -> Not listening -> tests when listener.IsListening == false
44 public void NL_DefaultProperties ()
46 HttpListener listener = new HttpListener ();
47 HLPC coll = listener.Prefixes;
48 Assert.AreEqual (0, coll.Count, "Count");
49 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
50 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
54 public void DefaultProperties ()
56 HttpListener listener = new HttpListener ();
57 HLPC coll = listener.Prefixes;
58 coll.Add ("http://127.0.0.1:8181/");
59 Assert.AreEqual (1, coll.Count, "Count");
60 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
61 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
67 HttpListener listener = new HttpListener ();
68 HLPC coll = listener.Prefixes;
70 coll.Add ("http://127.0.0.1:8181/");
71 Assert.AreEqual (1, coll.Count, "Count");
72 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
73 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
78 public void Duplicate ()
80 HttpListener listener = new HttpListener ();
81 HLPC coll = listener.Prefixes;
82 coll.Add ("http://127.0.0.1:8181/");
83 coll.Add ("http://127.0.0.1:8181/");
85 Assert.AreEqual (1, coll.Count, "Count");
86 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
87 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
92 public void EndsWithSlash ()
94 HttpListener listener = new HttpListener ();
95 listener.Prefixes.Add ("http://127.0.0.1:7777/");
99 public void DifferentPath ()
101 HttpListener listener = new HttpListener ();
102 listener.Prefixes.Add ("http://127.0.0.1:7777/");
103 listener.Prefixes.Add ("http://127.0.0.1:7777/hola/");
104 Assert.AreEqual (2, listener.Prefixes.Count, "#01");
108 public void NL_Clear ()
110 HttpListener listener = new HttpListener ();
111 HLPC coll = listener.Prefixes;
116 public void NL_Remove ()
118 HttpListener listener = new HttpListener ();
119 HLPC coll = listener.Prefixes;
120 Assert.IsFalse (coll.Remove ("http://127.0.0.1:8181/"));
124 public void NL_RemoveBadUri ()
126 HttpListener listener = new HttpListener ();
127 HLPC coll = listener.Prefixes;
128 Assert.IsFalse (coll.Remove ("httpblah://127.0.0.1:8181/"));
132 [ExpectedException (typeof (ArgumentException))]
133 public void NL_AddBadUri ()
135 HttpListener listener = new HttpListener ();
136 HLPC coll = listener.Prefixes;
137 coll.Add ("httpblah://127.0.0.1:8181/");
141 [ExpectedException (typeof (ArgumentException))]
142 public void NoHostInUrl ()
144 HttpListener listener = new HttpListener ();
145 listener.Prefixes.Add ("http://:7777/hola/");
149 public void MultipleSlashes ()
151 // this one throws on Start(), not when adding it.
152 // See same test name in HttpListenerTest.
153 HttpListener listener = new HttpListener ();
154 HLPC coll = listener.Prefixes;
155 coll.Add ("http://localhost:7777/hola////");
156 string [] strs = new string [1];
157 coll.CopyTo (strs, 0);
158 Assert.AreEqual ("http://localhost:7777/hola////", strs [0]);
162 public void PercentSign ()
164 HttpListener listener = new HttpListener ();
165 HLPC coll = listener.Prefixes;
166 // this one throws on Start(), not when adding it.
167 // See same test name in HttpListenerTest.
168 coll.Add ("http://localhost:7777/hola%3E/");
169 string [] strs = new string [1];
170 coll.CopyTo (strs, 0);
171 Assert.AreEqual ("http://localhost:7777/hola%3E/", strs [0]);
175 public void Disposed1 ()
177 HttpListener listener = new HttpListener ();
178 HLPC coll = listener.Prefixes;
180 Assert.AreEqual (0, coll.Count, "Count");
181 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
182 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
186 [ExpectedException (typeof (ObjectDisposedException))]
187 public void Disposed2 ()
189 HttpListener listener = new HttpListener ();
190 HLPC coll = listener.Prefixes;
192 coll.Add ("http://localhost:7777/hola/");
196 [ExpectedException (typeof (ObjectDisposedException))]
197 public void Disposed3 ()
199 HttpListener listener = new HttpListener ();
200 HLPC coll = listener.Prefixes;
206 [ExpectedException (typeof (ObjectDisposedException))]
207 public void Disposed4 ()
209 HttpListener listener = new HttpListener ();
210 HLPC coll = listener.Prefixes;
212 coll.Remove ("http://localhost:7777/hola/");
216 [ExpectedException (typeof (ObjectDisposedException))]
217 public void Disposed5 ()
219 HttpListener listener = new HttpListener ();
220 HLPC coll = listener.Prefixes;
222 string [] strs = new string [0];
223 coll.CopyTo (strs, 0);
227 public void Disposed6 ()
229 HttpListener listener = new HttpListener ();
230 HLPC coll = listener.Prefixes;
233 foreach (string s in coll) {
234 a = s; // just to make the compiler happy
240 public void Disposed7 ()
242 HttpListener listener = new HttpListener ();
243 HLPC coll = listener.Prefixes;
244 coll.Add ("http://127.0.0.1/");
247 foreach (string s in coll) {
249 Assert.AreEqual (s, "http://127.0.0.1/");
251 Assert.AreEqual (items, 1);