DataSourceSelectArgumentsTest.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // DataSourceSelectArgumentsTest.cs - unit tests for System.Web.UI.DataSourceSelectArguments
  3. //
  4. // Author:
  5. // Igor Zelmanovich <[email protected]>
  6. //
  7. // Copyright (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
  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. #if NET_2_0
  29. using NUnit.Framework;
  30. using System;
  31. using System.IO;
  32. using System.Security.Permissions;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Collections;
  36. using System.Web.UI.WebControls;
  37. namespace MonoCasTests.System.Web.UI
  38. {
  39. [TestFixture]
  40. public class DataSourceSelectArgumentsTest
  41. {
  42. public class PockerDataSourceView : DataSourceView
  43. {
  44. public PockerDataSourceView ()
  45. : base (new ObjectDataSource (), "") {
  46. }
  47. public DataSourceCapabilities DataSourceCapabilities;
  48. public bool RaiseUnsupportedCapabilityErrorCalled;
  49. public override bool CanPage {
  50. get {
  51. return true;
  52. }
  53. }
  54. public override bool CanSort {
  55. get {
  56. return true;
  57. }
  58. }
  59. public override bool CanRetrieveTotalRowCount {
  60. get {
  61. return true;
  62. }
  63. }
  64. protected override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments) {
  65. throw new Exception ("The method or operation is not implemented.");
  66. }
  67. protected override void RaiseUnsupportedCapabilityError (DataSourceCapabilities capability) {
  68. RaiseUnsupportedCapabilityErrorCalled = true;
  69. DataSourceCapabilities = capability;
  70. }
  71. }
  72. [Test]
  73. public void Equals ()
  74. {
  75. DataSourceSelectArguments arg1 = new DataSourceSelectArguments ();
  76. DataSourceSelectArguments arg2 = DataSourceSelectArguments.Empty;
  77. Assert.IsTrue (arg1.Equals (arg2), "Equals#1");
  78. Assert.IsTrue (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#1");
  79. arg1.SortExpression = "sort";
  80. arg1.MaximumRows = 10;
  81. arg1.StartRowIndex = 5;
  82. arg1.RetrieveTotalRowCount = true;
  83. arg1.TotalRowCount = 30;
  84. Assert.IsFalse (arg1.Equals (arg2), "Equals#2");
  85. Assert.IsFalse (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#2");
  86. arg2.SortExpression = "sort";
  87. arg2.MaximumRows = 10;
  88. arg2.StartRowIndex = 5;
  89. Assert.IsFalse (arg1.Equals (arg2), "Equals#3");
  90. Assert.IsFalse (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#3");
  91. arg2.RetrieveTotalRowCount = true;
  92. arg2.TotalRowCount = 30;
  93. Assert.IsTrue (arg1.Equals (arg2), "Equals#4");
  94. Assert.IsTrue (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#4");
  95. }
  96. [Test]
  97. public void RaiseUnsupportedCapabilitiesError () {
  98. PockerDataSourceView view = new PockerDataSourceView ();
  99. DataSourceSelectArguments arg = new DataSourceSelectArguments ();
  100. arg.RaiseUnsupportedCapabilitiesError (view);
  101. Assert.IsFalse (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  102. view = new PockerDataSourceView ();
  103. arg = new DataSourceSelectArguments ();
  104. arg.StartRowIndex = 10;
  105. arg.RaiseUnsupportedCapabilitiesError (view);
  106. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  107. Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  108. view = new PockerDataSourceView ();
  109. arg = new DataSourceSelectArguments ();
  110. arg.MaximumRows = 5;
  111. arg.RaiseUnsupportedCapabilitiesError (view);
  112. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  113. Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  114. view = new PockerDataSourceView ();
  115. arg = new DataSourceSelectArguments ();
  116. arg.SortExpression = "Sort";
  117. arg.RaiseUnsupportedCapabilitiesError (view);
  118. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  119. Assert.AreEqual (DataSourceCapabilities.Sort, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  120. view = new PockerDataSourceView ();
  121. arg = new DataSourceSelectArguments ();
  122. arg.RetrieveTotalRowCount = true;
  123. arg.RaiseUnsupportedCapabilitiesError (view);
  124. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  125. Assert.AreEqual (DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  126. view = new PockerDataSourceView ();
  127. arg = new DataSourceSelectArguments ();
  128. arg.AddSupportedCapabilities (DataSourceCapabilities.Page | DataSourceCapabilities.Sort | DataSourceCapabilities.RetrieveTotalRowCount);
  129. arg.SortExpression = "Sort";
  130. arg.StartRowIndex = 10;
  131. arg.MaximumRows = 5;
  132. arg.RetrieveTotalRowCount = true;
  133. arg.RaiseUnsupportedCapabilitiesError (view);
  134. Assert.IsFalse (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  135. view = new PockerDataSourceView ();
  136. arg = new DataSourceSelectArguments ();
  137. arg.SortExpression = "Sort";
  138. arg.StartRowIndex = 10;
  139. arg.MaximumRows = 5;
  140. arg.RetrieveTotalRowCount = true;
  141. arg.RaiseUnsupportedCapabilitiesError (view);
  142. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  143. Assert.AreEqual (DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  144. view = new PockerDataSourceView ();
  145. arg = new DataSourceSelectArguments ();
  146. arg.SortExpression = "Sort";
  147. arg.StartRowIndex = 10;
  148. arg.MaximumRows = 5;
  149. arg.RaiseUnsupportedCapabilitiesError (view);
  150. Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
  151. Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
  152. }
  153. }
  154. }
  155. #endif