(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / Test / DataBinderTests.cs
blobb965660dfd972b7b5ef72d3f20fe2dccc84a3dac
1 //
2 // System.Web.UI.DataBinderTests
3 //
4 // Authors:
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
8 //
10 //#define NUNIT // Comment out this one if you wanna play with the test without using NUnit
12 #if NUNIT
13 using NUnit.Framework;
14 #else
15 using System.Reflection;
16 #endif
18 using System.IO;
19 using System;
20 using System.Text;
21 using System.Web;
22 using System.Web.UI;
23 using System.Runtime.CompilerServices;
25 namespace MonoTests.System.Web.UI
27 #if NUNIT
28 public class DataBinderTests : TestCase
30 #else
31 public class DataBinderTests
33 #endif
34 #if NUNIT
35 public static ITest Suite
37 get {
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 ()
47 #else
48 static DataBinderTests ()
50 #endif
51 instance = new ClassInstance ("instance");
52 instance.another = new ClassInstance ("another");
53 echo = new StringEcho();
56 static ClassInstance instance;
57 static StringEcho echo;
59 public void TestEval1 ()
61 try {
62 DataBinder.Eval (instance, "hello");
63 Fail ("Eval1 #1 didn't throw exception");
64 } catch (HttpException) {
67 object o = instance.Prop1;
68 AssertEquals ("Eval1 #2", DataBinder.Eval (instance, "Prop1"), o);
69 o = instance.Prop2;
70 AssertEquals ("Eval1 #3", DataBinder.Eval (instance, "Prop2"), o);
71 o = instance [0];
72 AssertEquals ("Eval1 #4", DataBinder.Eval (instance, "[0]"), o);
73 o = instance ["hi there!"];
74 AssertEquals ("Eval1 #4", DataBinder.Eval (instance, "[\"hi there!\"]"), o);
77 public void TestEval2 ()
79 try {
80 DataBinder.Eval (instance, "Another.hello");
81 Fail ("Eval2 #1 didn't throw exception");
82 } catch (HttpException) {
85 object o = instance.Another.Prop1;
86 AssertEquals ("Eval2 #2", DataBinder.Eval (instance, "Another.Prop1"), o);
87 o = instance.Another.Prop2;
88 AssertEquals ("Eval2 #3", DataBinder.Eval (instance, "Another.Prop2"), o);
89 o = instance.Another [0];
90 AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[0]"), o);
91 o = instance.Another ["hi there!"];
92 AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[\"hi there!\"]"), o);
93 AssertEquals ("Eval2 #5", DataBinder.Eval (instance,
94 "Another[\"hi there!\"] MS ignores this]"), o);
96 // MS gets fooled with this!!!
97 //AssertEquals ("Eval2 #4", DataBinder.Eval (instance, "Another[\"hi] there!\"]"), o);
100 public void TestEval3 ()
102 try {
103 DataBinder.Eval (echo, "[0]");
104 Fail ("Eval3 #1 didn't throw exception");
105 } catch (ArgumentException) {
108 AssertEquals ("Eval3 #2", DataBinder.Eval (echo, "[test]"), "test");
109 AssertEquals ("Eval3 #3", DataBinder.Eval (echo, "[\"test\"]"), "test");
110 AssertEquals ("Eval3 #4", DataBinder.Eval (echo, "['test']"), "test");
111 AssertEquals ("Eval3 #5", DataBinder.Eval (echo, "['test\"]"), "'test\"");
112 AssertEquals ("Eval3 #6", DataBinder.Eval (echo, "[\"test']"), "\"test'");
116 #if !NUNIT
117 void Assert (string msg, bool result)
119 if (!result)
120 Console.WriteLine (msg);
123 void AssertEquals (string msg, object expected, object real)
125 if (expected == null && real == null)
126 return;
128 if (expected != null && expected.Equals (real))
129 return;
131 Console.WriteLine ("{0}: expected: '{1}', got: '{2}'", msg, expected, real);
134 void Fail (string msg)
136 Console.WriteLine ("Failed: {0}", msg);
139 static void Main ()
141 DataBinderTests dbt = new DataBinderTests ();
142 Type t = typeof (DataBinderTests);
143 MethodInfo [] methods = t.GetMethods ();
144 foreach (MethodInfo m in methods) {
145 if (m.Name.Substring (0, 4) == "Test")
146 m.Invoke (dbt, null);
149 #endif
152 class ClassInstance
154 public string hello = "Hello";
155 public ClassInstance another;
156 string prefix;
158 public ClassInstance (string prefix)
160 this.prefix = prefix;
163 public object Prop1
165 get {
166 return prefix + "This is Prop1";
170 public object Prop2
172 get {
173 return prefix + "This is Prop2";
177 public object this [int index]
179 get {
180 return prefix + "This is the indexer for int. Index: " + index;
184 public object this [string index]
186 get {
187 return prefix + "This is the indexer for string. Index: " + index;
191 public ClassInstance Another
193 get {
194 return another;
199 class StringEcho
201 public object this [string msg] {
202 get { return msg; }