WebControlAdapterTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #if NET_2_0
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Drawing;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. using System.Web.UI.WebControls.Adapters;
  39. using System.Web.Configuration;
  40. using MonoTests.SystemWeb.Framework;
  41. namespace MonoTests.System.Web.UI.WebControls.Adapters
  42. {
  43. [TestFixture]
  44. public class WebControlAdapterTest
  45. {
  46. MyWebControl c;
  47. MyWebControlAdapter a;
  48. StringWriter sw;
  49. HtmlTextWriter w;
  50. [SetUp]
  51. public void SetUp ()
  52. {
  53. c = new MyWebControl ();
  54. a = new MyWebControlAdapter (c);
  55. sw = new StringWriter ();
  56. w = new HtmlTextWriter (sw);
  57. }
  58. [Test]
  59. public void RenderBeginTag ()
  60. {
  61. a.RenderBeginTag (w);
  62. Assert.AreEqual ("RenderBeginTag\n", sw.ToString (), "RenderBeginTag #1");
  63. }
  64. [Test]
  65. public void RenderContentsTag ()
  66. {
  67. a.RenderContents (w);
  68. Assert.AreEqual ("RenderContents\n", sw.ToString (), "RenderContents #1");
  69. }
  70. [Test]
  71. public void RenderEndTag ()
  72. {
  73. a.RenderEndTag (w);
  74. Assert.AreEqual ("RenderEndTag\n", sw.ToString (), "RenderEndTag #1");
  75. }
  76. [Test]
  77. public void Render ()
  78. {
  79. a.Render (w);
  80. Assert.AreEqual ("RenderBeginTag\nRenderContents\nRenderEndTag\n", sw.ToString (), "Render #1");
  81. }
  82. [Test]
  83. public void Control ()
  84. {
  85. Assert.AreEqual (c, a.Control, "Control #1");
  86. }
  87. [Test]
  88. public void IsEnabled ()
  89. {
  90. MyWebControl parent = new MyWebControl ();
  91. parent.Controls.Add (c);
  92. Assert.IsTrue (a.IsEnabled, "IsEnabled #1");
  93. parent.Enabled = false;
  94. Assert.IsFalse (a.IsEnabled, "IsEnabled #2");
  95. parent.Enabled = true;
  96. c.Enabled = false;
  97. Assert.IsFalse (a.IsEnabled, "IsEnabled #3");
  98. }
  99. #region Support classes
  100. class MyWebControl : WebControl
  101. {
  102. public override void RenderBeginTag (HtmlTextWriter w)
  103. {
  104. w.WriteLine("RenderBeginTag");
  105. }
  106. protected internal override void RenderContents (HtmlTextWriter w)
  107. {
  108. w.WriteLine("RenderContents");
  109. }
  110. public override void RenderEndTag (HtmlTextWriter w)
  111. {
  112. w.WriteLine("RenderEndTag");
  113. }
  114. }
  115. class MyWebControlAdapter : WebControlAdapter
  116. {
  117. internal MyWebControlAdapter (WebControl wc) : base (wc)
  118. {
  119. }
  120. new internal void RenderBeginTag (HtmlTextWriter w)
  121. {
  122. base.RenderBeginTag(w);
  123. }
  124. new internal void RenderContents (HtmlTextWriter w)
  125. {
  126. base.RenderContents(w);
  127. }
  128. new internal void RenderEndTag (HtmlTextWriter w)
  129. {
  130. base.RenderEndTag(w);
  131. }
  132. new internal void Render (HtmlTextWriter w)
  133. {
  134. base.Render(w);
  135. }
  136. new internal WebControl Control {
  137. get { return base.Control; }
  138. }
  139. new internal bool IsEnabled {
  140. get { return base.IsEnabled; }
  141. }
  142. }
  143. #endregion
  144. }
  145. }
  146. #endif