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.
34 using System.Collections.Generic;
38 using System.Web.UI.WebControls;
41 using System.Collections;
42 using System.Collections.Specialized;
43 using NUnit.Framework;
48 namespace MonoTests.System.Web.UI.WebControls
52 public class AutoGeneratedFieldTest
55 public void AutoGeneratedField_DefaultProperty ()
57 AutoGeneratedField field = new AutoGeneratedField ("test");
58 Assert.AreEqual (true, field.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
59 Assert.AreEqual (string.Empty, field.DataFormatString, "DataFormatString");
60 Assert.AreEqual (true, field.InsertVisible, "InsertVisible");
64 public void AutoGeneratedField_DefaultPropertyNotWorking ()
66 AutoGeneratedField field = new AutoGeneratedField ("test");
67 Assert.AreEqual (typeof (String), field.DataType, "DataType");
71 public void AutoGeneratedField_AssignProperty ()
73 AutoGeneratedField field = new AutoGeneratedField ("test");
74 Assert.AreEqual ("test", field.DataField, "DataField");
75 field.DataType = typeof (bool);
76 Assert.AreEqual (typeof (bool), field.DataType, "DataType");
80 public void AutoGeneratedField_ExtractValuesFromCell()
82 AutoGeneratedField field = new AutoGeneratedField ("field");
83 OrderedDictionary dictionary = new OrderedDictionary ();
84 DataControlFieldCell cell = new DataControlFieldCell (null);
86 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
87 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
88 Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue");
92 public void AutoGeneratedField_ExtractValuesFromCellCheckbox ()
94 // Aditional implementation for bollean data type
96 AutoGeneratedField field = new AutoGeneratedField ("field");
97 field.DataType = typeof (bool);
98 OrderedDictionary dictionary = new OrderedDictionary ();
99 DataControlFieldCell cell = new DataControlFieldCell(null);
100 cell.Controls.Add (new CheckBox ());
101 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
102 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
103 Assert.AreEqual ("False", dictionary[0].ToString (), "ExtractValuesFromCellValue");
104 CheckBox cb = new CheckBox ();
106 cell.Controls.Clear ();
107 cell.Controls.Add (cb);
108 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
109 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
110 Assert.AreEqual ("True", dictionary[0].ToString (), "ExtractValuesFromCellValue");
114 public void AutoGeneratedField_ValidateSupportsCallback ()
116 //This method has been implemented as an empty method
121 [ExpectedException(typeof(NotSupportedException))]
122 public void AutoGeneratedField_ConvertEmptyStringToNullExeption ()
124 AutoGeneratedField field = new AutoGeneratedField ("test");
125 field.ConvertEmptyStringToNull = false;
130 [ExpectedException (typeof (NotSupportedException))]
131 public void AutoGeneratedField_DataFormatStringExeption ()
133 AutoGeneratedField field = new AutoGeneratedField ("test");
134 field.DataFormatString = "test";
138 [ExpectedException (typeof (NotSupportedException))]
139 public void AutoGeneratedField_InsertVisibleExeption ()
141 AutoGeneratedField field = new AutoGeneratedField ("test");
142 field.InsertVisible = false;