TemplateControlCas.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // TemplateControlCas.cs - CAS unit tests for System.Web.UI.TemplateControl
  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.Security.Permissions;
  32. using System.Web;
  33. using System.Web.UI;
  34. namespace MonoCasTests.System.Web.UI {
  35. class NonAbstractTemplateControl : TemplateControl {
  36. public NonAbstractTemplateControl ()
  37. {
  38. }
  39. }
  40. [TestFixture]
  41. [Category ("CAS")]
  42. public class TemplateControlCas {
  43. [Test]
  44. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  45. #if NET_2_0
  46. [ExpectedException (typeof (ArgumentNullException))]
  47. #else
  48. [ExpectedException (typeof (HttpException))]
  49. #endif
  50. public void LoadControl_Deny_Unrestricted ()
  51. {
  52. NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
  53. tc.LoadControl (null);
  54. }
  55. [Test]
  56. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  57. #if NET_2_0
  58. [ExpectedException (typeof (ArgumentNullException))]
  59. #else
  60. [ExpectedException (typeof (HttpException))]
  61. #endif
  62. public void LoadTemplate_Deny_Unrestricted ()
  63. {
  64. NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
  65. tc.LoadTemplate (null);
  66. }
  67. [Test]
  68. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  69. [ExpectedException (typeof (ArgumentNullException))]
  70. public void ParseControl_Deny_Unrestricted ()
  71. {
  72. NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
  73. try {
  74. tc.ParseControl (null);
  75. }
  76. catch (NullReferenceException) {
  77. #if NET_2_0
  78. throw;
  79. #else
  80. Assert.Ignore ("NRE");
  81. #endif
  82. }
  83. }
  84. [Test]
  85. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  86. [ExpectedException (typeof (ArgumentNullException))]
  87. public void ReadStringResource_Deny_Unrestricted ()
  88. {
  89. try {
  90. TemplateControl.ReadStringResource (null);
  91. }
  92. catch (TypeInitializationException) {
  93. #if NET_2_0
  94. Assert.Ignore ("exception during initialization");
  95. #else
  96. throw;
  97. #endif
  98. }
  99. }
  100. private void Handler (object sender, EventArgs e)
  101. {
  102. }
  103. [Test]
  104. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  105. public void Events_Deny_Unrestricted ()
  106. {
  107. NonAbstractTemplateControl tc = new NonAbstractTemplateControl ();
  108. tc.AbortTransaction += new EventHandler (Handler);
  109. tc.CommitTransaction += new EventHandler (Handler);
  110. tc.Error += new EventHandler (Handler);
  111. tc.AbortTransaction -= new EventHandler (Handler);
  112. tc.CommitTransaction -= new EventHandler (Handler);
  113. tc.Error -= new EventHandler (Handler);
  114. }
  115. #if NET_2_0
  116. [Test]
  117. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  118. [ExpectedException (typeof (TypeInitializationException))]
  119. public void IFilterResolutionService_Deny_Unrestricted ()
  120. {
  121. IFilterResolutionService frs = new NonAbstractTemplateControl ();
  122. try {
  123. Assert.AreEqual (0, frs.CompareFilters (String.Empty, String.Empty), "CompareFilters");
  124. }
  125. catch (NotImplementedException) {
  126. // mono
  127. }
  128. try {
  129. Assert.IsFalse (frs.EvaluateFilter (String.Empty), "EvaluateFilter");
  130. }
  131. catch (NotImplementedException) {
  132. // mono
  133. }
  134. }
  135. #endif
  136. }
  137. }