1 // AssemblyInformationalVersionAttributeTest.cs 2 // 3 // Author: Vineeth N <nvineeth@yahoo.com> 4 // 5 // (C) 2004 Ximian, Inc. http://www.ximian.com 6 // 7 8 using System; 9 using System.Threading; 10 using System.Reflection; 11 using System.Reflection.Emit; 12 using NUnit.Framework; 13 14 namespace MonoTests.System.Reflection { 15 16 /// <summary> 17 /// Test Fixture for AssemblyInformationalVersionAttribute. 18 /// </summary> 19 [TestFixture] 20 public class AssemblyInformationalVersionAttributeTest { 21 22 #if !MOBILE 23 private AssemblyBuilder dynAssembly; 24 AssemblyName dynAsmName = new AssemblyName (); 25 AssemblyInformationalVersionAttribute attr; 26 AssemblyInformationalVersionAttributeTest()27 public AssemblyInformationalVersionAttributeTest () 28 { 29 //create a dynamic assembly with the required attribute 30 //and check for the validity 31 32 dynAsmName.Name = "TestAssembly"; 33 34 dynAssembly = Thread.GetDomain ().DefineDynamicAssembly ( 35 dynAsmName,AssemblyBuilderAccess.Run 36 ); 37 38 // Set the required Attribute of the assembly. 39 Type attribute = typeof (AssemblyInformationalVersionAttribute); 40 ConstructorInfo ctrInfo = attribute.GetConstructor ( 41 new Type [] { typeof (string) } 42 ); 43 CustomAttributeBuilder attrBuilder = 44 new CustomAttributeBuilder (ctrInfo, new object [1] { "2.0.0.0" }); 45 dynAssembly.SetCustomAttribute (attrBuilder); 46 object [] attributes = dynAssembly.GetCustomAttributes (true); 47 attr = attributes [0] as AssemblyInformationalVersionAttribute; 48 } 49 50 [Test] InformationalVersionTest()51 public void InformationalVersionTest () 52 { 53 Assert.AreEqual (attr.InformationalVersion, 54 "2.0.0.0", "#1"); 55 } 56 57 [Test] TypeIdTest()58 public void TypeIdTest () 59 { 60 Assert.AreEqual ( 61 attr.TypeId, 62 typeof (AssemblyInformationalVersionAttribute), "#1" 63 ); 64 65 } 66 67 [Test] MatchTestForTrue()68 public void MatchTestForTrue () 69 { 70 Assert.AreEqual ( 71 attr.Match (attr), 72 true, "#1"); 73 } 74 [Test] MatchTestForFalse()75 public void MatchTestForFalse () 76 { 77 78 Assert.AreEqual ( 79 attr.Match (new AssemblyInformationalVersionAttribute ("Descrptn")), 80 false, "#1"); 81 } 82 #endif 83 [Test] CtorTest()84 public void CtorTest () 85 { 86 var a = new AssemblyInformationalVersionAttribute ("1.2.3.4"); 87 Assert.AreEqual ("1.2.3.4", a.InformationalVersion); 88 } 89 } 90 } 91