AssemblyFileVersionAttributeTest.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // AssemblyFileVersionAttributeTest.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 AssemblyFileVersionAttributeTest.
  15. /// </summary>
  16. [TestFixture]
  17. public class AssemblyFileVersionAttributeTest : Assertion {
  18. private AssemblyBuilder dynAssembly;
  19. AssemblyName dynAsmName = new AssemblyName ();
  20. AssemblyFileVersionAttribute attr;
  21. public AssemblyFileVersionAttributeTest ()
  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 (AssemblyFileVersionAttribute);
  31. ConstructorInfo ctrInfo = attribute.GetConstructor (
  32. new Type [] { typeof(string) }
  33. );
  34. CustomAttributeBuilder attrBuilder =
  35. new CustomAttributeBuilder(ctrInfo, new object [1] { "1.0.0.0" });
  36. dynAssembly.SetCustomAttribute (attrBuilder);
  37. object [] attributes = dynAssembly.GetCustomAttributes (true);
  38. attr = attributes [0] as AssemblyFileVersionAttribute;
  39. }
  40. [Test]
  41. [ExpectedException (typeof (ArgumentNullException))]
  42. public void ArgumentNullExceptionTest()
  43. {
  44. string version = null;
  45. new AssemblyFileVersionAttribute (version);
  46. }
  47. [Test]
  48. public void FileVersionTest ()
  49. {
  50. AssertEquals ("#Testing FileVersion",
  51. attr.Version,
  52. "1.0.0.0");
  53. }
  54. [Test]
  55. public void TypeIdTest ()
  56. {
  57. AssertEquals ("#testing Typeid",
  58. attr.TypeId,
  59. typeof (AssemblyFileVersionAttribute)
  60. );
  61. }
  62. [Test]
  63. public void MatchTestForTrue ()
  64. {
  65. AssertEquals ("#testing Match method-- for true",
  66. attr.Match (attr),
  67. true);
  68. }
  69. [Test]
  70. public void MatchTestForFalse ()
  71. {
  72. AssertEquals ("#testing Match method-- for false",
  73. attr.Match (new AssemblyFileVersionAttribute ("Descrptn")),
  74. false);
  75. }
  76. }
  77. }