3 // Marek Habersack <mhabersack@novell.com>
5 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
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:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
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.
27 using System.Collections.Generic;
31 using System.Web.UI.WebControls;
33 using NUnit.Framework;
34 using MonoTests.Common;
35 using MonoTests.System.Web;
37 namespace MonoTests.System.Web.UI.WebControls
40 public class RouteParameterTest
43 public void Constructor ()
45 var rp = new RouteParameter ();
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");
58 public void Constructor_RouteParameter ()
61 RouteParameter original;
63 AssertExtensions.Throws<NullReferenceException> (() => {
64 rp = new FakeRouteParameter ((RouteParameter) null);
67 original = new RouteParameter ("Name", "Key");
68 rp = new FakeRouteParameter (original);
70 Assert.AreEqual (original.Name, rp.Name, "#B1-2");
71 Assert.AreEqual (original.RouteKey, rp.RouteKey, "#B1-3");
75 public void Constructor_String_String ()
79 rp = new RouteParameter (null, "key");
80 Assert.AreEqual (String.Empty, rp.Name, "#A1-1");
81 Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
83 rp = new RouteParameter ("name", null);
84 Assert.AreEqual ("name", rp.Name, "#A2-1");
85 Assert.AreEqual (String.Empty, rp.RouteKey, "#A2-2");
89 public void Constructor_String_DbType_String ()
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");
98 Assert.AreEqual (TypeCode.Empty, rp.Type, "#A2");
102 public void Constructor_String_TypeCode_String ()
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");
111 Assert.AreEqual (DbType.Object, rp.DbType, "#A2");
118 FakeRouteParameter original;
120 original = new FakeRouteParameter ("name", TypeCode.Int64, "key");
121 rp = original.DoClone () as RouteParameter;
123 Assert.IsNotNull (rp, "#A1-1");
124 Assert.AreNotSame (original, rp, "#A1-2");
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");
132 public void Evaluate ()
134 var rp = new FakeRouteParameter ();
135 FakeHttpWorkerRequest2 f;
136 HttpContext ctx = HttpResponseTest.Cook (1, out f);
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 ());
146 public void RouteKey ()
148 var rp = new RouteParameter ();
151 Assert.AreEqual (String.Empty, rp.RouteKey, "#A1");
155 class FakeRouteParameter : RouteParameter
157 public FakeRouteParameter ()
160 public FakeRouteParameter (RouteParameter original)
164 public FakeRouteParameter (string name, TypeCode type, string routeKey)
165 : base (name, type, routeKey)
168 public Parameter DoClone ()
173 public object DoEvaluate (HttpContext context, Control control)
175 return Evaluate (context, control);