2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 16 Oct 2008 14:20:23 +0000 (14:20 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 16 Oct 2008 14:20:23 +0000 (14:20 -0000)
* System.Web.Routing_test.dll.sources:
  added RouteValueDictionaryTest.cs.

* RouteValueDictionary.cs : object argument is actually for
  anonymous type instance.

* RouteValueDictionaryTest.cs : new test.

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

mcs/class/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/RouteValueDictionary.cs
mcs/class/System.Web.Routing/System.Web.Routing_test.dll.sources
mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteValueDictionaryTest.cs [new file with mode: 0644]

index c03dae0c74e9bc3b288cfaf69a284ea5775e046b..ec260b6ca3e127906ebd497af6e6602d28e080bc 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-16  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * System.Web.Routing_test.dll.sources:
+         added RouteValueDictionaryTest.cs.
+
 2008-09-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * System.Web.Routing_test.dll.sources: 
index 837fa054c0d932f091657e122e4d0f7522957000..4cda19e903b2ee6c1e429f6bca0d5cf1b5a1899e 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-16  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * RouteValueDictionary.cs : object argument is actually for
+         anonymous type instance.
+
 2008-10-10  Atsushi Enomoto  <atsushi@ximian.com>
 
        * UrlRoutingModule.cs : implement PostMapRequestHandler() and 
index c356a3d0aae8e24be7593a2321a39167fbfe696b..f6abac97aa90c8c21e46a381498ae8e583bc0151 100644 (file)
@@ -55,12 +55,15 @@ namespace System.Web.Routing
                                Add (p.Key, p.Value);
                }
 
-               public RouteValueDictionary (object values)
+               public RouteValueDictionary (object values) // anonymous type instance
                {
                        if (values == null)
-                               throw new ArgumentNullException ("values");
-                       foreach (var p in (IEnumerable<KeyValuePair<string,object>>) values)
-                               Add (p.Key, p.Value);
+                               return;
+
+                       foreach (var fi in values.GetType ().GetFields ())
+                               Add (fi.Name, fi.GetValue (values));
+                       foreach (var pi in values.GetType ().GetProperties ())
+                               Add (pi.Name, pi.GetValue (values, null));
                }
 
                public int Count {
@@ -80,7 +83,7 @@ namespace System.Web.Routing
                }
 
                public object this [string key] {
-                       get { return d [key]; }
+                       get { object v; return d.TryGetValue (key, out v) ? v : null; }
                        set { d [key] = value; }
                }
 
index 3f66118b683b8ce9c171491e00dc70f3fe232aa4..c2513f475316dcae17e4f05f04f06624c3142f00 100644 (file)
@@ -2,6 +2,7 @@ System.Web.Routing/HttpMethodConstraintTest.cs
 System.Web.Routing/RouteCollectionTest.cs
 System.Web.Routing/RouteDataTest.cs
 System.Web.Routing/RouteTest.cs
+System.Web.Routing/RouteValueDictionaryTest.cs
 System.Web.Routing/StopRoutingHandlerTest.cs
 System.Web.Routing/TestStubTypes.cs
 System.Web.Routing/UrlRoutingHandlerTest.cs
index 7604241a3b193e0fa3db1ceb9777e0d0a7ded52a..a0ca7e993f60a94916c9387d2bad5a3bed8d8de3 100644 (file)
@@ -1,3 +1,7 @@
+2008-10-16  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * RouteValueDictionaryTest.cs : new test.
+
 2008-10-10  Atsushi Enomoto  <atsushi@ximian.com>
 
        * UrlRoutingModuleTest.cs , TestStubTypes.cs : added test for
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteValueDictionaryTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteValueDictionaryTest.cs
new file mode 100644 (file)
index 0000000..0977693
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// RouteValueDictionaryTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 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.Collections.Generic;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class RouteValueDictionaryTest
+       {
+               [Test]
+               public void ConstructorNullArgs ()
+               {
+                       // null is allowed
+                       new RouteValueDictionary ((object) null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNullArgs2 ()
+               {
+                       new RouteValueDictionary ((IDictionary<string,object>) null);
+               }
+
+               [Test]
+               public void ConstructorObject ()
+               {
+                       var d = new RouteValueDictionary (new {Foo = "urn:foo", Bar = "urn:bar"});
+                       Assert.AreEqual ("urn:foo", d ["Foo"], "#1");
+                       Assert.AreEqual ("urn:bar", d ["Bar"], "#2");
+                       Assert.IsNull (d ["Baz"], "#3");
+               }
+       }
+}