AssemblyInformationalVersionAttributeTest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 {
  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. Assert.AreEqual (attr.InformationalVersion,
  44. "2.0.0.0", "#1");
  45. }
  46. [Test]
  47. public void TypeIdTest ()
  48. {
  49. Assert.AreEqual (
  50. attr.TypeId,
  51. typeof (AssemblyInformationalVersionAttribute), "#1"
  52. );
  53. }
  54. [Test]
  55. public void MatchTestForTrue ()
  56. {
  57. Assert.AreEqual (
  58. attr.Match (attr),
  59. true, "#1");
  60. }
  61. [Test]
  62. public void MatchTestForFalse ()
  63. {
  64. Assert.AreEqual (
  65. attr.Match (new AssemblyInformationalVersionAttribute ("Descrptn")),
  66. false, "#1");
  67. }
  68. }
  69. }