2007-02-05 Adar Wesley <adarw@mainsoft.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / AutoGeneratedFieldTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.AutoGeneratedField.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 #if NET_2_0
31
32
33 using System;
34 using System.Collections.Generic;
35 using System.Text;
36 using System.Web;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
39 using System.IO;
40 using System.Drawing;
41 using System.Collections;
42 using System.Collections.Specialized;
43 using NUnit.Framework;
44
45
46
47
48 namespace MonoTests.System.Web.UI.WebControls
49 {
50         
51         [TestFixture]
52         public class AutoGeneratedFieldTest
53         {
54                 [Test]
55                 public void AutoGeneratedField_DefaultProperty ()
56                 {
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");
61                 }
62
63                 [Test]
64                 public void AutoGeneratedField_DefaultPropertyNotWorking ()
65                 {
66                         AutoGeneratedField field = new AutoGeneratedField ("test");
67                         Assert.AreEqual (typeof (String), field.DataType, "DataType");
68                 }
69
70                 [Test]
71                 public void AutoGeneratedField_AssignProperty ()
72                 {
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");
77                 }
78
79                 [Test]
80                 public void AutoGeneratedField_ExtractValuesFromCell()
81                 {
82                         AutoGeneratedField field = new AutoGeneratedField ("field");
83                         OrderedDictionary dictionary = new OrderedDictionary ();
84                         DataControlFieldCell cell = new DataControlFieldCell (null);
85                         cell.Text = "cell";
86                         field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
87                         Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
88                         Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue");
89                 }
90
91                 [Test]
92                 public void AutoGeneratedField_ExtractValuesFromCellCheckbox ()
93                 {
94                         // Aditional implementation for bollean data type
95
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 ();
105                         cb.Checked = true;
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");
111                 }
112
113                 [Test]
114                 public void AutoGeneratedField_ValidateSupportsCallback ()
115                 {
116                         //This method has been implemented as an empty method  
117                 }
118
119
120                 [Test]
121                 [ExpectedException(typeof(NotSupportedException))]
122                 public void AutoGeneratedField_ConvertEmptyStringToNullExeption ()
123                 {
124                         AutoGeneratedField field = new AutoGeneratedField ("test");
125                         field.ConvertEmptyStringToNull = false; 
126
127                 }
128
129                 [Test]
130                 [ExpectedException (typeof (NotSupportedException))]
131                 public void AutoGeneratedField_DataFormatStringExeption ()
132                 {
133                         AutoGeneratedField field = new AutoGeneratedField ("test");
134                         field.DataFormatString = "test";
135                 }
136
137                 [Test]
138                 [ExpectedException (typeof (NotSupportedException))]
139                 public void AutoGeneratedField_InsertVisibleExeption ()
140                 {
141                         AutoGeneratedField field = new AutoGeneratedField ("test");
142                         field.InsertVisible = false;
143                 }
144
145         }
146 }
147 #endif