AssemblyInformationalVersionAttributeTest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // AssemblyInformationalVersionAttributeTest.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 AssemblyInformationalVersionAttribute.
  15. /// </summary>
  16. [TestFixture]
  17. public class AssemblyInformationalVersionAttributeTest : Assertion {
  18. private AssemblyBuilder dynAssembly;
  19. AssemblyName dynAsmName = new AssemblyName ();
  20. AssemblyInformationalVersionAttribute attr;
  21. public AssemblyInformationalVersionAttributeTest ()
  22. {
  23. //create a dynamic assembly with the required attribute
  24. //and check for the validity
  25. dynAsmName.Name = "TestAssembly";
  26. dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
  27. dynAsmName,AssemblyBuilderAccess.Run
  28. );
  29. // Set the required Attribute of the assembly.
  30. Type attribute = typeof (AssemblyInformationalVersionAttribute);
  31. ConstructorInfo ctrInfo = attribute.GetConstructor (
  32. new Type [] { typeof (string) }
  33. );
  34. CustomAttributeBuilder attrBuilder =
  35. new CustomAttributeBuilder (ctrInfo, new object [1] { "2.0.0.0" });
  36. dynAssembly.SetCustomAttribute (attrBuilder);
  37. object [] attributes = dynAssembly.GetCustomAttributes (true);
  38. attr = attributes [0] as AssemblyInformationalVersionAttribute;
  39. }
  40. [Test]
  41. public void InformationalVersionTest ()
  42. {
  43. AssertEquals ("#Testing InformationalVersion",
  44. attr.InformationalVersion,
  45. "2.0.0.0");
  46. }
  47. [Test]
  48. public void TypeIdTest ()
  49. {
  50. AssertEquals ("#testing Typeid",
  51. attr.TypeId,
  52. typeof (AssemblyInformationalVersionAttribute)
  53. );
  54. }
  55. [Test]
  56. public void MatchTestForTrue ()
  57. {
  58. AssertEquals ("#testing Match method-- for true",
  59. attr.Match (attr),
  60. true);
  61. }
  62. [Test]
  63. public void MatchTestForFalse ()
  64. {
  65. AssertEquals ("#testing Match method-- for false",
  66. attr.Match (new AssemblyInformationalVersionAttribute ("Descrptn")),
  67. false);
  68. }
  69. }
  70. }