AssemblyDelaySignAttributeTest.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // AssemblyDelaySignAttributeTest.cs
  2. //
  3. // Author: Vineeth N <[email protected]>
  4. //
  5. // (C) 2004 Ximian, Inc. http://www.ximian.com
  6. //
  7. using System;
  8. using System.Threading;
  9. using System.Reflection;
  10. using System.Reflection.Emit;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Reflection {
  13. /// <summary>
  14. /// Summary description for AssemblyDelaySignAttributeTest.
  15. /// </summary>
  16. [TestFixture]
  17. public class AssemblyDelaySignAttributeTest:Assertion
  18. {
  19. private AssemblyBuilder dynAssembly;
  20. AssemblyName dynAsmName = new AssemblyName ();
  21. AssemblyDelaySignAttribute attr;
  22. public AssemblyDelaySignAttributeTest ()
  23. {
  24. //create a dynamic assembly with the required attribute
  25. //and check for the validity
  26. dynAsmName.Name = "TestAssembly";
  27. dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
  28. dynAsmName,AssemblyBuilderAccess.Run
  29. );
  30. // Set the required Attribute of the assembly.
  31. Type attribute = typeof (AssemblyDelaySignAttribute);
  32. ConstructorInfo ctrInfo = attribute.GetConstructor (
  33. new Type [] { typeof (bool) }
  34. );
  35. CustomAttributeBuilder attrBuilder =
  36. new CustomAttributeBuilder (ctrInfo, new object [1] { false });
  37. dynAssembly.SetCustomAttribute (attrBuilder);
  38. object [] attributes = dynAssembly.GetCustomAttributes (true);
  39. attr = attributes [0] as AssemblyDelaySignAttribute;
  40. }
  41. [Test]
  42. public void DelaySignTest ()
  43. {
  44. AssertEquals ("#Testing DelaySign",
  45. attr.DelaySign,
  46. false);
  47. }
  48. [Test]
  49. public void TypeIdTest ()
  50. {
  51. AssertEquals ("#testing Typeid",
  52. attr.TypeId,
  53. typeof (AssemblyDelaySignAttribute)
  54. );
  55. }
  56. [Test]
  57. public void MatchTestForTrue ()
  58. {
  59. AssertEquals ("#testing Match method-- for true",
  60. attr.Match (attr),
  61. true);
  62. }
  63. [Test]
  64. public void MatchTestForFalse ()
  65. {
  66. AssertEquals ("#testing Match method-- for false",
  67. attr.Match (new AssemblyDelaySignAttribute (true)),
  68. false);
  69. }
  70. }
  71. }