5 namespace Monotests_Mono.Data.SqlExpressions
8 public class DataColumnExprTest
11 public void TestDataColumnExpr0SingleColumnValue ()
13 DataTable table = new DataTable ();
14 table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
15 table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
16 table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(Col_0.Value <> 0, Col_1 + 5, 0)");
18 DataRow row = table.NewRow ();
19 row ["Col_0.Value"] = 0;
23 Assert.AreEqual (0, (int)table.Rows[0][2], "#1");
27 public void TestDataColumnLikeExpr ()
29 DataTable dt = new DataTable ();
30 dt.Columns.Add ("c1");
31 dt.Rows.Add (new string [] { null });
32 dt.Rows.Add (new string [] { "xax" });
33 dt.Columns.Add ("c2", typeof (bool), "c1 LIKE '%a%'");
34 //Assert.IsFalse ((bool) dt.Rows [0] [1]); ... cannot cast from DBNull to bool.
35 Assert.IsTrue ((bool) dt.Rows [1] [1]);
39 public void TestDataColumnExpr0Literal ()
41 DataTable table = new DataTable ();
42 table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
43 table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
44 table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(false, Col_1 + 5, 0)");
46 DataRow row = table.NewRow ();
47 row ["Col_0.Value"] = 0;
51 Assert.AreEqual (0, (int)table.Rows[0][2], "#1");
54 public void TestDataColumnExpr1 ()
56 DataTable table = new DataTable ();
57 table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
58 table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
59 table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(Col_0.Value > 10, Col_1 + 5, 0)");
61 DataRow row = table.NewRow ();
62 row ["Col_0.Value"] = 20;
66 Assert.AreEqual ((int)table.Rows[0][1] + 5, table.Rows[0][2], "#1");
69 public void TestDataColumnExpr2 ()
71 DataTable table = new DataTable ();
72 table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
73 table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
74 table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(Col_0.Value > 10, Col_1 + 5, 0)");
76 DataRow row = table.NewRow ();
77 row ["Col_0.Value"] = 9;
81 Assert.AreEqual (0, (int)table.Rows[0][2], "#1");
84 public void TestDataColumnSubstring ()
86 DataTable table = new DataTable ();
87 table.Columns.Add ("Col_0", Type.GetType ("System.String"));
88 table.Columns.Add ("Result", Type.GetType ("System.String"), "SUBSTRING(Col_0+'K?', 2+2, 2)");
90 DataRow row = table.NewRow ();
91 row ["Col_0"] = "Is O";
94 Assert.AreEqual ("OK", (string)table.Rows[0][1], "#1");
97 public void TestConcat ()
99 DataTable table = new DataTable ();
100 table.Columns.Add ("Result", Type.GetType ("System.Int32"), "'3' + '2'");
102 DataRow row = table.NewRow ();
104 table.Rows.Add (row);
105 Assert.AreEqual (32, table.Rows[0][0], "#1");
109 public void TestIsNull ()
111 DataTable table = new DataTable ();
112 table.Columns.Add ("Result", typeof(bool), "('3') IS NULL");
114 DataRow row = table.NewRow ();
116 table.Rows.Add (row);
117 Assert.AreEqual (false, table.Rows[0][0], "#1");
121 public class DataColumnCharTest
123 private static DataTable _dt = new DataTable();
128 _dt.Columns.Add(new DataColumn("a", typeof(char)));
135 Assert.AreEqual (true, FindRow("'A'"), "Test1-1 failed");
136 Assert.AreEqual (true, FindRow("65"), "Test1-2 failed");
137 Assert.AreEqual (true, FindRow("'1'"), "Test1-3 failed");
141 [ExpectedException(typeof(FormatException))]
149 Assert.AreEqual (false, FindRow ("1"), "Test3-1 failed");
152 private static bool FindRow(string f)
154 string filter = string.Format("a = {0}", f);
156 DataRow[] rows = _dt.Select(filter);
158 if (rows.Length == 0)
164 private static void AddData(char a)
166 DataRow row = _dt.NewRow();