2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / corlib / Test / System.Reflection / AssemblyCopyrightAttributeTest.cs
1 // AssemblyCopyrightAttributeTest.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 AssemblyCopyrightAttribute
18         /// </summary>
19         [TestFixture]
20         public class AssemblyCopyrightAttributeTest
21         {
22                 private AssemblyBuilder dynAssembly;
23                 AssemblyName dynAsmName = new AssemblyName ();
24                 AssemblyCopyrightAttribute attr;
25
26                 public AssemblyCopyrightAttributeTest ()
27                 {
28                         //create a dynamic assembly with the required attribute
29                         //and check for the validity
30
31                         dynAsmName.Name = "TestAssembly";
32
33                         dynAssembly = Thread.GetDomain().DefineDynamicAssembly (
34                                 dynAsmName,AssemblyBuilderAccess.Run
35                                 );
36
37                         // Set the required Attribute of the assembly.
38                         Type attribute = typeof (AssemblyCopyrightAttribute);
39                         ConstructorInfo ctrInfo = attribute.GetConstructor (
40                                 new Type []{ typeof (string) }
41                                 );
42                         CustomAttributeBuilder attrBuilder =
43                                 new CustomAttributeBuilder (ctrInfo, new object [1] {"Ximian"} );
44                         dynAssembly.SetCustomAttribute(attrBuilder);
45                         object [] attributes = dynAssembly.GetCustomAttributes (true);
46                         attr = attributes [0] as AssemblyCopyrightAttribute;
47                 }
48                 
49                 [Test]
50                 public void CopyrightTest ()
51                 {
52                         Assert.AreEqual (
53                                 attr.Copyright,
54                                 "Ximian", "#1");
55                 }
56
57                 [Test]
58                 public void TypeIdTest ()
59                 {
60                         Assert.AreEqual (
61                                 attr.TypeId,
62                                 typeof (AssemblyCopyrightAttribute)
63                                 , "#1");
64                 }
65
66                 [Test]
67                 public void MatchTestForTrue ()
68                 {
69                         Assert.AreEqual (
70                                 attr.Match (attr),
71                                 true, "#1");
72                 }
73
74                 [Test]
75                 public void MatchTestForFalse ()
76                 {       
77                         Assert.AreEqual (
78                                 attr.Match (new AssemblyCopyrightAttribute ("imian")),
79                                 false, "#1");
80                 }
81         }
82 }
83