WebControlAdapterTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // Tests for System.Web.UI.WebControls.Adapters.WebControlAdapter
  3. //
  4. // Author:
  5. // Dean Brettle ([email protected])
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using NUnit.Framework;
  29. using System;
  30. using System.Collections;
  31. using System.Drawing;
  32. using System.IO;
  33. using System.Globalization;
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Web.UI.WebControls;
  37. using System.Web.UI.WebControls.Adapters;
  38. using System.Web.Configuration;
  39. using MonoTests.SystemWeb.Framework;
  40. namespace MonoTests.System.Web.UI.WebControls.Adapters
  41. {
  42. [TestFixture]
  43. public class WebControlAdapterTest
  44. {
  45. MyWebControl c;
  46. MyWebControlAdapter a;
  47. StringWriter sw;
  48. HtmlTextWriter w;
  49. [SetUp]
  50. public void SetUp ()
  51. {
  52. c = new MyWebControl ();
  53. a = new MyWebControlAdapter (c);
  54. sw = new StringWriter ();
  55. w = new HtmlTextWriter (sw);
  56. }
  57. [Test]
  58. public void RenderBeginTag ()
  59. {
  60. a.RenderBeginTag (w);
  61. Assert.AreEqual ("RenderBeginTag\n", sw.ToString (), "RenderBeginTag #1");
  62. }
  63. [Test]
  64. public void RenderContentsTag ()
  65. {
  66. a.RenderContents (w);
  67. Assert.AreEqual ("RenderContents\n", sw.ToString (), "RenderContents #1");
  68. }
  69. [Test]
  70. public void RenderEndTag ()
  71. {
  72. a.RenderEndTag (w);
  73. Assert.AreEqual ("RenderEndTag\n", sw.ToString (), "RenderEndTag #1");
  74. }
  75. [Test]
  76. public void Render ()
  77. {
  78. a.Render (w);
  79. Assert.AreEqual ("RenderBeginTag\nRenderContents\nRenderEndTag\n", sw.ToString (), "Render #1");
  80. }
  81. [Test]
  82. public void Control ()
  83. {
  84. Assert.AreEqual (c, a.Control, "Control #1");
  85. }
  86. [Test]
  87. public void IsEnabled ()
  88. {
  89. MyWebControl parent = new MyWebControl ();
  90. parent.Controls.Add (c);
  91. Assert.IsTrue (a.IsEnabled, "IsEnabled #1");
  92. parent.Enabled = false;
  93. Assert.IsFalse (a.IsEnabled, "IsEnabled #2");
  94. parent.Enabled = true;
  95. c.Enabled = false;
  96. Assert.IsFalse (a.IsEnabled, "IsEnabled #3");
  97. }
  98. #region Support classes
  99. class MyWebControl : WebControl
  100. {
  101. public override void RenderBeginTag (HtmlTextWriter w)
  102. {
  103. w.WriteLine("RenderBeginTag");
  104. }
  105. protected internal override void RenderContents (HtmlTextWriter w)
  106. {
  107. w.WriteLine("RenderContents");
  108. }
  109. public override void RenderEndTag (HtmlTextWriter w)
  110. {
  111. w.WriteLine("RenderEndTag");
  112. }
  113. }
  114. class MyWebControlAdapter : SystemWebTestShim.WebControlAdapter
  115. {
  116. internal MyWebControlAdapter (WebControl wc) : base (wc)
  117. {
  118. }
  119. new internal void RenderBeginTag (HtmlTextWriter w)
  120. {
  121. base.RenderBeginTag(w);
  122. }
  123. new internal void RenderContents (HtmlTextWriter w)
  124. {
  125. base.RenderContents(w);
  126. }
  127. new internal void RenderEndTag (HtmlTextWriter w)
  128. {
  129. base.RenderEndTag(w);
  130. }
  131. new internal void Render (HtmlTextWriter w)
  132. {
  133. base.Render(w);
  134. }
  135. new internal WebControl Control {
  136. get { return base.Control; }
  137. }
  138. new internal bool IsEnabled {
  139. get { return base.IsEnabled; }
  140. }
  141. }
  142. #endregion
  143. }
  144. }