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 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 44 45 46 47 namespace MonoTests.System.Web.UI.WebControls 48 { 49 50 [TestFixture] 51 public class AutoGeneratedFieldTest 52 { 53 [Test] AutoGeneratedField_DefaultProperty()54 public void AutoGeneratedField_DefaultProperty () 55 { 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"); 60 } 61 62 [Test] AutoGeneratedField_DefaultPropertyNotWorking()63 public void AutoGeneratedField_DefaultPropertyNotWorking () 64 { 65 AutoGeneratedField field = new AutoGeneratedField ("test"); 66 Assert.AreEqual (typeof (String), field.DataType, "DataType"); 67 } 68 69 [Test] AutoGeneratedField_AssignProperty()70 public void AutoGeneratedField_AssignProperty () 71 { 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"); 76 } 77 78 [Test] AutoGeneratedField_ExtractValuesFromCell()79 public void AutoGeneratedField_ExtractValuesFromCell() 80 { 81 AutoGeneratedField field = new AutoGeneratedField ("field"); 82 OrderedDictionary dictionary = new OrderedDictionary (); 83 DataControlFieldCell cell = new DataControlFieldCell (null); 84 cell.Text = "cell"; 85 field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true); 86 Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount"); 87 Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue"); 88 } 89 90 [Test] AutoGeneratedField_ExtractValuesFromCellCheckbox()91 public void AutoGeneratedField_ExtractValuesFromCellCheckbox () 92 { 93 // Aditional implementation for bollean data type 94 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 (); 104 cb.Checked = true; 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"); 110 } 111 112 [Test] AutoGeneratedField_ValidateSupportsCallback()113 public void AutoGeneratedField_ValidateSupportsCallback () 114 { 115 //This method has been implemented as an empty method 116 } 117 118 [Test] AutoGeneratedField_BoolArray()119 public void AutoGeneratedField_BoolArray () { 120 GridView GridView1 = new GridView (); 121 GridView1.DataSource = new bool [] { true }; 122 GridView1.DataBind (); 123 } 124 125 [Test] 126 [ExpectedException(typeof(NotSupportedException))] AutoGeneratedField_ConvertEmptyStringToNullExeption()127 public void AutoGeneratedField_ConvertEmptyStringToNullExeption () 128 { 129 AutoGeneratedField field = new AutoGeneratedField ("test"); 130 field.ConvertEmptyStringToNull = false; 131 132 } 133 134 [Test] 135 [ExpectedException (typeof (NotSupportedException))] AutoGeneratedField_DataFormatStringExeption()136 public void AutoGeneratedField_DataFormatStringExeption () 137 { 138 AutoGeneratedField field = new AutoGeneratedField ("test"); 139 field.DataFormatString = "test"; 140 } 141 142 [Test] 143 [ExpectedException (typeof (NotSupportedException))] AutoGeneratedField_InsertVisibleExeption()144 public void AutoGeneratedField_InsertVisibleExeption () 145 { 146 AutoGeneratedField field = new AutoGeneratedField ("test"); 147 field.InsertVisible = false; 148 } 149 150 } 151 } 152