2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / corlib / Test / System.Reflection / AssemblyAlgorithmIdAttributeTest.cs
1 // AssemblyAlgorithmIdAttributeTest.cs
2 //
3 // Author: Vineeth N <nvineeth@yahoo.com>
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 System.Configuration.Assemblies;
12 using NUnit.Framework;
13
14 namespace MonoTests.System.Reflection {
15
16         /// <summary>
17         /// Test Fixture for AssemblyAlgorithmIdAttribute class
18         /// </summary>
19         [TestFixture]
20         public class AssemblyAlgorithmIdAttributeTest : Assertion
21         {
22                 private AssemblyBuilder dynAssembly;
23                 AssemblyName dynAsmName = new AssemblyName ();
24                 AssemblyAlgorithmIdAttribute attr;
25
26                 public AssemblyAlgorithmIdAttributeTest ()
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 (AssemblyAlgorithmIdAttribute);
39                         ConstructorInfo ctrInfo = attribute.GetConstructor (
40                                 new Type [] { typeof (AssemblyHashAlgorithm) }
41                                 );
42                         CustomAttributeBuilder attrBuilder =
43                                 new CustomAttributeBuilder (
44                                 ctrInfo,
45                                 new object [1] { AssemblyHashAlgorithm.MD5 }
46                                 );
47                         dynAssembly.SetCustomAttribute (attrBuilder);
48                         object [] attributes = dynAssembly.GetCustomAttributes (true);
49                         attr = attributes [0] as AssemblyAlgorithmIdAttribute;
50                 }
51                 
52                 [Test]
53                 public void AlgorithmIdTest()
54                 {
55                         AssertEquals ("#Testing AlgorithmId",
56                                 attr.AlgorithmId,
57                                 (uint) AssemblyHashAlgorithm.MD5);
58                 }
59
60                 [Test]
61                 public void TypeIdTest ()
62                 {
63                         AssertEquals ("#testing Typeid",
64                                 attr.TypeId,
65                                 typeof (AssemblyAlgorithmIdAttribute)
66                                 );
67
68                 }
69
70                 [Test]
71                 public void MatchTestForTrue ()
72                 {
73                         AssertEquals ("#testing Match method-- for true",
74                                 attr.Match (attr),
75                                 true);
76                 }
77                 [Test]
78                 public void MatchTestForFalse ()
79                 {                       
80                         AssertEquals ("#testing Match method-- for false",
81                                 attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),
82                                 false);
83                 }
84         }
85 }
86