2 // Tests for System.Web.UI.WebControls.SqlDataSourceView
5 // Chris Toshok (toshok@novell.com)
9 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using NUnit.Framework;
35 using System.Configuration;
36 using System.Data.Common;
38 using System.Globalization;
41 using System.Web.UI.WebControls;
43 namespace MonoTests.System.Web.UI.WebControls
45 class SqlViewPoker : SqlDataSourceView {
46 public SqlViewPoker (SqlDataSource ds, string name, HttpContext context)
47 : base (ds, name, context)
52 public object SaveToViewState ()
54 return SaveViewState ();
57 public void LoadFromViewState (object savedState)
59 LoadViewState (savedState);
64 public class SqlDataSourceViewTest {
66 public void Defaults ()
68 SqlDataSource ds = new SqlDataSource ();
69 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
71 Assert.IsTrue (sql.CancelSelectOnNullParameter, "A1");
72 Assert.IsFalse (sql.CanDelete,"A2");
73 Assert.IsFalse (sql.CanInsert,"A3");
74 Assert.IsFalse (sql.CanPage,"A4");
75 Assert.IsFalse (sql.CanRetrieveTotalRowCount,"A5");
76 Assert.IsTrue (sql.CanSort,"A6");
77 Assert.IsFalse (sql.CanUpdate,"A7");
78 Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A8");
79 Assert.AreEqual ("", sql.DeleteCommand, "A9");
80 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A10");
81 Assert.IsNotNull (sql.DeleteParameters, "A11");
82 Assert.AreEqual (0, sql.DeleteParameters.Count, "A12");
83 Assert.AreEqual ("", sql.FilterExpression, "A13");
84 Assert.IsNotNull (sql.FilterParameters, "A14");
85 Assert.AreEqual (0, sql.FilterParameters.Count, "A15");
86 Assert.AreEqual ("", sql.InsertCommand, "A16");
87 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A17");
88 Assert.IsNotNull (sql.InsertParameters, "A18");
89 Assert.AreEqual (0, sql.InsertParameters.Count, "A19");
90 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A20");
91 Assert.AreEqual ("", sql.SelectCommand, "A21");
92 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A22");
93 Assert.IsNotNull (sql.SelectParameters, "A23");
94 Assert.AreEqual (0, sql.SelectParameters.Count, "A24");
95 Assert.AreEqual ("", sql.SortParameterName, "A25");
96 Assert.AreEqual ("", sql.UpdateCommand, "A26");
97 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A27");
98 Assert.IsNotNull (sql.UpdateParameters, "A28");
99 Assert.AreEqual (0, sql.UpdateParameters.Count, "A29");
103 [Category ("NotWorking")]
104 public void ViewState ()
106 SqlDataSource ds = new SqlDataSource ();
107 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
109 /* XXX test parameters */
111 sql.CancelSelectOnNullParameter = false;
112 sql.ConflictDetection = ConflictOptions.CompareAllValues;
113 sql.DeleteCommandType = SqlDataSourceCommandType.Text;
114 sql.DeleteCommand = "delete command";
115 sql.FilterExpression = "filter expression";
116 sql.InsertCommand = "insert command";
117 sql.InsertCommandType = SqlDataSourceCommandType.Text;
118 sql.OldValuesParameterFormatString = "{1}";
119 sql.SelectCommand = "select command";
120 sql.SelectCommandType = SqlDataSourceCommandType.Text;
121 sql.SortParameterName = "sort parameter";
122 sql.UpdateCommand = "update command";
123 sql.UpdateCommandType = SqlDataSourceCommandType.Text;
125 Assert.IsFalse (sql.CancelSelectOnNullParameter, "A1");
126 Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "A2");
127 Assert.AreEqual ("delete command", sql.DeleteCommand, "A3");
128 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
129 Assert.AreEqual ("filter expression", sql.FilterExpression, "A5");
130 Assert.AreEqual ("insert command", sql.InsertCommand, "A6");
131 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A7");
132 Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "A8");
133 Assert.AreEqual ("select command", sql.SelectCommand, "A9");
134 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A10");
135 Assert.AreEqual ("sort parameter", sql.SortParameterName, "A11");
136 Assert.AreEqual ("update command", sql.UpdateCommand, "A12");
137 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A13");
139 object state = sql.SaveToViewState();
141 sql = new SqlViewPoker (ds, "DefaultView", null);
142 sql.LoadFromViewState (state);
144 Assert.IsTrue(sql.CancelSelectOnNullParameter, "B1");
145 Assert.IsFalse(sql.CanDelete, "B2");
146 Assert.IsFalse(sql.CanInsert, "B3");
147 Assert.IsFalse(sql.CanPage, "B4");
148 Assert.IsFalse(sql.CanRetrieveTotalRowCount, "B5");
149 Assert.IsTrue(sql.CanSort, "B6");
150 Assert.IsFalse(sql.CanUpdate, "B7");
151 Assert.AreEqual(ConflictOptions.OverwriteChanges, sql.ConflictDetection, "B8");
152 Assert.AreEqual("", sql.DeleteCommand, "B9");
153 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B10");
154 Assert.IsNotNull(sql.DeleteParameters, "B11");
155 Assert.AreEqual(0, sql.DeleteParameters.Count, "B12");
156 Assert.AreEqual("", sql.FilterExpression, "B13");
157 Assert.IsNotNull(sql.FilterParameters, "B14");
158 Assert.AreEqual(0, sql.FilterParameters.Count, "B15");
159 Assert.AreEqual("", sql.InsertCommand, "B16");
160 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "B17");
161 Assert.IsNotNull(sql.InsertParameters, "B18");
162 Assert.AreEqual(0, sql.InsertParameters.Count, "B19");
163 Assert.AreEqual("{0}", sql.OldValuesParameterFormatString, "B20");
164 Assert.AreEqual("", sql.SelectCommand, "B21");
165 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "B22");
166 Assert.IsNotNull(sql.SelectParameters, "B23");
167 Assert.AreEqual(0, sql.SelectParameters.Count, "B24");
168 Assert.AreEqual("", sql.SortParameterName, "B25");
169 Assert.AreEqual("", sql.UpdateCommand, "B26");
170 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B27");
171 Assert.IsNotNull(sql.UpdateParameters, "B28");
172 Assert.AreEqual(0, sql.UpdateParameters.Count, "B29");
176 public void CanDelete ()
178 SqlDataSource ds = new SqlDataSource ();
179 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
181 sql.DeleteCommand = "DELETE from foo";
182 Assert.IsTrue (sql.CanDelete, "A1");
184 sql.DeleteCommand = "";
185 Assert.IsFalse (sql.CanDelete, "A2");
187 sql.DeleteCommand = null;
188 Assert.IsFalse (sql.CanDelete, "A3");
192 public void CanInsert ()
194 SqlDataSource ds = new SqlDataSource ();
195 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
197 sql.InsertCommand = "INSERT into foo";
198 Assert.IsTrue (sql.CanInsert, "A1");
200 sql.InsertCommand = "";
201 Assert.IsFalse (sql.CanInsert, "A2");
203 sql.InsertCommand = null;
204 Assert.IsFalse (sql.CanInsert, "A3");
208 public void CanUpdate ()
210 SqlDataSource ds = new SqlDataSource ();
211 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
213 sql.UpdateCommand = "UPDATE foo";
214 Assert.IsTrue (sql.CanUpdate, "A1");
216 sql.UpdateCommand = "";
217 Assert.IsFalse (sql.CanUpdate, "A2");
219 sql.UpdateCommand = null;
220 Assert.IsFalse (sql.CanUpdate, "A3");
224 public void CanSort ()
226 SqlDataSource ds = new SqlDataSource ();
227 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
229 sql.SortParameterName = "foo";
230 Assert.IsTrue (sql.CanSort, "A1");
232 sql.SortParameterName = null;
233 Assert.IsTrue (sql.CanSort, "A2");
235 sql.SortParameterName = "";
236 Assert.IsTrue (sql.CanSort, "A3");
238 sql.SortParameterName = "foo";
240 ds.DataSourceMode = SqlDataSourceMode.DataReader;
241 Assert.IsTrue (sql.CanSort, "A4");
243 ds.DataSourceMode = SqlDataSourceMode.DataSet;
244 Assert.IsTrue (sql.CanSort, "A5");
246 sql.SortParameterName = "";
248 ds.DataSourceMode = SqlDataSourceMode.DataReader;
249 Assert.IsFalse (sql.CanSort, "A6");
251 ds.DataSourceMode = SqlDataSourceMode.DataSet;
252 Assert.IsTrue (sql.CanSort, "A7");
256 public void OldValuesParameterFormatString ()
258 SqlDataSource ds = new SqlDataSource ();
260 Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A1");
262 ds.OldValuesParameterFormatString = "hi {0}";
264 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
266 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A2");
268 ds.OldValuesParameterFormatString = "hi {0}";
270 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A3");
272 ds.OldValuesParameterFormatString = "{0}";
273 sql.OldValuesParameterFormatString = "hi {0}";
275 Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A4");
279 public void CancelSelectOnNullParameter ()
281 SqlDataSource ds = new SqlDataSource ();
283 ds.CancelSelectOnNullParameter = false;
285 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
287 Assert.IsTrue (sql.CancelSelectOnNullParameter, "A1");
289 ds.CancelSelectOnNullParameter = true;
290 sql.CancelSelectOnNullParameter = false;
292 Assert.IsTrue (ds.CancelSelectOnNullParameter, "A2");
294 sql.CancelSelectOnNullParameter = false;
295 ds.CancelSelectOnNullParameter = true;
296 Assert.IsFalse (sql.CancelSelectOnNullParameter, "A3");