Increase tests' correctness as now they better follow the .NET behavior, and
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / SqlDataSourceTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.SqlDataSource
3 //
4 // Author:
5 //      Chris Toshok (toshok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if NET_2_0
32
33 using NUnit.Framework;
34 using System;
35 using System.Configuration;
36 using System.Data.Common;
37 using System.IO;
38 using System.Globalization;
39 using System.Web;
40 using System.Web.UI;
41 using System.Web.UI.WebControls;
42
43 namespace MonoTests.System.Web.UI.WebControls
44 {
45         class SqlPoker : SqlDataSource {
46                 public SqlPoker ()
47                 {
48                         TrackViewState ();
49                 }
50
51                 public object SaveToViewState ()
52                 {
53                         return SaveViewState ();
54                 }
55
56                 public void LoadFromViewState (object savedState)
57                 {
58                         LoadViewState (savedState);
59                 }
60         }
61
62         [TestFixture]
63         public class SqlDataSourceTest {
64                 [Test]
65                 public void Defaults ()
66                 {
67                         SqlPoker sql = new SqlPoker ();
68
69                         Assert.AreEqual ("", sql.CacheKeyDependency, "A1");
70                         Assert.IsTrue (sql.CancelSelectOnNullParameter, "A2");
71                         Assert.AreEqual(ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A3");
72                         Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
73             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "A5");
74             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "A6");
75             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A7");
76                         Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A8");
77                         Assert.AreEqual ("", sql.SqlCacheDependency, "A9");
78                         Assert.AreEqual ("", sql.SortParameterName, "A10");
79                         Assert.AreEqual (0, sql.CacheDuration, "A11");
80                         Assert.AreEqual (DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "A12");
81                         Assert.IsFalse (sql.EnableCaching, "A13");
82                         Assert.AreEqual ("", sql.ProviderName, "A14");
83                         Assert.AreEqual ("", sql.ConnectionString, "A15");
84                         Assert.AreEqual (SqlDataSourceMode.DataSet, sql.DataSourceMode, "A16");
85                         Assert.AreEqual ("", sql.DeleteCommand, "A17");
86                         Assert.IsNotNull (sql.DeleteParameters, "A18");
87                         Assert.AreEqual (0, sql.DeleteParameters.Count, "A18.1");
88                         Assert.IsNotNull (sql.FilterParameters, "A19");
89                         Assert.AreEqual (0, sql.FilterParameters.Count, "A19.1");
90                         Assert.AreEqual ("", sql.InsertCommand, "A20");
91                         Assert.IsNotNull (sql.InsertParameters, "A21");
92                         Assert.AreEqual (0, sql.InsertParameters.Count, "A21.1");
93                         Assert.AreEqual ("", sql.SelectCommand, "A22");
94                         Assert.IsNotNull (sql.SelectParameters, "A23");
95                         Assert.AreEqual (0, sql.SelectParameters.Count, "A23.1");
96                         Assert.AreEqual ("", sql.UpdateCommand, "A24");
97                         Assert.IsNotNull (sql.UpdateParameters, "A25");
98                         Assert.AreEqual (0, sql.UpdateParameters.Count, "A25.1");
99                         Assert.AreEqual ("", sql.FilterExpression, "A26");
100                 }
101
102         // WARNING!!!!!! This information will be saved into viewstate only in mono implementation .
103
104                 [Test]
105         [Category ("NotWorking")]
106         public void ViewState ()
107                 {
108                         SqlPoker sql = new SqlPoker ();
109
110                         sql.CacheKeyDependency = "hi";
111                         sql.CancelSelectOnNullParameter = false;
112                         sql.ConflictDetection = ConflictOptions.CompareAllValues;
113                         sql.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
114             sql.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
115             sql.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
116             sql.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
117                         sql.OldValuesParameterFormatString = "{1}";
118                         sql.SqlCacheDependency = "hi";
119                         sql.SortParameterName = "hi";
120                         sql.CacheDuration = 1;
121                         sql.CacheExpirationPolicy = DataSourceCacheExpiry.Sliding;
122                         sql.EnableCaching = true;
123                         sql.DataSourceMode = SqlDataSourceMode.DataReader;
124                         sql.DeleteCommand = "DELETE foo";
125                         sql.InsertCommand = "INSERT foo";
126                         sql.SelectCommand = "SELECT foo";
127                         sql.UpdateCommand = "UPDATE foo";
128                         sql.FilterExpression = "hi";
129                         
130                         Assert.AreEqual ("hi", sql.CacheKeyDependency, "A1");
131                         Assert.IsFalse (sql.CancelSelectOnNullParameter, "A2");
132                         Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "A3");
133                         Assert.AreEqual(SqlDataSourceCommandType.StoredProcedure, sql.DeleteCommandType, "A4");
134             Assert.AreEqual(SqlDataSourceCommandType.StoredProcedure, sql.InsertCommandType, "A5");
135             Assert.AreEqual(SqlDataSourceCommandType.StoredProcedure, sql.SelectCommandType, "A6");
136             Assert.AreEqual(SqlDataSourceCommandType.StoredProcedure, sql.UpdateCommandType, "A7");
137                         Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "A8");
138                         Assert.AreEqual ("hi", sql.SqlCacheDependency, "A9");
139                         Assert.AreEqual ("hi", sql.SortParameterName, "A10");
140                         Assert.AreEqual (1, sql.CacheDuration, "A11");
141                         Assert.AreEqual (DataSourceCacheExpiry.Sliding, sql.CacheExpirationPolicy, "A12");
142                         Assert.IsTrue (sql.EnableCaching, "A13");
143                         Assert.AreEqual (SqlDataSourceMode.DataReader, sql.DataSourceMode, "A16");
144                         Assert.AreEqual ("DELETE foo", sql.DeleteCommand, "A17");
145                         Assert.AreEqual ("INSERT foo", sql.InsertCommand, "A20");
146                         Assert.AreEqual ("SELECT foo", sql.SelectCommand, "A22");
147                         Assert.AreEqual ("UPDATE foo", sql.UpdateCommand, "A24");
148                         Assert.AreEqual ("hi", sql.FilterExpression, "A26");
149
150                         object state = sql.SaveToViewState();
151
152                         sql = new SqlPoker ();
153                         sql.LoadFromViewState (state);
154
155             Assert.AreEqual("", sql.CacheKeyDependency, "B1");
156             Assert.IsTrue(sql.CancelSelectOnNullParameter, "B2");
157             Assert.AreEqual(ConflictOptions.OverwriteChanges, sql.ConflictDetection, "B3");
158             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B4");
159             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "B5");
160             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "B6");
161             Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B7");
162             Assert.AreEqual("{0}", sql.OldValuesParameterFormatString, "B8");
163             Assert.AreEqual("", sql.SqlCacheDependency, "B9");
164             Assert.AreEqual("", sql.SortParameterName, "B10");
165             Assert.AreEqual(0, sql.CacheDuration, "B11");
166             Assert.AreEqual(DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "B12");
167             Assert.IsFalse(sql.EnableCaching, "B13");
168             Assert.AreEqual("", sql.ProviderName, "B14");
169             Assert.AreEqual("", sql.ConnectionString, "B15");
170             Assert.AreEqual(SqlDataSourceMode.DataSet, sql.DataSourceMode, "B16");
171             Assert.AreEqual("", sql.DeleteCommand, "B17");
172             Assert.IsNotNull(sql.DeleteParameters, "B18");
173             Assert.AreEqual(0, sql.DeleteParameters.Count, "B18.1");
174             Assert.IsNotNull(sql.FilterParameters, "B19");
175             Assert.AreEqual(0, sql.FilterParameters.Count, "B19.1");
176             Assert.AreEqual("", sql.InsertCommand, "B20");
177             Assert.IsNotNull(sql.InsertParameters, "B21");
178             Assert.AreEqual(0, sql.InsertParameters.Count, "B21.1");
179             Assert.AreEqual("", sql.SelectCommand, "B22");
180             Assert.IsNotNull(sql.SelectParameters, "B23");
181             Assert.AreEqual(0, sql.SelectParameters.Count, "B23.1");
182             Assert.AreEqual("", sql.UpdateCommand, "B24");
183             Assert.IsNotNull(sql.UpdateParameters, "B25");
184             Assert.AreEqual(0, sql.UpdateParameters.Count, "B25.1");
185             Assert.AreEqual("", sql.FilterExpression, "B26");
186         }
187     }
188 }
189
190 #endif