AssemblyFileVersionAttributeTest.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 {
  18. #if !MOBILE
  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. #endif
  77. [Test]
  78. public void CtorTest ()
  79. {
  80. var a = new AssemblyFileVersionAttribute ("1.2.3.4");
  81. Assert.AreEqual ("1.2.3.4", a.Version);
  82. }
  83. }
  84. }