InstanceDescriptorCas.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // InstanceDescriptorCas.cs - CAS unit tests for
  3. // System.ComponentModel.Design.Serialization.InstanceDescriptor
  4. //
  5. // Author:
  6. // Sebastien Pouliot <[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 NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.ComponentModel.Design.Serialization;
  33. using System.Reflection;
  34. using System.Security;
  35. using System.Security.Permissions;
  36. using MonoTests.System.ComponentModel.Design.Serialization;
  37. namespace MonoCasTests.System.ComponentModel.Design.Serialization {
  38. [TestFixture]
  39. [Category ("CAS")]
  40. public class InstanceDescriptorCas {
  41. [SetUp]
  42. public virtual void SetUp ()
  43. {
  44. if (!SecurityManager.SecurityEnabled)
  45. Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
  46. }
  47. [Test]
  48. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  49. public void UnitTestReuse ()
  50. {
  51. InstanceDescriptorTest unit = new InstanceDescriptorTest ();
  52. unit.FixtureSetUp ();
  53. unit.Constructor_Null_ICollection ();
  54. unit.Constructor_MemberInfo_ICollection ();
  55. unit.Constructor_Null_ICollection_Boolean ();
  56. unit.Constructor_MemberInfo_ICollection_Boolean ();
  57. }
  58. [Test]
  59. [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
  60. [ExpectedException (typeof (SecurityException))]
  61. public void Ctor2_LinkDemand_Deny_Anything ()
  62. {
  63. // denying anything -> not unrestricted
  64. Type[] types = new Type[2] { typeof (MemberInfo), typeof (ICollection) };
  65. ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
  66. Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection)");
  67. Assert.IsNotNull (ci.Invoke (new object[2] { null, new object[] { } }), "invoke");
  68. }
  69. [Test]
  70. [PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
  71. public void Ctor2_LinkDemand_PermitOnly_Unrestricted ()
  72. {
  73. Type[] types = new Type[2] { typeof (MemberInfo), typeof (ICollection) };
  74. ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
  75. Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection)");
  76. Assert.IsNotNull (ci.Invoke (new object[2] { null, new object[] { } }), "invoke");
  77. }
  78. [Test]
  79. [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
  80. [ExpectedException (typeof (SecurityException))]
  81. public void Ctor3_LinkDemand_Deny_Anything ()
  82. {
  83. // denying anything -> not unrestricted
  84. Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
  85. ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
  86. Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection,bool)");
  87. Assert.IsNotNull (ci.Invoke (new object[3] { null, new object[] { }, false }), "invoke");
  88. }
  89. [Test]
  90. [PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
  91. public void Ctor3_LinkDemand_PermitOnly_Unrestricted ()
  92. {
  93. Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
  94. ConstructorInfo ci = typeof (InstanceDescriptor).GetConstructor (types);
  95. Assert.IsNotNull (ci, ".ctor(MemberInfo,ICollection,bool)");
  96. Assert.IsNotNull (ci.Invoke (new object[3] { null, new object[] { }, false }), "invoke");
  97. }
  98. [Test]
  99. [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
  100. [ExpectedException (typeof (SecurityException))]
  101. public void Property_LinkDemand_Deny_Anything ()
  102. {
  103. InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
  104. // denying anything -> not unrestricted
  105. Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
  106. MethodInfo mi = typeof (InstanceDescriptor).GetProperty ("IsComplete").GetGetMethod ();
  107. Assert.IsNotNull (mi, "IsComplete)");
  108. Assert.IsTrue ((bool)mi.Invoke (id, null), "invoke");
  109. }
  110. [Test]
  111. [PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
  112. public void Property_LinkDemand_PermitOnly_Unrestricted ()
  113. {
  114. InstanceDescriptor id = new InstanceDescriptor (null, new object[] { });
  115. // denying anything -> not unrestricted
  116. Type[] types = new Type[3] { typeof (MemberInfo), typeof (ICollection), typeof (bool) };
  117. MethodInfo mi = typeof (InstanceDescriptor).GetProperty ("IsComplete").GetGetMethod ();
  118. Assert.IsNotNull (mi, "IsComplete)");
  119. Assert.IsTrue ((bool) mi.Invoke (id, null), "invoke");
  120. }
  121. }
  122. }