[System] UriKind.RelativeOrAbsolute workaround.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / CheckBoxFieldTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.CheckBoxFieldTest.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@mainsoft.com)
6 //
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29
30
31
32 using System;
33 using System.Collections.Generic;
34 using System.Text;
35 using System.Web;
36 using System.Web.UI;
37 using System.Web.UI.WebControls;
38 using System.IO;
39 using System.Drawing;
40 using System.Collections;
41 using System.Collections.Specialized;
42 using NUnit.Framework;
43 using System.Data;
44
45 using MonoTests.SystemWeb.Framework;
46 using MonoTests.stand_alone.WebHarness;
47
48 namespace MonoTests.System.Web.UI.WebControls
49 {
50         class PokerCheckBoxField : CheckBoxField
51         {
52                 // View state Stuff
53                 public PokerCheckBoxField ()
54                         : base ()
55                 {
56                         TrackViewState ();
57                 }
58
59                 public object SaveState ()
60                 {
61                         return SaveViewState ();
62                 }
63
64                 public void LoadState (object o)
65                 {
66                         LoadViewState (o);
67                 }
68
69                 public StateBag StateBag
70                 {
71                         get { return base.ViewState; }
72                 }
73
74                 public bool GetSupportsHtmlEncode
75                 {
76                         get
77                         {
78                                 return base.SupportsHtmlEncode;
79                         }
80                 }
81
82                 public void DoCopyProperties (DataControlField newField)
83                 {
84                         base.CopyProperties (newField);
85                 }
86
87                 public DataControlField DoCreateField ()
88                 {
89                         return base.CreateField ();
90                 }
91
92                 public object DoGetDesignTimeValue ()
93                 {
94                         return base.GetDesignTimeValue ();
95                 }
96
97                 public void DoInitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
98                 {
99                         this.InitializeDataCell (cell, rowState);
100                 }
101
102                 protected override void OnDataBindField (object sender, EventArgs e)
103                 {
104                         base.OnDataBindField (sender, e);
105                         CheckBoxFieldTest.databound += 1;
106                 }
107         }
108         
109         [TestFixture]
110         public class CheckBoxFieldTest
111         {
112                 public const string FIELDNAME  = "checkbox";
113                 public const string WRONGFIELD = "str";
114                 public static int databound;
115
116                 [TestFixtureSetUp]
117                 public void SetUp ()
118                 {
119                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_0.aspx", "CheckBoxField_Bug595568_0.aspx");
120                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_1.aspx", "CheckBoxField_Bug595568_1.aspx");
121                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_2.aspx", "CheckBoxField_Bug595568_2.aspx");
122                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_5.aspx", "CheckBoxField_Bug595568_5.aspx");
123                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_6.aspx", "CheckBoxField_Bug595568_6.aspx");
124                         WebTest.CopyResource (GetType (), "CheckBoxField_Bug595568_7.aspx", "CheckBoxField_Bug595568_7.aspx");
125                 }
126
127                 [Test (Description="Bug 595568 #0")]
128                 public void CheckBoxField_Bug595568_0 ()
129                 {
130 #if NET_4_0
131                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl00_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" checked=\"checked\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl00_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl00_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /></span></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
132 #else
133                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl02_ctl00\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" checked=\"checked\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl03_ctl00\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><span title=\"Dummy\"><input id=\"gridView_ctl04_ctl00\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /></span></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
134 #endif
135                         WebTest t = new WebTest ("CheckBoxField_Bug595568_0.aspx");
136                         string pageHtml = t.Run ();
137                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
138
139                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
140                 }
141
142                 [Test (Description="Bug 595568 #1")]
143                 public void CheckBoxField_Bug595568_1 ()
144                 {
145 #if NET_4_0
146                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl02$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl01_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" checked=\"checked\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl03$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl01_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl04$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl01_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></span></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
147 #else
148                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl02$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl02_ctl01\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" checked=\"checked\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl03$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl03_ctl01\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></span></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl04$ctl00\">\r\n\r\n\t\t\t</select><span title=\"Dummy\"><input id=\"gridView_ctl04_ctl01\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></span></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
149 #endif
150                         WebTest t = new WebTest ("CheckBoxField_Bug595568_1.aspx");
151                         string pageHtml = t.Run ();
152                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
153
154                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
155                 }
156
157                 [Test (Description="Bug 595568 #2")]
158                 public void CheckBoxField_Bug595568_2 ()
159                 {
160 #if NET_4_0
161                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl01_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" checked=\"checked\" /></span><input id=\"gridView_ctl02_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl02\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl01_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></span><input id=\"gridView_ctl02_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl02\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl01_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></span><input id=\"gridView_ctl02_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl02\" /></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
162 #else
163                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl02_ctl00\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl02_ctl01\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" checked=\"checked\" /></span><input id=\"gridView_ctl02_ctl02\" type=\"checkbox\" name=\"gridView$ctl02$ctl02\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl03_ctl00\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl03_ctl01\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></span><input id=\"gridView_ctl03_ctl02\" type=\"checkbox\" name=\"gridView$ctl03$ctl02\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl04_ctl00\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /><span title=\"Dummy\"><input id=\"gridView_ctl04_ctl01\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></span><input id=\"gridView_ctl04_ctl02\" type=\"checkbox\" name=\"gridView$ctl04$ctl02\" /></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
164 #endif
165                         
166                         WebTest t = new WebTest ("CheckBoxField_Bug595568_2.aspx");
167                         string pageHtml = t.Run ();
168                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
169
170                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
171                 }
172
173                 [Test (Description="Bug 595568 #5")]
174                 public void CheckBoxField_Bug595568_5 ()
175                 {
176                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl02$ctl00\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl03$ctl00\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl04$ctl00\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
177
178                         WebTest t = new WebTest ("CheckBoxField_Bug595568_5.aspx");
179                         string pageHtml = t.Run ();
180                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
181
182                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
183                 }
184                 
185                 [Test (Description="Bug 595568 #6")]
186                 public void CheckBoxField_Bug595568_6 ()
187                 {       
188 #if NET_4_0
189                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl02$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl01_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl03$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl01_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl04$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl01_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
190 #else
191                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl02$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl02_ctl01\" type=\"checkbox\" name=\"gridView$ctl02$ctl01\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl03$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl03_ctl01\" type=\"checkbox\" name=\"gridView$ctl03$ctl01\" /></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><select size=\"4\" name=\"gridView$ctl04$ctl00\">\r\n\r\n\t\t\t</select><input id=\"gridView_ctl04_ctl01\" type=\"checkbox\" name=\"gridView$ctl04$ctl01\" /></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
192 #endif
193
194                         WebTest t = new WebTest ("CheckBoxField_Bug595568_6.aspx");
195                         string pageHtml = t.Run ();
196                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
197
198                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
199                 }
200
201                 [Test (Description="Bug 595568 #7")]
202                 public void CheckBoxField_Bug595568_7 ()
203                 {
204 #if NET_4_0
205                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_0\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" /><select size=\"4\" name=\"gridView$ctl02$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_1\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /><select size=\"4\" name=\"gridView$ctl03$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl00_2\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /><select size=\"4\" name=\"gridView$ctl04$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
206 #else
207                         string originalHtml = "<div>\r\n\t<table cellspacing=\"0\" rules=\"all\" border=\"1\" id=\"gridView\" style=\"border-collapse:collapse;\">\r\n\t\t<tr>\r\n\t\t\t<th scope=\"col\">&nbsp;</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl02_ctl00\" type=\"checkbox\" name=\"gridView$ctl02$ctl00\" /><select size=\"4\" name=\"gridView$ctl02$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl03_ctl00\" type=\"checkbox\" name=\"gridView$ctl03$ctl00\" /><select size=\"4\" name=\"gridView$ctl03$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr><tr>\r\n\t\t\t<td><input id=\"gridView_ctl04_ctl00\" type=\"checkbox\" name=\"gridView$ctl04$ctl00\" /><select size=\"4\" name=\"gridView$ctl04$ctl01\">\r\n\r\n\t\t\t</select></td>\r\n\t\t</tr>\r\n\t</table>\r\n</div>";
208 #endif
209                         WebTest t = new WebTest ("CheckBoxField_Bug595568_7.aspx");             
210                         string pageHtml = t.Run ();
211                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
212
213                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
214                 }
215                 
216                 [Test]
217                 public void CheckBoxField_DefaultProperty ()
218                 {
219                         PokerCheckBoxField field = new PokerCheckBoxField ();
220                         Assert.AreEqual ("", field.DataField, "DataField");
221                         Assert.AreEqual ("", field.Text, "Text");
222                         Assert.AreEqual (false, field.GetSupportsHtmlEncode, "SupportsHtmlEncode"); 
223                 }
224
225                 [Test]
226                 public void CheckBoxField_AssignProperty ()
227                 {
228                         PokerCheckBoxField field = new PokerCheckBoxField ();
229                         field.DataField = "test";
230                         Assert.AreEqual ("test", field.DataField, "DataField");
231                         field.Text = "test";
232                         Assert.AreEqual ("test", field.Text, "Text");
233                 }
234
235                 public void CheckBoxField_ExtractValuesFromCell ()
236                 {
237                         PokerCheckBoxField field = new PokerCheckBoxField ();
238                         OrderedDictionary dictionary = new OrderedDictionary ();
239                         DataControlFieldCell cell = new DataControlFieldCell (null);
240                         cell.Controls.Add (new CheckBox ());
241                         field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
242                         Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount#1");
243                         Assert.AreEqual ("False", dictionary[0].ToString (), "ExtractValuesFromCellValueFalse");
244                         CheckBox cb = new CheckBox ();
245                         cb.Checked = true;
246                         cell.Controls.Clear ();
247                         cell.Controls.Add (cb);
248                         field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
249                         Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount#2");
250                         Assert.AreEqual ("True", dictionary[0].ToString (), "ExtractValuesFromCellValueTrue");
251                 }
252
253                 [Test]
254                 public void CheckBoxField_ValidateSupportsCallback ()
255                 {
256                         PokerCheckBoxField field = new PokerCheckBoxField ();
257                         field.ValidateSupportsCallback ();
258                 }
259
260                 [Test]
261                 public void CheckBoxField_CopyProperties()
262                 {
263                         PokerCheckBoxField field = new PokerCheckBoxField ();
264                         CheckBoxField copy = new CheckBoxField();
265                         field.DataField = "test";
266                         field.Text = "test";
267                         field.DoCopyProperties (copy);
268                         Assert.AreEqual ("test", copy.Text, "Text");
269                         Assert.AreEqual ("test", copy.DataField, "DataField");
270                 }
271
272                 [Test]
273                 public void CheckBoxField_CreateField ()
274                 {
275                         PokerCheckBoxField field = new PokerCheckBoxField ();
276                         CheckBoxField blank = (CheckBoxField)field.DoCreateField ();
277                         Assert.IsNotNull (blank, "CreateField");
278                 }
279
280                 [Test]
281                 public void CheckBoxField_GetDesignTimeValue ()
282                 {
283                         PokerCheckBoxField field = new PokerCheckBoxField ();
284                         bool result = (bool)field.DoGetDesignTimeValue ();
285                         Assert.AreEqual (true, result, "GetDesignTimeValue");
286                 }
287
288                 [Test]
289                 public void CheckBoxField_InitializeDataCell ()
290                 {
291                         PokerCheckBoxField field = new PokerCheckBoxField ();
292                         field.HeaderText = "headertest";
293                         DataControlFieldCell cell = new DataControlFieldCell (null);
294                         DataControlRowState state = DataControlRowState.Edit;
295                         Assert.AreEqual (0, cell.Controls.Count, "InitializeDataCellControlsBeforeInit");
296                         field.DoInitializeDataCell (cell, state);
297                         Assert.AreEqual (1, cell.Controls.Count, "InitializeDataCellControlsAfterInit");
298                         Assert.AreEqual ("headertest", ((CheckBox)cell.Controls[0]).ToolTip, "InitializeDataCellControlsData");
299
300                         cell.Controls.Clear ();
301                         field.DataField = "fake";
302                         field.Text = "celltext";
303                         state = DataControlRowState.Normal;
304                         field.DoInitializeDataCell (cell, state);
305                         Assert.AreEqual (1, cell.Controls.Count, "InitializeDataCellControlsAfterInit");
306                         Assert.AreEqual ("celltext", ((CheckBox) cell.Controls[0]).Text, "InitializeDataCellControlsData");
307                 }
308
309                 [Test]
310                 public void CheckBoxField_OnDataBindField ()
311                 {
312                         Page page = new Page ();
313                         GridView grid = new GridView ();
314                         page.Controls.Add (grid);
315                         grid.DataSource = this.CreateDataSource ();
316                         grid.AutoGenerateColumns = false;
317                         PokerCheckBoxField field = new PokerCheckBoxField ();
318                         field.HeaderText = "field_header";
319                         field.FooterText = "field_footer";
320                         field.DataField = FIELDNAME;
321                         grid.Columns.Add (field);
322                         grid.DataBind ();
323                         Assert.AreEqual (2, databound, "DataBindField");
324                         Assert.AreEqual (4, ((Control) grid.Controls[0]).Controls.Count, "DataBindFieldRowCountr");
325                 }
326
327                 [Test]
328                 [ExpectedException (typeof (HttpException))]
329                 public void CheckBoxField_OnDataBindFieldException ()
330                 {
331                         Page page = new Page ();
332                         GridView grid = new GridView ();
333                         page.Controls.Add (grid);
334                         grid.DataSource = this.CreateDataSource ();
335                         grid.AutoGenerateColumns = false;
336                         PokerCheckBoxField field = new PokerCheckBoxField ();
337                         field.HeaderText = "field_header";
338                         field.FooterText = "field_footer";
339                         field.DataField = WRONGFIELD;
340                         grid.Columns.Add (field);
341                         grid.DataBind ();
342                 }
343
344                 [Test]
345                 [ExpectedException(typeof(NotSupportedException))]
346                 public void CheckBoxField_GetApplyFormatInEditModeExeption ()
347                 {
348                         PokerCheckBoxField field = new PokerCheckBoxField ();
349                         bool stab = field.ApplyFormatInEditMode;
350                 }
351
352                 [Test]
353                 [ExpectedException (typeof (NotSupportedException))]
354                 public void CheckBoxField_SetApplyFormatInEditModeExeption ()
355                 {
356                         PokerCheckBoxField field = new PokerCheckBoxField ();
357                         field.ApplyFormatInEditMode = true;
358                 }
359
360                 [Test]
361                 [ExpectedException (typeof (NotSupportedException))]
362                 public void CheckBoxField_GetConvertEmptyStringToNull ()
363                 {
364                         PokerCheckBoxField field = new PokerCheckBoxField ();
365                         bool stab = field.ConvertEmptyStringToNull;
366                 }
367
368                 [Test]
369                 [ExpectedException (typeof (NotSupportedException))]
370                 public void CheckBoxField_SetConvertEmptyStringToNull ()
371                 {
372                         PokerCheckBoxField field = new PokerCheckBoxField ();
373                         field.ConvertEmptyStringToNull = true;
374                 }
375
376                 [Test]
377                 [ExpectedException (typeof (NotSupportedException))]
378                 public void CheckBoxField_SetDataFormatString ()
379                 {
380                         PokerCheckBoxField field = new PokerCheckBoxField ();
381                         field.DataFormatString = "";
382                 }
383
384                 [Test]
385                 [ExpectedException (typeof (NotSupportedException))]
386                 public void CheckBoxField_GetDataFormatString ()
387                 {
388                         PokerCheckBoxField field = new PokerCheckBoxField ();
389                         string res = field.DataFormatString;
390                 }
391
392                 [Test]
393                 [ExpectedException (typeof (NotSupportedException))]
394                 public void CheckBoxField_SetHtmlEncode ()
395                 {
396                         PokerCheckBoxField field = new PokerCheckBoxField ();
397                         field.HtmlEncode = true;
398                 }
399
400                 [Test]
401                 [ExpectedException (typeof (NotSupportedException))]
402                 public void CheckBoxField_GetHtmlEncode ()
403                 {
404                         PokerCheckBoxField field = new PokerCheckBoxField ();
405                         bool res = field.HtmlEncode;
406                 }
407
408                 [Test]
409                 [ExpectedException (typeof (NotSupportedException))]
410                 public void CheckBoxField_SetNullDisplayText ()
411                 {
412                         PokerCheckBoxField field = new PokerCheckBoxField ();
413                         field.NullDisplayText = "";
414                 }
415
416                 [Test]
417                 [ExpectedException (typeof (NotSupportedException))]
418                 public void CheckBoxField_GetNullDisplayText ()
419                 {
420                         PokerCheckBoxField field = new PokerCheckBoxField ();
421                         string res = field.NullDisplayText;
422                 }
423
424                 public  DataTable CreateDataSource ()
425                 {
426                         DataTable aTable = new DataTable ("A");
427                         DataColumn dtCol;
428                         DataRow dtRow;
429                         // Create ID column and add to the DataTable.
430                         dtCol = new DataColumn ();
431                         dtCol.DataType = Type.GetType ("System.Boolean");
432                         dtCol.ColumnName = FIELDNAME;
433                         dtCol.Caption = FIELDNAME;
434                         dtCol.ReadOnly = true;
435
436                         // Add the column to the DataColumnCollection.
437                         aTable.Columns.Add (dtCol);
438
439
440                         dtCol = new DataColumn ();
441                         dtCol.DataType = Type.GetType ("System.String");
442                         dtCol.ColumnName = WRONGFIELD;
443                         dtCol.Caption = WRONGFIELD;
444                         dtCol.ReadOnly = true;
445                         
446
447                         // Add the column to the DataColumnCollection.
448                         aTable.Columns.Add (dtCol);
449
450                         // Create 2 rows to the table
451                         dtRow = aTable.NewRow ();
452                         dtRow[FIELDNAME] = true;
453                         dtRow[WRONGFIELD] = "1";
454                         aTable.Rows.Add (dtRow);
455
456                         dtRow = aTable.NewRow ();
457                         dtRow[FIELDNAME] = false;
458                         dtRow[WRONGFIELD] = "1";
459                         aTable.Rows.Add (dtRow);
460                         return aTable;
461                 }
462         }
463 }