AssemblyInformationalVersionAttributeTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // AssemblyInformationalVersionAttributeTest.cs
  2. //
  3. // Author: Vineeth N <[email protected]>
  4. //
  5. // (C) 2004 Ximian, Inc. http://www.ximian.com
  6. //
  7. #if !MOBILE
  8. using System;
  9. using System.Threading;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Reflection {
  14. /// <summary>
  15. /// Test Fixture for AssemblyInformationalVersionAttribute.
  16. /// </summary>
  17. [TestFixture]
  18. public class AssemblyInformationalVersionAttributeTest {
  19. private AssemblyBuilder dynAssembly;
  20. AssemblyName dynAsmName = new AssemblyName ();
  21. AssemblyInformationalVersionAttribute attr;
  22. public AssemblyInformationalVersionAttributeTest ()
  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 (AssemblyInformationalVersionAttribute);
  32. ConstructorInfo ctrInfo = attribute.GetConstructor (
  33. new Type [] { typeof (string) }
  34. );
  35. CustomAttributeBuilder attrBuilder =
  36. new CustomAttributeBuilder (ctrInfo, new object [1] { "2.0.0.0" });
  37. dynAssembly.SetCustomAttribute (attrBuilder);
  38. object [] attributes = dynAssembly.GetCustomAttributes (true);
  39. attr = attributes [0] as AssemblyInformationalVersionAttribute;
  40. }
  41. [Test]
  42. public void InformationalVersionTest ()
  43. {
  44. Assert.AreEqual (attr.InformationalVersion,
  45. "2.0.0.0", "#1");
  46. }
  47. [Test]
  48. public void TypeIdTest ()
  49. {
  50. Assert.AreEqual (
  51. attr.TypeId,
  52. typeof (AssemblyInformationalVersionAttribute), "#1"
  53. );
  54. }
  55. [Test]
  56. public void MatchTestForTrue ()
  57. {
  58. Assert.AreEqual (
  59. attr.Match (attr),
  60. true, "#1");
  61. }
  62. [Test]
  63. public void MatchTestForFalse ()
  64. {
  65. Assert.AreEqual (
  66. attr.Match (new AssemblyInformationalVersionAttribute ("Descrptn")),
  67. false, "#1");
  68. }
  69. }
  70. }
  71. #endif