2 // DataSourceSelectArgumentsTest.cs - unit tests for System.Web.UI.DataSourceSelectArguments
\r
5 // Igor Zelmanovich <igorz@mainsoft.com>
\r
7 // Copyright (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
30 using NUnit.Framework;
\r
34 using System.Security.Permissions;
\r
36 using System.Web.UI;
\r
37 using System.Collections;
\r
38 using System.Web.UI.WebControls;
\r
40 namespace MonoCasTests.System.Web.UI
\r
44 public class DataSourceSelectArgumentsTest
\r
47 public class PockerDataSourceView : DataSourceView
\r
49 public PockerDataSourceView ()
\r
50 : base (new ObjectDataSource (), "") {
\r
53 public DataSourceCapabilities DataSourceCapabilities;
\r
54 public bool RaiseUnsupportedCapabilityErrorCalled;
\r
56 public override bool CanPage {
\r
62 public override bool CanSort {
\r
68 public override bool CanRetrieveTotalRowCount {
\r
74 protected override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments) {
\r
75 throw new Exception ("The method or operation is not implemented.");
\r
78 protected override void RaiseUnsupportedCapabilityError (DataSourceCapabilities capability) {
\r
79 RaiseUnsupportedCapabilityErrorCalled = true;
\r
80 DataSourceCapabilities = capability;
\r
85 public void Equals ()
\r
87 DataSourceSelectArguments arg1 = new DataSourceSelectArguments ();
\r
88 DataSourceSelectArguments arg2 = DataSourceSelectArguments.Empty;
\r
90 Assert.IsTrue (arg1.Equals (arg2), "Equals#1");
\r
91 Assert.IsTrue (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#1");
\r
93 arg1.SortExpression = "sort";
\r
94 arg1.MaximumRows = 10;
\r
95 arg1.StartRowIndex = 5;
\r
96 arg1.RetrieveTotalRowCount = true;
\r
97 arg1.TotalRowCount = 30;
\r
99 Assert.IsFalse (arg1.Equals (arg2), "Equals#2");
\r
100 Assert.IsFalse (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#2");
\r
102 arg2.SortExpression = "sort";
\r
103 arg2.MaximumRows = 10;
\r
104 arg2.StartRowIndex = 5;
\r
106 Assert.IsFalse (arg1.Equals (arg2), "Equals#3");
\r
107 Assert.IsFalse (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#3");
\r
109 arg2.RetrieveTotalRowCount = true;
\r
110 arg2.TotalRowCount = 30;
\r
112 Assert.IsTrue (arg1.Equals (arg2), "Equals#4");
\r
113 Assert.IsTrue (arg1.GetHashCode () == arg2.GetHashCode (), "GetHashCode#4");
\r
117 public void RaiseUnsupportedCapabilitiesError () {
\r
118 PockerDataSourceView view = new PockerDataSourceView ();
\r
119 DataSourceSelectArguments arg = new DataSourceSelectArguments ();
\r
120 arg.RaiseUnsupportedCapabilitiesError (view);
\r
121 Assert.IsFalse (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
123 view = new PockerDataSourceView ();
\r
124 arg = new DataSourceSelectArguments ();
\r
125 arg.StartRowIndex = 10;
\r
126 arg.RaiseUnsupportedCapabilitiesError (view);
\r
127 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
128 Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
130 view = new PockerDataSourceView ();
\r
131 arg = new DataSourceSelectArguments ();
\r
132 arg.MaximumRows = 5;
\r
133 arg.RaiseUnsupportedCapabilitiesError (view);
\r
134 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
135 Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
137 view = new PockerDataSourceView ();
\r
138 arg = new DataSourceSelectArguments ();
\r
139 arg.SortExpression = "Sort";
\r
140 arg.RaiseUnsupportedCapabilitiesError (view);
\r
141 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
142 Assert.AreEqual (DataSourceCapabilities.Sort, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
144 view = new PockerDataSourceView ();
\r
145 arg = new DataSourceSelectArguments ();
\r
146 arg.RetrieveTotalRowCount = true;
\r
147 arg.RaiseUnsupportedCapabilitiesError (view);
\r
148 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
149 Assert.AreEqual (DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
151 view = new PockerDataSourceView ();
\r
152 arg = new DataSourceSelectArguments ();
\r
153 arg.AddSupportedCapabilities (DataSourceCapabilities.Page | DataSourceCapabilities.Sort | DataSourceCapabilities.RetrieveTotalRowCount);
\r
154 arg.SortExpression = "Sort";
\r
155 arg.StartRowIndex = 10;
\r
156 arg.MaximumRows = 5;
\r
157 arg.RetrieveTotalRowCount = true;
\r
158 arg.RaiseUnsupportedCapabilitiesError (view);
\r
159 Assert.IsFalse (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
161 view = new PockerDataSourceView ();
\r
162 arg = new DataSourceSelectArguments ();
\r
163 arg.SortExpression = "Sort";
\r
164 arg.StartRowIndex = 10;
\r
165 arg.MaximumRows = 5;
\r
166 arg.RetrieveTotalRowCount = true;
\r
167 arg.RaiseUnsupportedCapabilitiesError (view);
\r
168 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
169 Assert.AreEqual (DataSourceCapabilities.RetrieveTotalRowCount, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
171 view = new PockerDataSourceView ();
\r
172 arg = new DataSourceSelectArguments ();
\r
173 arg.SortExpression = "Sort";
\r
174 arg.StartRowIndex = 10;
\r
175 arg.MaximumRows = 5;
\r
176 arg.RaiseUnsupportedCapabilitiesError (view);
\r
177 Assert.IsTrue (view.RaiseUnsupportedCapabilityErrorCalled, "RaiseUnsupportedCapabilitiesError");
\r
178 Assert.AreEqual (DataSourceCapabilities.Page, view.DataSourceCapabilities, "RaiseUnsupportedCapabilitiesError");
\r
182 public void Empty () {
\r
183 DataSourceSelectArguments arg1 = DataSourceSelectArguments.Empty;
\r
184 DataSourceSelectArguments arg2 = DataSourceSelectArguments.Empty;
\r
186 Assert.IsFalse (Object.ReferenceEquals (arg1, arg2), "Not Cached instance");
\r
190 public void SortExpression () {
\r
191 DataSourceSelectArguments arg1 = new DataSourceSelectArguments();
\r
192 Assert.IsNotNull (arg1.SortExpression, "SortExpression is not null #1");
\r
194 arg1 = new DataSourceSelectArguments (null);
\r
195 Assert.IsNotNull (arg1.SortExpression, "SortExpression is not null #2");
\r
197 arg1.SortExpression = null;
\r
198 Assert.IsNotNull (arg1.SortExpression, "SortExpression is not null #3");
\r