2 // HttpMethodConstraintTest.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
37 class MyHttpMethodConstraint : HttpMethodConstraint
39 public MyHttpMethodConstraint (params string [] args)
44 public bool CallMatch (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
46 return Match (httpContext, route, parameterName, values, routeDirection);
51 public class HttpMethodConstraintTest
54 [ExpectedException (typeof (ArgumentNullException))]
55 public void ConstructorNullArgs ()
57 new HttpMethodConstraint (null);
61 public void ConstructorEmptyArray ()
63 new HttpMethodConstraint (new string [0]);
67 [ExpectedException (typeof (ArgumentNullException))]
68 public void MatchNullContext ()
70 var c = new MyHttpMethodConstraint (new string [0]);
71 c.CallMatch (null, new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
75 [ExpectedException (typeof (ArgumentNullException))]
76 public void MatchNullRoute ()
78 var c = new MyHttpMethodConstraint (new string [0]);
79 c.CallMatch (new HttpContextStub (), null, "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
83 [ExpectedException (typeof (ArgumentNullException))]
84 public void MatchNullName ()
86 var c = new MyHttpMethodConstraint (new string [0]);
87 c.CallMatch (new HttpContextStub (), new Route (null, null), null, new RouteValueDictionary (), RouteDirection.IncomingRequest);
91 [ExpectedException (typeof (ArgumentNullException))]
92 public void MatchNullValues ()
94 var c = new MyHttpMethodConstraint (new string [0]);
95 c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", null, RouteDirection.IncomingRequest);
101 var c = new MyHttpMethodConstraint (new string [0]);
102 Assert.IsFalse (c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest));
106 [ExpectedException (typeof (NotImplementedException))]
107 public void MatchDependsOnRequest ()
109 // it tries to get HttpContext.Request only when HttpMethodConstraint actually has one or more values.
110 var c = new MyHttpMethodConstraint (new string [] {"GET"});
111 c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
115 public void Match2 ()
117 var c = new MyHttpMethodConstraint (new string [] {"GET"});
118 Assert.IsFalse (c.CallMatch (new HttpContextStub (""), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#1");
119 Assert.IsTrue (c.CallMatch (new HttpContextStub ("", "", "GET"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#2");
120 Assert.IsFalse (c.CallMatch (new HttpContextStub ("", "", "POST"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#3");
121 // LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
122 // Assert.IsFalse (c.CallMatch (new HttpContextStub ("", "", "get"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#4");