2 // Tests for System.Web.UI.WebControls.AutoGeneratedField.cs
5 // Yoni Klein (yonik@mainsoft.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections.Generic;
37 using System.Web.UI.WebControls;
40 using System.Collections;
41 using System.Collections.Specialized;
42 using NUnit.Framework;
47 namespace MonoTests.System.Web.UI.WebControls
51 public class AutoGeneratedFieldTest
54 public void AutoGeneratedField_DefaultProperty ()
56 AutoGeneratedField field = new AutoGeneratedField ("test");
57 Assert.AreEqual (true, field.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
58 Assert.AreEqual (string.Empty, field.DataFormatString, "DataFormatString");
59 Assert.AreEqual (true, field.InsertVisible, "InsertVisible");
63 public void AutoGeneratedField_DefaultPropertyNotWorking ()
65 AutoGeneratedField field = new AutoGeneratedField ("test");
66 Assert.AreEqual (typeof (String), field.DataType, "DataType");
70 public void AutoGeneratedField_AssignProperty ()
72 AutoGeneratedField field = new AutoGeneratedField ("test");
73 Assert.AreEqual ("test", field.DataField, "DataField");
74 field.DataType = typeof (bool);
75 Assert.AreEqual (typeof (bool), field.DataType, "DataType");
79 public void AutoGeneratedField_ExtractValuesFromCell()
81 AutoGeneratedField field = new AutoGeneratedField ("field");
82 OrderedDictionary dictionary = new OrderedDictionary ();
83 DataControlFieldCell cell = new DataControlFieldCell (null);
85 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
86 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
87 Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue");
91 public void AutoGeneratedField_ExtractValuesFromCellCheckbox ()
93 // Aditional implementation for bollean data type
95 AutoGeneratedField field = new AutoGeneratedField ("field");
96 field.DataType = typeof (bool);
97 OrderedDictionary dictionary = new OrderedDictionary ();
98 DataControlFieldCell cell = new DataControlFieldCell(null);
99 cell.Controls.Add (new CheckBox ());
100 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
101 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
102 Assert.AreEqual ("False", dictionary[0].ToString (), "ExtractValuesFromCellValue");
103 CheckBox cb = new CheckBox ();
105 cell.Controls.Clear ();
106 cell.Controls.Add (cb);
107 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
108 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
109 Assert.AreEqual ("True", dictionary[0].ToString (), "ExtractValuesFromCellValue");
113 public void AutoGeneratedField_ValidateSupportsCallback ()
115 //This method has been implemented as an empty method
119 public void AutoGeneratedField_BoolArray () {
120 GridView GridView1 = new GridView ();
121 GridView1.DataSource = new bool [] { true };
122 GridView1.DataBind ();
126 [ExpectedException(typeof(NotSupportedException))]
127 public void AutoGeneratedField_ConvertEmptyStringToNullExeption ()
129 AutoGeneratedField field = new AutoGeneratedField ("test");
130 field.ConvertEmptyStringToNull = false;
135 [ExpectedException (typeof (NotSupportedException))]
136 public void AutoGeneratedField_DataFormatStringExeption ()
138 AutoGeneratedField field = new AutoGeneratedField ("test");
139 field.DataFormatString = "test";
143 [ExpectedException (typeof (NotSupportedException))]
144 public void AutoGeneratedField_InsertVisibleExeption ()
146 AutoGeneratedField field = new AutoGeneratedField ("test");
147 field.InsertVisible = false;