Update mcs/class/System.Core/System/TimeZoneInfo.cs
[mono.git] / mcs / class / System.Web.Routing / Test / System.Web.Routing / HttpMethodConstraintTest.cs
1 //
2 // HttpMethodConstraintTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2008 Novell Inc. http://novell.com
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30 using System;
31 using System.Web;
32 using System.Web.Routing;
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Web.Routing
36 {
37         class MyHttpMethodConstraint : HttpMethodConstraint
38         {
39                 public MyHttpMethodConstraint (params string [] args)
40                         : base (args)
41                 {
42                 }
43
44                 public bool CallMatch (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
45                 {
46                         return Match (httpContext, route, parameterName, values, routeDirection);
47                 }
48         }
49
50         [TestFixture]
51         public class HttpMethodConstraintTest
52         {
53                 [Test]
54                 [ExpectedException (typeof (ArgumentNullException))]
55                 public void ConstructorNullArgs ()
56                 {
57                         new HttpMethodConstraint (null);
58                 }
59
60                 [Test]
61                 public void ConstructorEmptyArray ()
62                 {
63                         new HttpMethodConstraint (new string [0]);
64                 }
65
66                 [Test]
67                 [ExpectedException (typeof (ArgumentNullException))]
68                 public void MatchNullContext ()
69                 {
70                         var c = new MyHttpMethodConstraint (new string [0]);
71                         c.CallMatch (null, new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
72                 }
73
74                 [Test]
75                 [ExpectedException (typeof (ArgumentNullException))]
76                 public void MatchNullRoute ()
77                 {
78                         var c = new MyHttpMethodConstraint (new string [0]);
79                         c.CallMatch (new HttpContextStub (), null, "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
80                 }
81
82                 [Test]
83                 [ExpectedException (typeof (ArgumentNullException))]
84                 public void MatchNullName ()
85                 {
86                         var c = new MyHttpMethodConstraint (new string [0]);
87                         c.CallMatch (new HttpContextStub (), new Route (null, null), null, new RouteValueDictionary (), RouteDirection.IncomingRequest);
88                 }
89
90                 [Test]
91                 [ExpectedException (typeof (ArgumentNullException))]
92                 public void MatchNullValues ()
93                 {
94                         var c = new MyHttpMethodConstraint (new string [0]);
95                         c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", null, RouteDirection.IncomingRequest);
96                 }
97
98                 [Test]
99                 public void Match ()
100                 {
101                         var c = new MyHttpMethodConstraint (new string [0]);
102                         Assert.IsFalse (c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest));
103                 }
104
105                 [Test]
106                 [ExpectedException (typeof (NotImplementedException))]
107                 public void MatchDependsOnRequest ()
108                 {
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);
112                 }
113
114                 [Test]
115                 public void Match2 ()
116                 {
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");
123                 }
124         }
125 }