2 // RouteCollectionTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 Novell Inc. http://novell.com
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Web.Routing;
33 using NUnit.Framework;
35 namespace MonoTests.System.Web.Routing
38 public class RouteCollectionTest
41 public void ConstructorNullArgs ()
44 new RouteCollection (null);
48 public void AddNullMame ()
50 var c = new RouteCollection ();
51 // when name is null, no duplicate check is done.
52 c.Add (null, new Route (null, null));
53 c.Add (null, new Route (null, null));
57 public void AddDuplicateEmpty ()
59 var c = new RouteCollection ();
60 // when name is "", no duplicate check is done.
61 c.Add ("", new Route (null, null));
62 c.Add ("", new Route (null, null));
66 [ExpectedException (typeof (ArgumentException))]
67 public void AddDuplicateName ()
69 var c = new RouteCollection ();
70 c.Add ("x", new Route (null, null));
71 c.Add ("x", new Route (null, null));
75 public void IndexForNonExistent ()
77 Assert.IsNull (new RouteCollection () [null]);
81 public void IndexForExistent ()
83 var c = new RouteCollection ();
84 var r = new Route (null, null);
86 Assert.AreEqual (r, c ["x"]);
90 public void IndexForNonExistentAfterRemoval ()
92 var c = new RouteCollection ();
93 var r = new Route (null, null);
96 Assert.IsNull(c ["x"]);
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void GetRouteDataNullArg ()
103 new RouteCollection ().GetRouteData (null);
107 public void GetRouteDataForNonExistent ()
109 var rd = new RouteCollection ().GetRouteData (new HttpContextStub ("~/foo"));
114 public void GetRouteDataWrongPathNoRoute ()
116 new RouteCollection ().GetRouteData (new HttpContextStub (String.Empty, String.Empty));
120 comment out those tests; I cannot explain those tests.
123 [ExpectedException (typeof (ArgumentOutOfRangeException))]
124 public void GetRouteDataWrongPathOneRoute ()
126 var c = new RouteCollection ();
127 var r = new Route ("foo", null);
129 // it somehow causes ArgumentOutOfRangeException for
130 // Request.AppRelativeCurrentExecutionFilePath.
131 c.GetRouteData (new HttpContextStub (String.Empty, String.Empty));
135 public void GetRouteDataWrongPathOneRoute2 ()
137 var c = new RouteCollection ();
138 var r = new Route ("foo", null);
140 c.GetRouteData (new HttpContextStub ("/~", String.Empty));
145 [ExpectedException (typeof (NotImplementedException))]
146 public void GetRouteDataForPathInfoNIE ()
148 var c = new RouteCollection ();
149 var r = new Route ("foo", null);
151 // it retrieves PathInfo and then dies.
152 var rd = c.GetRouteData (new HttpContextStub ("~/foo"));
156 public void GetRouteDataForNullHandler ()
158 var c = new RouteCollection ();
159 var r = new Route ("foo", null); // allowed
161 var rd = c.GetRouteData (new HttpContextStub ("~/foo", String.Empty));
162 Assert.IsNotNull (rd, "#1");
163 Assert.AreEqual (r, rd.Route, "#2");