Merge pull request #1936 from esdrubal/DotNetRelativeOrAbsolute
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / RouteParameterTest.cs
1 //
2 // Authors:
3 //      Marek Habersack <mhabersack@novell.com>
4 //
5 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 using System;
27 using System.Collections.Generic;
28 using System.Data;
29 using System.Web;
30 using System.Web.UI;
31 using System.Web.UI.WebControls;
32
33 using NUnit.Framework;
34 using MonoTests.Common;
35 using MonoTests.System.Web;
36
37 namespace MonoTests.System.Web.UI.WebControls
38 {
39         [TestFixture]
40         public class RouteParameterTest
41         {
42                 [Test]
43                 public void Constructor ()
44                 {
45                         var rp = new RouteParameter ();
46
47                         Assert.AreEqual (String.Empty, rp.RouteKey, "#A1");
48                         Assert.AreEqual (String.Empty, rp.Name, "#A2");
49                         Assert.AreEqual (TypeCode.Empty, rp.Type, "#A3");
50                         Assert.AreEqual (ParameterDirection.Input, rp.Direction, "#A4");
51                         Assert.IsNull (rp.DefaultValue, "#A5");
52                         Assert.AreEqual (DbType.Object, rp.DbType, "#A6");
53                         Assert.AreEqual (true, rp.ConvertEmptyStringToNull, "#A7");
54                         Assert.AreEqual (0, rp.Size, "#A8");
55                 }
56
57                 [Test]
58                 public void Constructor_RouteParameter ()
59                 {
60                         RouteParameter rp;
61                         RouteParameter original;
62
63                         AssertExtensions.Throws<NullReferenceException> (() => {
64                                 rp = new FakeRouteParameter ((RouteParameter) null);
65                         }, "#A1");
66
67                         original = new RouteParameter ("Name", "Key");
68                         rp = new FakeRouteParameter (original);
69
70                         Assert.AreEqual (original.Name, rp.Name, "#B1-2");
71                         Assert.AreEqual (original.RouteKey, rp.RouteKey, "#B1-3");
72                 }
73
74                 [Test]
75                 public void Constructor_String_String ()
76                 {
77                         RouteParameter rp;
78
79                         rp = new RouteParameter (null, "key");
80                         Assert.AreEqual (String.Empty, rp.Name, "#A1-1");
81                         Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
82
83                         rp = new RouteParameter ("name", null);
84                         Assert.AreEqual ("name", rp.Name, "#A2-1");
85                         Assert.AreEqual (String.Empty, rp.RouteKey, "#A2-2");
86                 }
87
88                 [Test]
89                 public void Constructor_String_DbType_String ()
90                 {
91                         RouteParameter rp;
92
93                         rp = new RouteParameter ("name", DbType.Int64, "key");
94                         Assert.AreEqual ("name", rp.Name, "#A1-1");
95                         Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
96                         Assert.AreEqual (DbType.Int64, rp.DbType, "#A1-3");
97
98                         Assert.AreEqual (TypeCode.Empty, rp.Type, "#A2");
99                 }
100
101                 [Test]
102                 public void Constructor_String_TypeCode_String ()
103                 {
104                         RouteParameter rp;
105
106                         rp = new RouteParameter ("name", TypeCode.Int64, "key");
107                         Assert.AreEqual ("name", rp.Name, "#A1-1");
108                         Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
109                         Assert.AreEqual (TypeCode.Int64, rp.Type, "#A1-3");
110
111                         Assert.AreEqual (DbType.Object, rp.DbType, "#A2");
112                 }
113
114                 [Test]
115                 public void Clone ()
116                 {
117                         RouteParameter rp;
118                         FakeRouteParameter original;
119
120                         original = new FakeRouteParameter ("name", TypeCode.Int64, "key");
121                         rp = original.DoClone () as RouteParameter;
122
123                         Assert.IsNotNull (rp, "#A1-1");
124                         Assert.AreNotSame (original, rp, "#A1-2");
125
126                         Assert.AreEqual (original.Name, rp.Name, "#A2-1");
127                         Assert.AreEqual (original.Type, rp.Type, "#A2-2");
128                         Assert.AreEqual (original.RouteKey, rp.RouteKey, "#A2-3");
129                 }
130
131                 [Test]
132                 public void Evaluate ()
133                 {
134                         var rp = new FakeRouteParameter ();
135                         FakeHttpWorkerRequest2 f;
136                         HttpContext ctx = HttpResponseTest.Cook (1, out f);
137
138                         Assert.IsNull (rp.DoEvaluate (null, new Control ()), "#A1-1");
139                         Assert.IsNull (rp.DoEvaluate (ctx, null), "#A1-2");
140                         AssertExtensions.Throws <NullReferenceException> (() => {
141                                 rp.DoEvaluate (ctx, new Control ());
142                         }, "#A1-2");
143                 }
144
145                 [Test]
146                 public void RouteKey ()
147                 {
148                         var rp = new RouteParameter ();
149
150                         rp.RouteKey = null;
151                         Assert.AreEqual (String.Empty, rp.RouteKey, "#A1");
152                 }
153         }
154
155         class FakeRouteParameter : RouteParameter
156         {
157                 public FakeRouteParameter ()
158                 { }
159
160                 public FakeRouteParameter (RouteParameter original)
161                         : base (original)
162                 { }
163
164                 public FakeRouteParameter (string name, TypeCode type, string routeKey)
165                         : base (name, type, routeKey)
166                 { }
167
168                 public Parameter DoClone ()
169                 {
170                         return Clone ();
171                 }
172
173                 public object DoEvaluate (HttpContext context, Control control)
174                 {
175                         return Evaluate (context, control);
176                 }
177         }
178 }