ControlCas.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // ControlCas.cs - CAS unit tests for System.Web.UI.Control
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 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.IO;
  31. using System.Reflection;
  32. using System.Security;
  33. using System.Security.Permissions;
  34. using System.Web;
  35. using System.Web.UI;
  36. using System.Web.UI.WebControls;
  37. namespace MonoCasTests.System.Web.UI {
  38. [TestFixture]
  39. [Category ("CAS")]
  40. public class ControlCas : AspNetHostingMinimal {
  41. private Control control;
  42. private HtmlTextWriter writer;
  43. private Page page;
  44. [TestFixtureSetUp]
  45. public void FixtureSetUp ()
  46. {
  47. control = new Control ();
  48. writer = new HtmlTextWriter (new StringWriter ());
  49. page = new Page ();
  50. }
  51. [Test]
  52. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  53. public void Properties_Deny_Unrestricted ()
  54. {
  55. Control c = new Control ();
  56. Assert.IsNull (c.ClientID, "ClientID");
  57. Assert.IsNotNull (c.Controls, "Controls");
  58. c.EnableViewState = true;
  59. Assert.IsTrue (c.EnableViewState, "EnableViewState");
  60. c.ID = "mono";
  61. Assert.AreEqual ("mono", c.ID, "ID");
  62. Assert.IsNull (c.NamingContainer, "NamingContainer");
  63. Assert.IsNull (c.Page, "Page");
  64. Assert.IsNull (c.Parent, "Parent");
  65. Assert.IsNull (c.Site, "Site");
  66. Assert.AreEqual ("mono", c.UniqueID, "UniqueID");
  67. Assert.IsTrue (c.Visible, "Visible");
  68. #if NET_2_0
  69. c.AppRelativeTemplateSourceDirectory = String.Empty;
  70. Assert.AreEqual (String.Empty, c.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory");
  71. c.EnableTheming = true;
  72. Assert.IsTrue (c.EnableTheming, "EnableTheming");
  73. c.SkinID = String.Empty;
  74. Assert.AreEqual (String.Empty, c.SkinID, "SkinID");
  75. c.TemplateControl = null;
  76. Assert.IsNull (c.TemplateControl, "TemplateControl");
  77. Assert.AreEqual (String.Empty, c.TemplateSourceDirectory, "TemplateSourceDirectory");
  78. #endif
  79. }
  80. private void SetRenderMethodDelegate (HtmlTextWriter writer, Control control)
  81. {
  82. }
  83. [Test]
  84. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  85. public void Methods_Deny_Unrestricted ()
  86. {
  87. Control c = new Control ();
  88. c.DataBind ();
  89. Assert.IsNull (c.FindControl ("mono"), "FindControl");
  90. Assert.IsFalse (c.HasControls (), "HasControls");
  91. c.RenderControl (writer);
  92. Assert.IsNotNull (c.ResolveUrl (String.Empty), "ResolveUrl");
  93. c.SetRenderMethodDelegate (new RenderMethod (SetRenderMethodDelegate));
  94. #if NET_2_0
  95. c.ApplyStyleSheetSkin (page);
  96. Assert.IsNotNull (c.ResolveClientUrl (String.Empty), "ResolveClientUrl");
  97. #endif
  98. c.Dispose ();
  99. }
  100. #if NET_2_0
  101. [Test]
  102. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  103. [ExpectedException (typeof (InvalidOperationException))]
  104. public void Focus_Deny_Unrestricted ()
  105. {
  106. Control c = new Control ();
  107. page.Controls.Add (c);
  108. c.Focus ();
  109. // normal, no forms on page
  110. }
  111. #endif
  112. private void Handler (object sender, EventArgs e)
  113. {
  114. }
  115. [Test]
  116. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  117. public void Events_Deny_Unrestricted ()
  118. {
  119. Control c = new Control ();
  120. c.DataBinding += new EventHandler (Handler);
  121. c.Disposed += new EventHandler (Handler);
  122. c.Init += new EventHandler (Handler);
  123. c.Load += new EventHandler (Handler);
  124. c.PreRender += new EventHandler (Handler);
  125. c.Unload += new EventHandler (Handler);
  126. c.DataBinding -= new EventHandler (Handler);
  127. c.Disposed -= new EventHandler (Handler);
  128. c.Init -= new EventHandler (Handler);
  129. c.Load -= new EventHandler (Handler);
  130. c.PreRender -= new EventHandler (Handler);
  131. c.Unload -= new EventHandler (Handler);
  132. }
  133. // LinkDemand
  134. public override Type Type {
  135. get { return typeof (Control); }
  136. }
  137. }
  138. }