2 // System.Web.UI.DataBinderTests
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 //#define NUNIT // Comment out this one if you wanna play with the test without using NUnit
13 using NUnit.Framework;
15 using System.Reflection;
23 using System.Runtime.CompilerServices;
25 namespace MonoTests.System.Web.UI
28 public class DataBinderTests : TestCase
31 public class DataBinderTests
35 public static ITest Suite
38 return new TestSuite (typeof (PathTest));
42 public DataBinderTests () : base ("MonoTests.System.Web.UI.DataBinderTests testcase") { }
43 public DataBinderTests (string name) : base (name) { }
45 protected override void SetUp ()
48 static DataBinderTests ()
51 instance = new ClassInstance ("instance");
52 instance.another = new ClassInstance ("another");
55 static ClassInstance instance;
57 public void TestEval1 ()
60 DataBinder.Eval (instance, "hello");
61 Fail ("Eval1 #1 didn't throw exception");
62 } catch (HttpException) {
65 object o = instance.Prop1;
66 AssertEquals ("Eval1 #2", DataBinder.Eval (instance, "Prop1"), o);
68 AssertEquals ("Eval1 #3", DataBinder.Eval (instance, "Prop2"), o);
70 AssertEquals ("Eval1 #4", DataBinder.Eval (instance, "[0]"), o);
71 o = instance ["hi there!"];
72 AssertEquals ("Eval1 #4", DataBinder.Eval (instance, "[\"hi there!\"]"), o);
75 public void TestEval2 ()
78 DataBinder.Eval (instance, "Another.hello");
79 Fail ("Eval2 #1 didn't throw exception");
80 } catch (HttpException) {
83 object o = instance.Another.Prop1;
84 AssertEquals ("Eval2 #2", DataBinder.Eval (instance, "Another.Prop1"), o);
85 o = instance.Another.Prop2;
86 AssertEquals ("Eval2 #3", DataBinder.Eval (instance, "Another.Prop2"), o);
87 o = instance.Another [0];
88 AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[0]"), o);
89 o = instance.Another ["hi there!"];
90 AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[\"hi there!\"]"), o);
91 AssertEquals ("Eval2 #5", DataBinder.Eval (instance,
92 "Another[\"hi there!\"] MS ignores this]"), o);
94 // MS gets fooled with this!!!
95 //AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[\"hi] there!\"]"), o);
99 void Assert (string msg, bool result)
102 Console.WriteLine (msg);
105 void AssertEquals (string msg, object expected, object real)
107 if (expected == null && real == null)
110 if (expected != null && expected.Equals (real))
113 Console.WriteLine ("{0}: expected: '{1}', got: '{2}'", msg, expected, real);
116 void Fail (string msg)
118 Console.WriteLine ("Failed: {0}", msg);
123 DataBinderTests dbt = new DataBinderTests ();
124 Type t = typeof (DataBinderTests);
125 MethodInfo [] methods = t.GetMethods ();
126 foreach (MethodInfo m in methods) {
127 if (m.Name.Substring (0, 4) == "Test")
128 m.Invoke (dbt, null);
136 public string hello = "Hello";
137 public ClassInstance another;
140 public ClassInstance (string prefix)
142 this.prefix = prefix;
148 return prefix + "This is Prop1";
155 return prefix + "This is Prop2";
159 public object this [int index]
162 return prefix + "This is the indexer for int. Index: " + index;
166 public object this [string index]
169 return prefix + "This is the indexer for string. Index: " + index;
173 public ClassInstance Another