AssemblyFileVersionAttributeTest.cs 2.1 KB

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