2010-06-03 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Wed, 2 Jun 2010 23:12:20 +0000 (23:12 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Wed, 2 Jun 2010 23:12:20 +0000 (23:12 -0000)
* Parameter.cs, ControlParameter.cs, SessionParameter.cs,
CookieParameter.cs, FormParameter.cs, ProfileParameter.cs,
QueryStringParameter.cs: Evaluate is 'protected internal virtual'
in 4.0.

* RouteParameter.cs: implemented.

svn path=/trunk/mcs/; revision=158371

13 files changed:
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/ControlParameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/CookieParameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/FormParameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/Parameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/ProfileParameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/QueryStringParameter.cs
mcs/class/System.Web/System.Web.UI.WebControls/RouteParameter.cs [new file with mode: 0644]
mcs/class/System.Web/System.Web.UI.WebControls/SessionParameter.cs
mcs/class/System.Web/System.Web_test.dll.sources
mcs/class/System.Web/Test/System.Web.UI.WebControls/RouteParameterTest.cs [new file with mode: 0644]
mcs/class/System.Web/Test/System.Web/HttpResponseTest.cs
mcs/class/System.Web/net_4_0_System.Web.dll.sources

index 13241cdb4823a828a67f78f049207f2306654bbe..396b849404ff6354bcb6909ca0ae79fe6e04cd04 100644 (file)
@@ -1,3 +1,12 @@
+2010-06-03  Marek Habersack  <mhabersack@novell.com>
+
+       * Parameter.cs, ControlParameter.cs, SessionParameter.cs,
+       CookieParameter.cs, FormParameter.cs, ProfileParameter.cs,
+       QueryStringParameter.cs: Evaluate is 'protected internal virtual'
+       in 4.0.
+
+       * RouteParameter.cs: implemented.
+
 2010-04-28  Marek Habersack  <mhabersack@novell.com>
 
        * CheckBoxList.cs: do not modify list item status in LoadPostData
index 0c14622f03d5f3d40cd9a65d7a3ae3a27912131f..d54faa156f969da0304cc69a1694579e990db01c 100644 (file)
@@ -78,8 +78,12 @@ namespace System.Web.UI.WebControls {
                {
                        return new ControlParameter (this);
                }
-               
-               protected override object Evaluate (HttpContext ctx, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext ctx, Control control)
                {
                        if (control == null)
                                return null;
index 257ddc4b3a946eeab8763ec5f786af50448b2da4..9c3ba818ed6c3b986602e2284beb940da120d0ab 100644 (file)
@@ -68,8 +68,12 @@ namespace System.Web.UI.WebControls {
                {
                        return new CookieParameter (this);
                }
-               
-               protected override object Evaluate (HttpContext ctx, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext ctx, Control control)
                {
                        if (ctx == null || ctx.Request == null)
                                return null;
index cb9b9c4a35c3666244d508b88dca6307763362a7..9d52e82cda38d0a585df77a2c1924bdaae6f2938 100644 (file)
@@ -68,8 +68,12 @@ namespace System.Web.UI.WebControls {
                {
                        return new FormParameter (this);
                }
-               
-               protected override object Evaluate (HttpContext ctx, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext ctx, Control control)
                {
                        if (control == null || ctx.Request == null)
                                return null;
@@ -77,7 +81,7 @@ namespace System.Web.UI.WebControls {
                        return ctx.Request.Form [FormField];
                }
                
-           [DefaultValueAttribute ("")]
+               [DefaultValueAttribute ("")]
                public string FormField {
                        get {
                                string s = ViewState ["FormField"] as string;
index 81faca7b4bb51a4fb7a18867aeb5dd2afc92d896..c17c68bbbfb0edee800c9e34d0c9b9a1f881dd4c 100644 (file)
@@ -47,6 +47,9 @@ namespace System.Web.UI.WebControls {
 
                protected Parameter (Parameter original)
                {
+                       if (original == null)
+                               throw new NullReferenceException (".NET emulation");
+                       
                        this.DefaultValue = original.DefaultValue;
                        this.Direction = original.Direction;
                        this.ConvertEmptyStringToNull = original.ConvertEmptyStringToNull;
@@ -309,7 +312,7 @@ namespace System.Web.UI.WebControls {
                                if (s != null)
                                        return s;
                                
-                               return "";
+                               return String.Empty;
                        }
                        set {
                                
@@ -404,7 +407,12 @@ namespace System.Web.UI.WebControls {
                // returns the value of the control that it is bound to, while 
                // the QueryStringParameter object retrieves the current name/value pair from 
                // the HttpRequest object.
-               protected virtual object Evaluate (HttpContext context, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               virtual object Evaluate (HttpContext context, Control control)
                {
                        return null;
                }
index fcaa635ce78a4a396915cf85bef7db915b412fa3..2f0e63df86138f669558a66b0f1cd737d33e7b88 100644 (file)
@@ -68,8 +68,12 @@ namespace System.Web.UI.WebControls
                {
                        return new ProfileParameter (this);
                }
-
-               protected override object Evaluate (HttpContext context, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext context, Control control)
                {
                        if (context == null || context.Profile == null)
                                return null;
index bc51e81f7ee3856d1ea24865cfd0374671c8e3cc..26708b33846f04df7f51c5d168720cd3449d8711 100644 (file)
@@ -69,8 +69,12 @@ namespace System.Web.UI.WebControls {
                {
                        return new QueryStringParameter (this);
                }
-               
-               protected override object Evaluate (HttpContext ctx, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext ctx, Control control)
                {
                        if (ctx == null || ctx.Request == null)
                                return null;
@@ -78,7 +82,7 @@ namespace System.Web.UI.WebControls {
                        return ctx.Request.QueryString [QueryStringField];
                }
                
-           [DefaultValueAttribute ("")]
+               [DefaultValueAttribute ("")]
                public string QueryStringField {
                        get {
                                string s = ViewState ["QueryStringField"] as string;
diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/RouteParameter.cs b/mcs/class/System.Web/System.Web.UI.WebControls/RouteParameter.cs
new file mode 100644 (file)
index 0000000..4273ae5
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// Authors:
+//   Marek Habersack <mhabersack@novell.com>
+//
+// (C) 2010 Novell, Inc (http://novell.com/)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.ComponentModel;
+using System.Data;
+using System.Web.Routing;
+
+namespace System.Web.UI.WebControls
+{
+       [DefaultProperty ("RouteKey")]
+       public class RouteParameter : Parameter
+       {
+               string routeKey;
+               
+               [DefaultValue ("")]
+               public string RouteKey {
+                       get { return routeKey; }
+                       set { routeKey = value ?? String.Empty; }
+               }
+
+               public RouteParameter ()
+               {
+                       this.RouteKey = String.Empty;
+                       this.Name = String.Empty;
+                       this.Type = TypeCode.Empty;
+                       this.Direction = ParameterDirection.Input;
+                       this.DefaultValue = null;
+               }
+
+               protected RouteParameter (RouteParameter original)
+                       : base (original)
+               {
+                       this.RouteKey = original.RouteKey;
+               }
+
+               public RouteParameter (string name, string routeKey)
+                       : base (name)
+               {
+                       this.RouteKey = routeKey;
+               }
+
+               public RouteParameter (string name, DbType dbType, string routeKey)
+                       : base (name, dbType)
+               {
+                       this.RouteKey = routeKey;
+               }
+
+               public RouteParameter (string name, TypeCode type, string routeKey)
+                       : base (name, type)
+               {
+                       this.RouteKey = routeKey;
+               }
+               
+               protected override Parameter Clone ()
+               {
+                       return new RouteParameter (this);
+               }
+
+               protected internal override object Evaluate (HttpContext context, Control control)
+               {
+                       if (context == null || control == null)
+                               return null;
+
+                       Page p = control.Page;
+                       if (p == null)
+                               throw new NullReferenceException (".NET emulation");
+
+                       RouteData rd = p.RouteData;
+                       if (rd == null)
+                               return null;
+                       
+                       return rd.Values [RouteKey];
+               }
+       }
+}
index c4ea93feddd6a76f1ef4c0a8fbdf52b2e95cd58e..733550aaf39adf81d73386fd0417be267aa0b70f 100644 (file)
@@ -68,8 +68,12 @@ namespace System.Web.UI.WebControls {
                {
                        return new SessionParameter (this);
                }
-               
-               protected override object Evaluate (HttpContext ctx, Control control)
+#if NET_4_0
+               protected internal
+#else
+               protected
+#endif
+               override object Evaluate (HttpContext ctx, Control control)
                {
                        if (ctx == null || ctx.Session == null)
                                return null;
index 60b3431e1e7f194fde0724461ade6a1978cc2501..9a690258f86d10bb1dc13c30539166a3114862c2 100644 (file)
@@ -512,6 +512,7 @@ System.Web.UI.WebControls/RepeatInfoCas.cs
 System.Web.UI.WebControls/RequiredFieldValidatorCas.cs
 System.Web.UI.WebControls/RoleGroupCas.cs
 System.Web.UI.WebControls/RoleGroupCollectionCas.cs
+System.Web.UI.WebControls/RouteParameterTest.cs
 System.Web.UI.WebControls/SelectedDatesCollectionCas.cs
 System.Web.UI.WebControls/SiteMapPathTest.cs
 System.Web.UI.WebControls/StyleCas.cs
diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/RouteParameterTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/RouteParameterTest.cs
new file mode 100644 (file)
index 0000000..dccaf32
--- /dev/null
@@ -0,0 +1,180 @@
+//
+// Authors:
+//      Marek Habersack <mhabersack@novell.com>
+//
+// Copyright (C) 2010 Novell, Inc. (http://novell.com/)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+#if NET_4_0
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+using NUnit.Framework;
+using MonoTests.Common;
+using MonoTests.System.Web;
+
+namespace MonoTests.System.Web.UI.WebControls
+{
+       [TestFixture]
+       public class RouteParameterTest
+       {
+               [Test]
+               public void Constructor ()
+               {
+                       var rp = new RouteParameter ();
+
+                       Assert.AreEqual (String.Empty, rp.RouteKey, "#A1");
+                       Assert.AreEqual (String.Empty, rp.Name, "#A2");
+                       Assert.AreEqual (TypeCode.Empty, rp.Type, "#A3");
+                       Assert.AreEqual (ParameterDirection.Input, rp.Direction, "#A4");
+                       Assert.IsNull (rp.DefaultValue, "#A5");
+                       Assert.AreEqual (DbType.Object, rp.DbType, "#A6");
+                       Assert.AreEqual (true, rp.ConvertEmptyStringToNull, "#A7");
+                       Assert.AreEqual (0, rp.Size, "#A8");
+               }
+
+               [Test]
+               public void Constructor_RouteParameter ()
+               {
+                       RouteParameter rp;
+                       RouteParameter original;
+
+                       AssertExtensions.Throws<NullReferenceException> (() => {
+                               rp = new FakeRouteParameter ((RouteParameter) null);
+                       }, "#A1");
+
+                       original = new RouteParameter ("Name", "Key");
+                       rp = new FakeRouteParameter (original);
+
+                       Assert.AreEqual (original.Name, rp.Name, "#B1-2");
+                       Assert.AreEqual (original.RouteKey, rp.RouteKey, "#B1-3");
+               }
+
+               [Test]
+               public void Constructor_String_String ()
+               {
+                       RouteParameter rp;
+
+                       rp = new RouteParameter (null, "key");
+                       Assert.AreEqual (String.Empty, rp.Name, "#A1-1");
+                       Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
+
+                       rp = new RouteParameter ("name", null);
+                       Assert.AreEqual ("name", rp.Name, "#A2-1");
+                       Assert.AreEqual (String.Empty, rp.RouteKey, "#A2-2");
+               }
+
+               [Test]
+               public void Constructor_String_DbType_String ()
+               {
+                       RouteParameter rp;
+
+                       rp = new RouteParameter ("name", DbType.Int64, "key");
+                       Assert.AreEqual ("name", rp.Name, "#A1-1");
+                       Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
+                       Assert.AreEqual (DbType.Int64, rp.DbType, "#A1-3");
+
+                       Assert.AreEqual (TypeCode.Empty, rp.Type, "#A2");
+               }
+
+               [Test]
+               public void Constructor_String_TypeCode_String ()
+               {
+                       RouteParameter rp;
+
+                       rp = new RouteParameter ("name", TypeCode.Int64, "key");
+                       Assert.AreEqual ("name", rp.Name, "#A1-1");
+                       Assert.AreEqual ("key", rp.RouteKey, "#A1-2");
+                       Assert.AreEqual (TypeCode.Int64, rp.Type, "#A1-3");
+
+                       Assert.AreEqual (DbType.Object, rp.DbType, "#A2");
+               }
+
+               [Test]
+               public void Clone ()
+               {
+                       RouteParameter rp;
+                       FakeRouteParameter original;
+
+                       original = new FakeRouteParameter ("name", TypeCode.Int64, "key");
+                       rp = original.DoClone () as RouteParameter;
+
+                       Assert.IsNotNull (rp, "#A1-1");
+                       Assert.AreNotSame (original, rp, "#A1-2");
+
+                       Assert.AreEqual (original.Name, rp.Name, "#A2-1");
+                       Assert.AreEqual (original.Type, rp.Type, "#A2-2");
+                       Assert.AreEqual (original.RouteKey, rp.RouteKey, "#A2-3");
+               }
+
+               [Test]
+               public void Evaluate ()
+               {
+                       var rp = new FakeRouteParameter ();
+                       FakeHttpWorkerRequest2 f;
+                       HttpContext ctx = HttpResponseTest.Cook (1, out f);
+
+                       Assert.IsNull (rp.DoEvaluate (null, new Control ()), "#A1-1");
+                       Assert.IsNull (rp.DoEvaluate (ctx, null), "#A1-2");
+                       AssertExtensions.Throws <NullReferenceException> (() => {
+                               rp.DoEvaluate (ctx, new Control ());
+                       }, "#A1-2");
+               }
+
+               [Test]
+               public void RouteKey ()
+               {
+                       var rp = new RouteParameter ();
+
+                       rp.RouteKey = null;
+                       Assert.AreEqual (String.Empty, rp.RouteKey, "#A1");
+               }
+       }
+
+       class FakeRouteParameter : RouteParameter
+       {
+               public FakeRouteParameter ()
+               { }
+
+               public FakeRouteParameter (RouteParameter original)
+                       : base (original)
+               { }
+
+               public FakeRouteParameter (string name, TypeCode type, string routeKey)
+                       : base (name, type, routeKey)
+               { }
+
+               public Parameter DoClone ()
+               {
+                       return Clone ();
+               }
+
+               public object DoEvaluate (HttpContext context, Control control)
+               {
+                       return Evaluate (context, control);
+               }
+       }
+}
+#endif
\ No newline at end of file
index 4cb3734bebafc76ef289a1e56c43aa54a61f5690..bc7a6d90a561f870dba78d17ddc8c8a9dac1224a 100644 (file)
@@ -246,7 +246,7 @@ namespace MonoTests.System.Web {
 
        [TestFixture]
        public class HttpResponseTest {
-               HttpContext Cook (int re, out FakeHttpWorkerRequest2 f)
+               public static HttpContext Cook (int re, out FakeHttpWorkerRequest2 f)
                {
                        f = new FakeHttpWorkerRequest2 (re);
                        HttpContext c = new HttpContext (f);
index 19379446079f57d498af7077e73ce523b427176a..69caf4362b6e843d6b5dcdcd89ff627f3480132d 100644 (file)
@@ -22,6 +22,7 @@ System.Web.UI.WebControls/IDataBoundControl.cs
 System.Web.UI.WebControls/IDataBoundItemControl.cs
 System.Web.UI.WebControls/IDataBoundListControl.cs
 System.Web.UI.WebControls/IFieldControl.cs
+System.Web.UI.WebControls/RouteParameter.cs
 System.Web.Util/RequestValidationSource.cs
 System.Web.Util/RequestValidator.cs