HtmlFormTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // HtmlFormTest.cs
  3. // - Unit tests for System.Web.UI.HtmlControls.HtmlForm
  4. //
  5. // Author:
  6. // Dick Porter <[email protected]>
  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. using System;
  30. using System.IO;
  31. using System.Web.UI;
  32. using System.Web.UI.HtmlControls;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.UI.HtmlControls {
  35. public class FormPoker : HtmlForm {
  36. public FormPoker () {
  37. TrackViewState ();
  38. }
  39. public object SaveState ()
  40. {
  41. return SaveViewState ();
  42. }
  43. public void LoadState (object state)
  44. {
  45. LoadViewState (state);
  46. }
  47. #if NET_2_0
  48. public ControlCollection GetControlCollection ()
  49. {
  50. return CreateControlCollection();
  51. }
  52. #endif
  53. }
  54. [TestFixture]
  55. public class HtmlFormTest {
  56. [Test]
  57. public void DefaultProperties ()
  58. {
  59. HtmlForm form = new HtmlForm ();
  60. Assert.AreEqual (0, form.Attributes.Count, "Attributes.Count");
  61. Assert.AreEqual (String.Empty, form.Enctype, "Enctype");
  62. Assert.AreEqual ("post", form.Method, "Method");
  63. Assert.AreEqual (form.UniqueID, form.Name, "Name");
  64. Assert.AreEqual (String.Empty, form.Target, "Target");
  65. Assert.AreEqual ("form", form.TagName, "TagName");
  66. #if NET_2_0
  67. Assert.IsFalse (form.SubmitDisabledControls, "TagName");
  68. #endif
  69. }
  70. [Test]
  71. public void NullProperties ()
  72. {
  73. HtmlForm form = new HtmlForm ();
  74. form.Enctype = null;
  75. Assert.AreEqual (String.Empty, form.Enctype, "Enctype");
  76. form.Method = null;
  77. Assert.AreEqual ("post", form.Method, "Method");
  78. form.Name = null;
  79. Assert.AreEqual (form.UniqueID, form.Name, "Name");
  80. form.Target = null;
  81. Assert.AreEqual (String.Empty, form.Target, "Target");
  82. #if NET_2_0
  83. form.DefaultButton = null;
  84. Assert.AreEqual (String.Empty, form.DefaultButton, "DefaultButton");
  85. form.DefaultFocus = null;
  86. Assert.AreEqual (String.Empty, form.DefaultFocus, "DefaultFocus");
  87. #endif
  88. Assert.AreEqual (0, form.Attributes.Count, "Attributes.Count");
  89. }
  90. [Test]
  91. public void Attributes ()
  92. {
  93. HtmlForm form = new HtmlForm ();
  94. IAttributeAccessor a = (IAttributeAccessor)form;
  95. #if NET_2_0
  96. /* not stored in Attributes */
  97. form.DefaultButton = "defaultbutton";
  98. Assert.IsNull (a.GetAttribute ("defaultbutton"), "A1");
  99. /* not stored in Attributes */
  100. form.DefaultFocus = "defaultfocus";
  101. Assert.IsNull (a.GetAttribute ("defaultfocus"), "A2");
  102. #endif
  103. form.Enctype = "enctype";
  104. Assert.AreEqual ("enctype", a.GetAttribute ("enctype"), "A3");
  105. form.Method = "method";
  106. Assert.AreEqual ("method", a.GetAttribute ("method"), "A4");
  107. /* not stored in Attributes */
  108. form.Name = "name";
  109. Assert.IsNull (a.GetAttribute ("name"), "A5");
  110. #if NET_2_0
  111. form.SubmitDisabledControls = true;
  112. Assert.IsNull (a.GetAttribute ("submitdisabledcontrols"), "A6");
  113. #endif
  114. form.Target = "target";
  115. Assert.AreEqual ("target", a.GetAttribute ("target"), "A7");
  116. }
  117. [Test]
  118. public void ViewState ()
  119. {
  120. FormPoker form = new FormPoker();
  121. FormPoker copy = new FormPoker();
  122. #if NET_2_0
  123. form.DefaultButton = "defaultbutton";
  124. form.DefaultFocus = "defaultfocus";
  125. #endif
  126. object state = form.SaveState();
  127. copy.LoadState (state);
  128. #if NET_2_0
  129. Assert.AreEqual ("", copy.DefaultButton, "A1");
  130. Assert.AreEqual ("defaultfocus", form.DefaultFocus, "A2");
  131. #endif
  132. }
  133. #if NET_2_0
  134. [Test]
  135. public void ControlCollection ()
  136. {
  137. FormPoker poker = new FormPoker();
  138. ControlCollection col = poker.GetControlCollection();
  139. Assert.AreEqual (col.GetType(), typeof (ControlCollection), "A1");
  140. Assert.IsFalse (col.IsReadOnly, "A2");
  141. Assert.AreEqual (0, col.Count, "A3");
  142. }
  143. #endif
  144. }
  145. }