File: search.aspx.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (46 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
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;

		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 ());
		}
	}
}