AutoGeneratedFieldTest.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // Tests for System.Web.UI.WebControls.AutoGeneratedField.cs
  3. //
  4. // Author:
  5. // Yoni Klein ([email protected])
  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. #if NET_2_0
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Text;
  32. using System.Web;
  33. using System.Web.UI;
  34. using System.Web.UI.WebControls;
  35. using System.IO;
  36. using System.Drawing;
  37. using System.Collections;
  38. using System.Collections.Specialized;
  39. using NUnit.Framework;
  40. namespace MonoTests.System.Web.UI.WebControls
  41. {
  42. [TestFixture]
  43. public class AutoGeneratedFieldTest
  44. {
  45. [Test]
  46. public void AutoGeneratedField_DefaultProperty ()
  47. {
  48. AutoGeneratedField field = new AutoGeneratedField ("test");
  49. Assert.AreEqual (true, field.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
  50. Assert.AreEqual (string.Empty, field.DataFormatString, "DataFormatString");
  51. Assert.AreEqual (true, field.InsertVisible, "InsertVisible");
  52. }
  53. [Test]
  54. public void AutoGeneratedField_DefaultPropertyNotWorking ()
  55. {
  56. AutoGeneratedField field = new AutoGeneratedField ("test");
  57. Assert.AreEqual (typeof (String), field.DataType, "DataType");
  58. }
  59. [Test]
  60. public void AutoGeneratedField_AssignProperty ()
  61. {
  62. AutoGeneratedField field = new AutoGeneratedField ("test");
  63. Assert.AreEqual ("test", field.DataField, "DataField");
  64. field.DataType = typeof (bool);
  65. Assert.AreEqual (typeof (bool), field.DataType, "DataType");
  66. }
  67. [Test]
  68. public void AutoGeneratedField_ExtractValuesFromCell()
  69. {
  70. AutoGeneratedField field = new AutoGeneratedField ("field");
  71. OrderedDictionary dictionary = new OrderedDictionary ();
  72. DataControlFieldCell cell = new DataControlFieldCell (null);
  73. cell.Text = "cell";
  74. field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
  75. Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
  76. Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue");
  77. }
  78. [Test]
  79. public void AutoGeneratedField_ExtractValuesFromCellCheckbox ()
  80. {
  81. // Aditional implementation for bollean data type
  82. AutoGeneratedField field = new AutoGeneratedField ("field");
  83. field.DataType = typeof (bool);
  84. OrderedDictionary dictionary = new OrderedDictionary ();
  85. DataControlFieldCell cell = new DataControlFieldCell(null);
  86. cell.Controls.Add (new CheckBox ());
  87. field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
  88. Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
  89. Assert.AreEqual ("False", dictionary[0].ToString (), "ExtractValuesFromCellValue");
  90. CheckBox cb = new CheckBox ();
  91. cb.Checked = true;
  92. cell.Controls.Clear ();
  93. cell.Controls.Add (cb);
  94. field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
  95. Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
  96. Assert.AreEqual ("True", dictionary[0].ToString (), "ExtractValuesFromCellValue");
  97. }
  98. [Test]
  99. public void AutoGeneratedField_ValidateSupportsCallback ()
  100. {
  101. //This method has been implemented as an empty method
  102. }
  103. [Test]
  104. [ExpectedException(typeof(NotSupportedException))]
  105. public void AutoGeneratedField_ConvertEmptyStringToNullExeption ()
  106. {
  107. AutoGeneratedField field = new AutoGeneratedField ("test");
  108. field.ConvertEmptyStringToNull = false;
  109. }
  110. [Test]
  111. [ExpectedException (typeof (NotSupportedException))]
  112. public void AutoGeneratedField_DataFormatStringExeption ()
  113. {
  114. AutoGeneratedField field = new AutoGeneratedField ("test");
  115. field.DataFormatString = "test";
  116. }
  117. [Test]
  118. [ExpectedException (typeof (NotSupportedException))]
  119. public void AutoGeneratedField_InsertVisibleExeption ()
  120. {
  121. AutoGeneratedField field = new AutoGeneratedField ("test");
  122. field.InsertVisible = false;
  123. }
  124. }
  125. }
  126. #endif