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 {
41 // NL -> Not listening -> tests when listener.IsListening == false
43 public void NL_DefaultProperties ()
45 HttpListener listener = new HttpListener ();
46 HLPC coll = listener.Prefixes;
47 Assert.AreEqual (0, coll.Count, "Count");
48 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
49 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
53 public void DefaultProperties ()
55 HttpListener listener = new HttpListener ();
56 HLPC coll = listener.Prefixes;
57 coll.Add ("http://127.0.0.1:8181/");
58 Assert.AreEqual (1, coll.Count, "Count");
59 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
60 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
66 HttpListener listener = new HttpListener ();
67 HLPC coll = listener.Prefixes;
69 coll.Add ("http://127.0.0.1:8181/");
70 Assert.AreEqual (1, coll.Count, "Count");
71 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
72 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
77 public void Duplicate ()
79 HttpListener listener = new HttpListener ();
80 HLPC coll = listener.Prefixes;
81 coll.Add ("http://127.0.0.1:8181/");
82 coll.Add ("http://127.0.0.1:8181/");
84 Assert.AreEqual (1, coll.Count, "Count");
85 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
86 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
91 public void EndsWithSlash ()
93 HttpListener listener = new HttpListener ();
94 listener.Prefixes.Add ("http://127.0.0.1:7777/");
98 public void DifferentPath ()
100 HttpListener listener = new HttpListener ();
101 listener.Prefixes.Add ("http://127.0.0.1:7777/");
102 listener.Prefixes.Add ("http://127.0.0.1:7777/hola/");
103 Assert.AreEqual (2, listener.Prefixes.Count, "#01");
107 public void NL_Clear ()
109 HttpListener listener = new HttpListener ();
110 HLPC coll = listener.Prefixes;
115 public void NL_Remove ()
117 HttpListener listener = new HttpListener ();
118 HLPC coll = listener.Prefixes;
119 Assert.IsFalse (coll.Remove ("http://127.0.0.1:8181/"));
123 public void NL_RemoveBadUri ()
125 HttpListener listener = new HttpListener ();
126 HLPC coll = listener.Prefixes;
127 Assert.IsFalse (coll.Remove ("httpblah://127.0.0.1:8181/"));
131 [ExpectedException (typeof (ArgumentException))]
132 public void NL_AddBadUri ()
134 HttpListener listener = new HttpListener ();
135 HLPC coll = listener.Prefixes;
136 coll.Add ("httpblah://127.0.0.1:8181/");
140 [ExpectedException (typeof (ArgumentException))]
141 public void NoHostInUrl ()
143 HttpListener listener = new HttpListener ();
144 listener.Prefixes.Add ("http://:7777/hola/");
148 public void MultipleSlashes ()
150 // this one throws on Start(), not when adding it.
151 // See same test name in HttpListenerTest.
152 HttpListener listener = new HttpListener ();
153 HLPC coll = listener.Prefixes;
154 coll.Add ("http://localhost:7777/hola////");
155 string [] strs = new string [1];
156 coll.CopyTo (strs, 0);
157 Assert.AreEqual ("http://localhost:7777/hola////", strs [0]);
161 public void PercentSign ()
163 HttpListener listener = new HttpListener ();
164 HLPC coll = listener.Prefixes;
165 // this one throws on Start(), not when adding it.
166 // See same test name in HttpListenerTest.
167 coll.Add ("http://localhost:7777/hola%3E/");
168 string [] strs = new string [1];
169 coll.CopyTo (strs, 0);
170 Assert.AreEqual ("http://localhost:7777/hola%3E/", strs [0]);
174 public void Disposed1 ()
176 HttpListener listener = new HttpListener ();
177 HLPC coll = listener.Prefixes;
179 Assert.AreEqual (0, coll.Count, "Count");
180 Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
181 Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
185 [ExpectedException (typeof (ObjectDisposedException))]
186 public void Disposed2 ()
188 HttpListener listener = new HttpListener ();
189 HLPC coll = listener.Prefixes;
191 coll.Add ("http://localhost:7777/hola/");
195 [ExpectedException (typeof (ObjectDisposedException))]
196 public void Disposed3 ()
198 HttpListener listener = new HttpListener ();
199 HLPC coll = listener.Prefixes;
205 [ExpectedException (typeof (ObjectDisposedException))]
206 public void Disposed4 ()
208 HttpListener listener = new HttpListener ();
209 HLPC coll = listener.Prefixes;
211 coll.Remove ("http://localhost:7777/hola/");
215 [ExpectedException (typeof (ObjectDisposedException))]
216 public void Disposed5 ()
218 HttpListener listener = new HttpListener ();
219 HLPC coll = listener.Prefixes;
221 string [] strs = new string [0];
222 coll.CopyTo (strs, 0);
226 public void Disposed6 ()
228 HttpListener listener = new HttpListener ();
229 HLPC coll = listener.Prefixes;
232 foreach (string s in coll) {
233 a = s; // just to make the compiler happy
239 public void Disposed7 ()
241 HttpListener listener = new HttpListener ();
242 HLPC coll = listener.Prefixes;
243 coll.Add ("http://127.0.0.1/");
246 foreach (string s in coll) {
248 Assert.AreEqual (s, "http://127.0.0.1/");
250 Assert.AreEqual (items, 1);