AssemblyFileVersionAttributeTest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 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. Assert.AreEqual (attr.Version,
  51. "1.0.0.0", "#1");
  52. }
  53. [Test]
  54. public void TypeIdTest ()
  55. {
  56. Assert.AreEqual (
  57. attr.TypeId,
  58. typeof (AssemblyFileVersionAttribute), "#1"
  59. );
  60. }
  61. [Test]
  62. public void MatchTestForTrue ()
  63. {
  64. Assert.AreEqual (
  65. attr.Match (attr),
  66. true, "#1");
  67. }
  68. [Test]
  69. public void MatchTestForFalse ()
  70. {
  71. Assert.AreEqual (
  72. attr.Match (new AssemblyFileVersionAttribute ("Descrptn")),
  73. false, "#1");
  74. }
  75. }
  76. }