In tests/attributes:
[mono.git] / mcs / class / corlib / Test / System.Reflection / AssemblyAlgorithmIdAttributeTest.cs
1 // AssemblyAlgorithmIdAttributeTest.cs\r
2 //\r
3 // Author: Vineeth N <nvineeth@yahoo.com>\r
4 //\r
5 // (C) 2004 Ximian, Inc. http://www.ximian.com\r
6 //\r
7 using System;\r
8 using System.Threading;\r
9 using System.Reflection;\r
10 using System.Reflection.Emit;\r
11 using System.Configuration.Assemblies;\r
12 using NUnit.Framework;\r
13 \r
14 namespace MonoTests.System.Reflection {\r
15 \r
16         /// <summary>\r
17         /// Test Fixture for AssemblyAlgorithmIdAttribute class\r
18         /// </summary>\r
19         [TestFixture]\r
20         public class AssemblyAlgorithmIdAttributeTest : Assertion\r
21         {\r
22                 private AssemblyBuilder dynAssembly;\r
23                 AssemblyName dynAsmName = new AssemblyName ();\r
24                 AssemblyAlgorithmIdAttribute attr;\r
25 \r
26                 public AssemblyAlgorithmIdAttributeTest ()\r
27                 {\r
28                         //create a dynamic assembly with the required attribute\r
29                         //and check for the validity\r
30 \r
31                         dynAsmName.Name = "TestAssembly";\r
32 \r
33                         dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (\r
34                                 dynAsmName,AssemblyBuilderAccess.Run\r
35                                 );\r
36 \r
37                         // Set the required Attribute of the assembly.\r
38                         Type attribute = typeof (AssemblyAlgorithmIdAttribute);\r
39                         ConstructorInfo ctrInfo = attribute.GetConstructor (\r
40                                 new Type [] { typeof (AssemblyHashAlgorithm) }\r
41                                 );\r
42                         CustomAttributeBuilder attrBuilder =\r
43                                 new CustomAttributeBuilder (\r
44                                 ctrInfo,\r
45                                 new object [1] { AssemblyHashAlgorithm.MD5 }\r
46                                 );\r
47                         dynAssembly.SetCustomAttribute (attrBuilder);\r
48                         object [] attributes = dynAssembly.GetCustomAttributes (true);\r
49                         attr = attributes [0] as AssemblyAlgorithmIdAttribute;\r
50                 }\r
51                 \r
52                 [Test]\r
53                 public void AlgorithmIdTest()\r
54                 {\r
55                         AssertEquals ("#Testing AlgorithmId",\r
56                                 attr.AlgorithmId,\r
57                                 (uint) AssemblyHashAlgorithm.MD5);\r
58                 }\r
59 \r
60                 [Test]\r
61                 public void TypeIdTest ()\r
62                 {\r
63                         AssertEquals ("#testing Typeid",\r
64                                 attr.TypeId,\r
65                                 typeof (AssemblyAlgorithmIdAttribute)\r
66                                 );\r
67 \r
68                 }\r
69 \r
70                 [Test]\r
71                 public void MatchTestForTrue ()\r
72                 {\r
73                         AssertEquals ("#testing Match method-- for true",\r
74                                 attr.Match (attr),\r
75                                 true);\r
76                 }\r
77                 [Test]\r
78                 public void MatchTestForFalse ()\r
79                 {                       \r
80                         AssertEquals ("#testing Match method-- for false",\r
81                                 attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),\r
82                                 false);\r
83                 }\r
84         }\r
85 }\r
86 \r