DataView_FindRows_O.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Authors:
  2. // Rafael Mizrahi <[email protected]>
  3. // Erez Lotan <[email protected]>
  4. // Oren Gurfinkel <[email protected]>
  5. // Ofer Borstein
  6. //
  7. // Copyright (c) 2004 Mainsoft Co.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using NUnit.Framework;
  29. using System;
  30. using System.Data;
  31. using GHTUtils;
  32. using GHTUtils.Base;
  33. namespace tests.system_data_dll.System_Data
  34. {
  35. [TestFixture] public class DataView_FindRows_O : GHTBase
  36. {
  37. [Test] public void Main()
  38. {
  39. DataView_FindRows_O tc = new DataView_FindRows_O();
  40. Exception exp = null;
  41. try
  42. {
  43. tc.BeginTest("DataView_FindRows_O");
  44. tc.run();
  45. }
  46. catch(Exception ex)
  47. {
  48. exp = ex;
  49. }
  50. finally
  51. {
  52. tc.EndTest(exp);
  53. }
  54. }
  55. //Activate This Construntor to log All To Standard output
  56. //public TestClass():base(true){}
  57. //Activate this constructor to log Failures to a log file
  58. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  59. //Activate this constructor to log All to a log file
  60. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  61. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  62. public void run()
  63. {
  64. Exception exp = null;
  65. DataRowView[] dvArr = null;
  66. //create the source datatable
  67. DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();
  68. //create the dataview for the table
  69. DataView dv = new DataView(dt);
  70. try
  71. {
  72. BeginCase("FindRows ,no sort - exception");
  73. try
  74. {
  75. dvArr = dv.FindRows(3);
  76. }
  77. catch (System.ArgumentException ex)
  78. {
  79. exp = ex;
  80. }
  81. Compare(exp.GetType().FullName,typeof(System.ArgumentException).FullName);
  82. exp=null;
  83. }
  84. catch(Exception ex) {exp = ex;}
  85. finally {EndCase(exp); exp = null;}
  86. dv.Sort = "String1";
  87. try
  88. {
  89. BeginCase("Find = wrong sort, can not find");
  90. dvArr = dv.FindRows(3);
  91. Compare(dvArr.Length ,0);
  92. exp=null;
  93. }
  94. catch(Exception ex) {exp = ex;}
  95. finally {EndCase(exp); exp = null;}
  96. dv.Sort = "ChildId";
  97. //get expected results
  98. DataRow[] drExpected = dt.Select("ChildId=3");
  99. try
  100. {
  101. BeginCase("FindRows - check count");
  102. dvArr = dv.FindRows(3);
  103. Compare(dvArr.Length,drExpected.Length );
  104. }
  105. catch(Exception ex) {exp = ex;}
  106. finally {EndCase(exp); exp = null;}
  107. try
  108. {
  109. BeginCase("FindRows - check data");
  110. //check that result is ok
  111. bool Succeed = true;
  112. for (int i=0; i<dvArr.Length ; i++)
  113. {
  114. Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected [i]["ChildId"];
  115. if (!Succeed) break;
  116. }
  117. Compare(Succeed ,true);
  118. }
  119. catch(Exception ex) {exp = ex;}
  120. finally {EndCase(exp); exp = null;}
  121. }
  122. }
  123. }