AssemblyDescriptionAttributeTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // AssemblyDescriptionAttributeTest.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 AssemblyDescriptionAttributeTest.
  15. /// </summary>
  16. [TestFixture]
  17. public class AssemblyDescriptionAttributeTest : Assertion
  18. {
  19. private AssemblyBuilder dynAssembly;
  20. AssemblyName dynAsmName = new AssemblyName ();
  21. AssemblyDescriptionAttribute attr;
  22. public AssemblyDescriptionAttributeTest ()
  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 (AssemblyDescriptionAttribute);
  32. ConstructorInfo ctrInfo = attribute.GetConstructor (
  33. new Type [] { typeof (string) }
  34. );
  35. CustomAttributeBuilder attrBuilder =
  36. new CustomAttributeBuilder (ctrInfo, new object [1] { "Emitted Assembly" });
  37. dynAssembly.SetCustomAttribute (attrBuilder);
  38. object [] attributes = dynAssembly.GetCustomAttributes (true);
  39. attr = attributes [0] as AssemblyDescriptionAttribute;
  40. }
  41. [Test]
  42. public void DescriptionTest ()
  43. {
  44. AssertEquals ("#Testing Description",
  45. attr.Description,
  46. "Emitted Assembly");
  47. }
  48. [Test]
  49. public void TypeIdTest ()
  50. {
  51. AssertEquals ("#testing Typeid",
  52. attr.TypeId,
  53. typeof (AssemblyDescriptionAttribute)
  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 AssemblyDescriptionAttribute ("Descrptn")),
  68. false);
  69. }
  70. }
  71. }