DataColumnExpressionTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Data;
  3. using NUnit.Framework;
  4. namespace Monotests_Mono.Data.SqlExpressions
  5. {
  6. [TestFixture]
  7. public class DataColumnExprTest
  8. {
  9. [Test]
  10. public void TestDataColumnExpr1 ()
  11. {
  12. DataTable table = new DataTable ();
  13. table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
  14. table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
  15. table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(Col_0.Value > 10, Col_1 + 5, 0)");
  16. DataRow row = table.NewRow ();
  17. row ["Col_0.Value"] = 20;
  18. row ["Col_1"] = 10;
  19. table.Rows.Add (row);
  20. Assert.AreEqual ((int)table.Rows[0][1] + 5, table.Rows[0][2], "#1");
  21. }
  22. [Test]
  23. public void TestDataColumnExpr2 ()
  24. {
  25. DataTable table = new DataTable ();
  26. table.Columns.Add ("Col_0.Value", Type.GetType ("System.Int32"));
  27. table.Columns.Add ("Col_1", Type.GetType ("System.Int32"));
  28. table.Columns.Add ("Result", Type.GetType ("System.Int32"), "IIF(Col_0.Value > 10, Col_1 + 5, 0)");
  29. DataRow row = table.NewRow ();
  30. row ["Col_0.Value"] = 9;
  31. row ["Col_1"] = 10;
  32. table.Rows.Add (row);
  33. Assert.AreEqual (0, (int)table.Rows[0][2], "#1");
  34. }
  35. }
  36. [TestFixture]
  37. public class DataColumnCharTest
  38. {
  39. private static DataTable _dt = new DataTable();
  40. [Test]
  41. public void Test1 ()
  42. {
  43. _dt.Columns.Add(new DataColumn("a", typeof(char)));
  44. AddData('1');
  45. AddData('2');
  46. AddData('3');
  47. AddData('A');
  48. Assert.AreEqual (true, FindRow("'A'"), "Test1-1 failed");
  49. Assert.AreEqual (true, FindRow("65"), "Test1-2 failed");
  50. Assert.AreEqual (true, FindRow("'1'"), "Test1-3 failed");
  51. }
  52. [Test]
  53. [ExpectedException(typeof(FormatException))]
  54. public void Test2 ()
  55. {
  56. FindRow("'65'");
  57. }
  58. [Test]
  59. public void Test3 ()
  60. {
  61. Assert.AreEqual (false, FindRow ("1"), "Test3-1 failed");
  62. }
  63. private static bool FindRow(string f)
  64. {
  65. string filter = string.Format("a = {0}", f);
  66. DataRow[] rows = _dt.Select(filter);
  67. if (rows.Length == 0)
  68. return false;
  69. else
  70. return true;
  71. }
  72. private static void AddData(char a)
  73. {
  74. DataRow row = _dt.NewRow();
  75. row["a"] = a;
  76. _dt.Rows.Add(row);
  77. }
  78. }
  79. }