AssemblyCopyrightAttributeTest.cs 1.9 KB

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