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.StoredProcedure, 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.StoredProcedure, 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.StoredProcedure, 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.StoredProcedure, sql.UpdateCommandType, "A27");
98 Assert.IsNotNull (sql.UpdateParameters, "A28");
99 Assert.AreEqual (0, sql.UpdateParameters.Count, "A29");
103 public void ViewState ()
105 SqlDataSource ds = new SqlDataSource ();
106 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
108 /* XXX test parameters */
110 sql.CancelSelectOnNullParameter = false;
111 sql.ConflictDetection = ConflictOptions.CompareAllValues;
112 sql.DeleteCommandType = SqlDataSourceCommandType.Text;
113 sql.DeleteCommand = "delete command";
114 sql.FilterExpression = "filter expression";
115 sql.InsertCommand = "insert command";
116 sql.InsertCommandType = SqlDataSourceCommandType.Text;
117 sql.OldValuesParameterFormatString = "{1}";
118 sql.SelectCommand = "select command";
119 sql.SelectCommandType = SqlDataSourceCommandType.Text;
120 sql.SortParameterName = "sort parameter";
121 sql.UpdateCommand = "update command";
122 sql.UpdateCommandType = SqlDataSourceCommandType.Text;
124 Assert.IsFalse (sql.CancelSelectOnNullParameter, "A1");
125 Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "A2");
126 Assert.AreEqual ("delete command", sql.DeleteCommand, "A3");
127 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
128 Assert.AreEqual ("filter expression", sql.FilterExpression, "A5");
129 Assert.AreEqual ("insert command", sql.InsertCommand, "A6");
130 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A7");
131 Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "A8");
132 Assert.AreEqual ("select command", sql.SelectCommand, "A9");
133 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A10");
134 Assert.AreEqual ("sort parameter", sql.SortParameterName, "A11");
135 Assert.AreEqual ("update command", sql.UpdateCommand, "A12");
136 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A13");
138 object state = sql.SaveToViewState();
140 sql = new SqlViewPoker (ds, "DefaultView", null);
141 sql.LoadFromViewState (state);
143 Assert.IsFalse (sql.CancelSelectOnNullParameter, "B1");
144 Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "B2");
145 Assert.AreEqual ("delete command", sql.DeleteCommand, "B3");
146 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B4");
147 Assert.AreEqual ("filter expression", sql.FilterExpression, "B5");
148 Assert.AreEqual ("insert command", sql.InsertCommand, "B6");
149 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "B7");
150 Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "B8");
151 Assert.AreEqual ("select command", sql.SelectCommand, "B9");
152 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "B10");
153 Assert.AreEqual ("sort parameter", sql.SortParameterName, "B11");
154 Assert.AreEqual ("update command", sql.UpdateCommand, "B12");
155 Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B13");
159 public void CanDelete ()
161 SqlDataSource ds = new SqlDataSource ();
162 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
164 sql.DeleteCommand = "DELETE from foo";
165 Assert.IsTrue (sql.CanDelete, "A1");
167 sql.DeleteCommand = "";
168 Assert.IsFalse (sql.CanDelete, "A2");
170 sql.DeleteCommand = null;
171 Assert.IsFalse (sql.CanDelete, "A3");
175 public void CanInsert ()
177 SqlDataSource ds = new SqlDataSource ();
178 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
180 sql.InsertCommand = "INSERT into foo";
181 Assert.IsTrue (sql.CanInsert, "A1");
183 sql.InsertCommand = "";
184 Assert.IsFalse (sql.CanInsert, "A2");
186 sql.InsertCommand = null;
187 Assert.IsFalse (sql.CanInsert, "A3");
191 public void CanUpdate ()
193 SqlDataSource ds = new SqlDataSource ();
194 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
196 sql.UpdateCommand = "UPDATE foo";
197 Assert.IsTrue (sql.CanUpdate, "A1");
199 sql.UpdateCommand = "";
200 Assert.IsFalse (sql.CanUpdate, "A2");
202 sql.UpdateCommand = null;
203 Assert.IsFalse (sql.CanUpdate, "A3");
207 public void CanSort ()
209 SqlDataSource ds = new SqlDataSource ();
210 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
212 sql.SortParameterName = "foo";
213 Assert.IsTrue (sql.CanSort, "A1");
215 sql.SortParameterName = null;
216 Assert.IsTrue (sql.CanSort, "A2");
218 sql.SortParameterName = "";
219 Assert.IsTrue (sql.CanSort, "A3");
221 sql.SortParameterName = "foo";
223 ds.DataSourceMode = SqlDataSourceMode.DataReader;
224 Assert.IsTrue (sql.CanSort, "A4");
226 ds.DataSourceMode = SqlDataSourceMode.DataSet;
227 Assert.IsTrue (sql.CanSort, "A5");
229 sql.SortParameterName = "";
231 ds.DataSourceMode = SqlDataSourceMode.DataReader;
232 Assert.IsFalse (sql.CanSort, "A6");
234 ds.DataSourceMode = SqlDataSourceMode.DataSet;
235 Assert.IsTrue (sql.CanSort, "A7");
239 public void OldValuesParameterFormatString ()
241 SqlDataSource ds = new SqlDataSource ();
243 Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A1");
245 ds.OldValuesParameterFormatString = "hi {0}";
247 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
249 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A2");
251 ds.OldValuesParameterFormatString = "hi {0}";
253 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A3");
255 ds.OldValuesParameterFormatString = "{0}";
256 sql.OldValuesParameterFormatString = "hi {0}";
258 Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A4");
262 public void CancelSelectOnNullParameter ()
264 SqlDataSource ds = new SqlDataSource ();
266 ds.CancelSelectOnNullParameter = false;
268 SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
270 Assert.IsTrue (sql.CancelSelectOnNullParameter, "A1");
272 ds.CancelSelectOnNullParameter = true;
273 sql.CancelSelectOnNullParameter = false;
275 Assert.IsTrue (ds.CancelSelectOnNullParameter, "A2");
277 sql.CancelSelectOnNullParameter = false;
278 ds.CancelSelectOnNullParameter = true;
279 Assert.IsFalse (sql.CancelSelectOnNullParameter, "A3");