Quellcode durchsuchen

2010-06-05 Marek Habersack <[email protected]>

	* PageRouteHandler.cs: implemented

2010-06-05  Marek Habersack  <[email protected]>

	* UrlRoutingModule.cs: 4.0 doesn't do the UrlRouting.axd magic, it
	simply remaps the current handler to the one obtained from the
	route.

2010-06-05  Marek Habersack  <[email protected]>

	* TemplateControlCompiler.cs: expression evaluation results are
	wrapped in a Convert.ConvertTo* call or a typecast.

	* RouteValueExpressionBuilder.cs: implemented

	* RouteUrlExpressionBuilder.cs: added missing custom attributes

svn path=/trunk/mcs/; revision=158497
Marek Habersack vor 15 Jahren
Ursprung
Commit
96b54e28f0

+ 6 - 0
mcs/class/System.Web.Routing/System.Web.Routing/ChangeLog

@@ -1,3 +1,9 @@
+2010-06-05  Marek Habersack  <[email protected]>
+
+	* UrlRoutingModule.cs: 4.0 doesn't do the UrlRouting.axd magic, it
+	simply remaps the current handler to the one obtained from the
+	route.
+
 2010-05-06  Marek Habersack  <[email protected]>
 
 	* RouteCollection.cs: GetVirtualPath throws ArgumentException

+ 9 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,12 @@
+2010-06-05  Marek Habersack  <[email protected]>
+
+	* TemplateControlCompiler.cs: expression evaluation results are
+	wrapped in a Convert.ConvertTo* call or a typecast.
+
+	* RouteValueExpressionBuilder.cs: implemented
+
+	* RouteUrlExpressionBuilder.cs: added missing custom attributes
+
 2010-06-01  Marek Habersack  <[email protected]>
 
 	* TemplateControlCompiler.cs: added new virtual method, 

+ 23 - 1
mcs/class/System.Web/System.Web.Compilation/RouteValueExpressionBuilder.cs

@@ -30,6 +30,8 @@
 
 using System;
 using System.CodeDom;
+using System.ComponentModel;
+using System.Reflection;
 using System.Web.UI;
 using System.Web.Routing;
 
@@ -48,6 +50,7 @@ namespace System.Web.Compilation
 		// This method is used only from within pages that aren't compiled
 		public override object EvaluateExpression (object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 		{
+			// Mono doesn't use this, so let's leave it like that for now
 			throw new NotImplementedException ();
 		}
 
@@ -75,7 +78,26 @@ namespace System.Web.Compilation
 			if (rd == null || String.IsNullOrEmpty (key))
 				return null;
 			
-			throw new NotImplementedException ();
+			object value = rd.Values [key];
+			if (value == null)
+				return null;
+
+			if (controlType == null || String.IsNullOrEmpty (propertyName) || !(value is string))
+				return value;
+
+			PropertyDescriptorCollection pcoll = TypeDescriptor.GetProperties (controlType);
+			if (pcoll == null || pcoll.Count == 0)
+				return value;
+
+			PropertyDescriptor pdesc = pcoll [propertyName];
+			if (pdesc == null)
+				return value;
+
+			TypeConverter cvt = pdesc.Converter;
+			if (cvt == null || !cvt.CanConvertFrom (typeof (string)))
+				return value;
+
+			return cvt.ConvertFrom (value);
 		}
 	}
 }

+ 4 - 0
mcs/class/System.Web/System.Web.Routing/ChangeLog

@@ -1,3 +1,7 @@
+2010-06-05  Marek Habersack  <[email protected]>
+
+	* PageRouteHandler.cs: implemented
+
 2009-06-16  Marek Habersack  <[email protected]>
 
 	* PageRouteHandler.cs: added

+ 1 - 1
mcs/class/System.Web/Test/standalone-runner-support/StandaloneTest.cs

@@ -136,7 +136,7 @@ namespace StandAloneRunnerSupport
 							Success = false;
 							throw new InvalidOperationException ("runner must not be null.");
 						}
-						result = runner.Run (tri.Url);
+						result = runner.Run (tri.Url, tri.PathInfo);
 						if (tri.Callback == null)
 							continue;
 

+ 4 - 0
mcs/class/System.Web/Test/standalone-runner-support/TestRunItem.cs

@@ -45,6 +45,10 @@ namespace StandAloneRunnerSupport
 			get; set;
 		}
 
+		public string PathInfo {
+			get; set;
+		}
+		
 		public string UrlDescription {
 			get; set;
 		}

+ 12 - 2
mcs/class/System.Web/Test/standalone-runner-support/TestRunner.cs

@@ -46,8 +46,13 @@ namespace StandAloneRunnerSupport
 		public TestRunner ()
 		{
 		}
-		
+
 		public string Run (string url)
+		{
+			return Run (url, null);
+		}
+		
+		public string Run (string url, string pathInfo)
 		{
 			ResetState ();
 			
@@ -67,7 +72,12 @@ namespace StandAloneRunnerSupport
 				if (!String.IsNullOrEmpty (query) && query [0] == '?')
 					query = query.Substring (1);
 				
-				var wr = new TestWorkerRequest (uri.AbsolutePath, query, output);
+				TestWorkerRequest wr;
+				
+				if (pathInfo != null)
+					wr = new TestWorkerRequest (uri.AbsolutePath, query, pathInfo, output);
+				else
+					wr = new TestWorkerRequest (uri.AbsolutePath, query, output);
 				
 				HttpRuntime.ProcessRequest (wr);
 				return output.ToString ();

+ 15 - 0
mcs/class/System.Web/Test/standalone-runner-support/TestWorkerRequest.cs

@@ -39,13 +39,20 @@ namespace StandAloneRunnerSupport
 		string page;
 		string query;
 		string appVirtualDir;
+		string pathInfo;
 		
 		public TestWorkerRequest (string page, string query, TextWriter output)
+			: this (page, query, null, output)
+		{
+		}
+		
+		public TestWorkerRequest (string page, string query, string pathInfo, TextWriter output)
 			: base (page, query, output)
 		{
 			this.page = page;
 			this.query = query;
 			this.appVirtualDir = GetAppPath ();
+			this.pathInfo = pathInfo;
 		}
 
 		public override string GetFilePath ()
@@ -53,6 +60,14 @@ namespace StandAloneRunnerSupport
 			return page;
 		}
 
+		public override string GetPathInfo ()
+		{
+			if (pathInfo == null)
+				return base.GetPathInfo ();
+
+			return pathInfo;
+		}
+		
 		public override string GetRawUrl ()
 		{
 			return TrimLeadingSlash (base.GetRawUrl ());

+ 174 - 0
mcs/class/System.Web/Test/standalone-tests/WebFormsRouting.cs

@@ -0,0 +1,174 @@
+//
+// Authors:
+//   Marek Habersack ([email protected])
+//
+// (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.Configuration;
+using System.Configuration.Provider;
+using System.IO;
+using System.Web;
+using System.Web.Hosting;
+
+using StandAloneRunnerSupport;
+using StandAloneTests;
+
+using NUnit.Framework;
+
+namespace StandAloneTests.WebFormsRouting
+{
+	[TestCase ("WebFormsRouting 01", "Web forms routing")]
+	public sealed class WebFormsRouting_01 : ITestCase
+	{
+		public string PhysicalPath {
+			get {
+				return Path.Combine (Consts.BasePhysicalDir, "WebFormsRouting");
+			}
+		}
+		
+		public string VirtualPath  {
+			get { return "/"; }
+		}
+
+		public bool SetUp (List <TestRunItem> runItems)
+		{
+			runItems.Add (new TestRunItem ("/Default.aspx", Default_Aspx));
+			runItems.Add (new TestRunItem ("/search/test", Search_Test));
+			runItems.Add (new TestRunItem ("/search/true", Search_True));
+			runItems.Add (new TestRunItem ("/search/red", Search_Red));
+			
+			return true;
+		}
+	
+		void Default_Aspx (string result, TestRunItem runItem)
+		{
+			string originalHtml = @"<a href=""/search/test"">Search for 'test'</a>";
+			
+			Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+		}
+
+		void Search_Test (string result, TestRunItem runItem)
+		{
+			string originalHtml = @"Search term is: <span id=""label1"">test</span><br />
+	Search term from expression is: <span id=""label2"">test</span><br />
+	<pre id=""testLog"">.: Missing key (key: &#39;SearchTermd&#39;)
+	Returned null.
+.: Missing property (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: test
+.: No converter (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: test
+.: Valid conversion to target (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.FormatException&#39; caught
+.: Invalid conversion to target (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.Exception&#39; caught
+.: Complex type converter (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.Exception&#39; caught
+.: Null controlType (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: test
+.: Null propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: test
+.: Empty propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: test
+.: Non-string value (key: &#39;intValue&#39;)
+	Returned value of type &#39;System.Int32&#39;: 123
+.: Non-string value (key: &#39;boolValue&#39;)
+	Returned value of type &#39;System.Boolean&#39;: False
+.: Non-string value (key: &#39;doubleValue&#39;)
+	Returned value of type &#39;System.Double&#39;: 1,23
+</pre>";
+			
+			Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+		}
+
+		void Search_True (string result, TestRunItem runItem)
+		{
+			string originalHtml = @"Search term is: <span id=""label1"">true</span><br />
+	Search term from expression is: <span id=""label2"">true</span><br />
+	<pre id=""testLog"">.: Missing key (key: &#39;SearchTermd&#39;)
+	Returned null.
+.: Missing property (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: true
+.: No converter (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: true
+.: Valid conversion to target (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.Boolean&#39;: True
+.: Invalid conversion to target (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.Exception&#39; caught
+.: Complex type converter (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.Exception&#39; caught
+.: Null controlType (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: true
+.: Null propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: true
+.: Empty propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: true
+.: Non-string value (key: &#39;intValue&#39;)
+	Returned value of type &#39;System.Int32&#39;: 123
+.: Non-string value (key: &#39;boolValue&#39;)
+	Returned value of type &#39;System.Boolean&#39;: False
+.: Non-string value (key: &#39;doubleValue&#39;)
+	Returned value of type &#39;System.Double&#39;: 1,23
+</pre>";
+			
+			Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+		}
+
+		void Search_Red (string result, TestRunItem runItem)
+		{
+			string originalHtml = @"Search term is: <span id=""label1"">red</span><br /> 
+	Search term from expression is: <span id=""label2"">red</span><br /> 
+	<pre id=""testLog"">.: Missing key (key: &#39;SearchTermd&#39;)
+	Returned null.
+.: Missing property (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: red
+.: No converter (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: red
+.: Valid conversion to target (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.FormatException&#39; caught
+.: Invalid conversion to target (key: &#39;SearchTerm&#39;)
+	Exception &#39;System.Exception&#39; caught
+.: Complex type converter (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.Drawing.Color&#39;: Color [Red]
+.: Null controlType (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: red
+.: Null propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: red
+.: Empty propertyName (key: &#39;SearchTerm&#39;)
+	Returned value of type &#39;System.String&#39;: red
+.: Non-string value (key: &#39;intValue&#39;)
+	Returned value of type &#39;System.Int32&#39;: 123
+.: Non-string value (key: &#39;boolValue&#39;)
+	Returned value of type &#39;System.Boolean&#39;: False
+.: Non-string value (key: &#39;doubleValue&#39;)
+	Returned value of type &#39;System.Double&#39;: 1,23
+</pre>";
+			
+			Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+		}
+	}
+}
+#endif

+ 1 - 1
mcs/class/System.Web/Test/standalone/WebFormsRouting/Default.aspx

@@ -9,7 +9,7 @@
 <body>
     <form id="form1" runat="server">
     <div>
-	<asp:HyperLink runat="server" NavigateUrl="<%$RouteUrl:SearchTerm=test%>">Search for 'test'</asp:HyperLink>
+	<%= AppDomain.CurrentDomain.GetData ("BEGIN_CODE_MARKER") %><asp:HyperLink runat="server" NavigateUrl="<%$RouteUrl:SearchTerm=test%>">Search for 'test'</asp:HyperLink><%= AppDomain.CurrentDomain.GetData ("END_CODE_MARKER") %>
     </div>
     </form>
 </body>

+ 8 - 1
mcs/class/System.Web/Test/standalone/WebFormsRouting/Global.asax.cs

@@ -7,7 +7,14 @@ public partial class _Global : HttpApplication
 {
 	void Application_Start (object sender, EventArgs e)
 	{
-		RouteTable.Routes.MapPageRoute ("SearchRoute", "search/{searchterm}", "~/search.aspx");
+		RouteTable.Routes.MapPageRoute ("SearchRoute", "search/{searchterm}", "~/search.aspx",
+						true,
+						new RouteValueDictionary { 
+							{ "intValue", 123 },
+							{ "boolValue", false },
+							{ "doubleValue", 1.23 }
+						},
+						null, null);
 		RouteTable.Routes.MapPageRoute ("UserRoute", "users/{username}", "~/users.aspx");
 	}
 }

+ 3 - 2
mcs/class/System.Web/Test/standalone/WebFormsRouting/search.aspx

@@ -9,8 +9,9 @@
 <body>
     <form id="form1" runat="server">
     <div>
-	Search term is: <asp:Label runat="server" ID="label1" /><br />
-	Search term from expression is: <asp:Label ID="label2" runat="server" Text="<%$RouteValue:SearchTerm%>" />
+	<%= AppDomain.CurrentDomain.GetData ("BEGIN_CODE_MARKER") %>Search term is: <asp:Label runat="server" ID="label1" /><br />
+	Search term from expression is: <asp:Label ID="label2" runat="server" Text="<%$RouteValue:SearchTerm%>" /><br />
+	<pre runat="server" id="testLog" /><%= AppDomain.CurrentDomain.GetData ("END_CODE_MARKER") %>
     </div>
     </form>
 </body>

+ 37 - 6
mcs/class/System.Web/Test/standalone/WebFormsRouting/search.aspx.cs

@@ -1,15 +1,46 @@
 using System;
 using System.Collections.Generic;
-using System.Linq;
+using System.Text;
 using System.Web;
+using System.Web.Compilation;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 
 public partial class search : System.Web.UI.Page
 {
-    protected void Page_Load(object sender, EventArgs e)
-    {
-	    string searchterm = Page.RouteData.Values ["searchterm"] as string;
-	    label1.Text = searchterm;
-    }
+	protected void Page_Load (object sender, EventArgs e)
+	{
+		string searchterm = Page.RouteData.Values ["searchterm"] as string;
+		label1.Text = searchterm;
+
+		var sb = new StringBuilder ();
+		RunTest (sb, "Missing key", "SearchTermd", typeof (Label), "Text");
+		RunTest (sb, "Missing property", "SearchTerm", typeof (Label), "NoSuchPropertyHere");
+		RunTest (sb, "No converter", "SearchTerm", typeof (Image), "Font");
+		RunTest (sb, "Valid conversion to target", "SearchTerm", typeof (Image), "Enabled");
+		RunTest (sb, "Invalid conversion to target", "SearchTerm", typeof (HotSpot), "TabIndex");
+		RunTest (sb, "Complex type converter", "SearchTerm", typeof (Style), "BackColor");
+		RunTest (sb, "Null controlType", "SearchTerm", null, "Text");
+		RunTest (sb, "Null propertyName", "SearchTerm", typeof (Label), null);
+		RunTest (sb, "Empty propertyName", "SearchTerm", typeof (Label), String.Empty);
+		RunTest (sb, "Non-string value", "intValue", typeof (Label), "Text");
+		RunTest (sb, "Non-string value", "boolValue", typeof (Label), "Text");
+		RunTest (sb, "Non-string value", "doubleValue", typeof (Label), "Text");
+
+		testLog.InnerText = sb.ToString ();
+	}
+
+	void RunTest (StringBuilder sb, string title, string key, Type controlType, string propertyName)
+	{
+		sb.AppendFormat (".: {0} (key: '{1}')\n", title, key);
+		try {
+			object val = RouteValueExpressionBuilder.GetRouteValue (this, key, controlType, propertyName);
+			if (val != null)
+				sb.AppendFormat ("\tReturned value of type '{0}': {1}\n", val.GetType (), val.ToString ());
+			else
+				sb.AppendFormat ("\tReturned null.\n");
+		} catch (Exception ex) {
+			sb.AppendFormat ("\tException '{0}' caught\n", ex.GetType ());
+		}
+	}
 }