1 // AssemblyAlgorithmIdAttributeTest.cs
3 // Author: Vineeth N <nvineeth@yahoo.com>
5 // (C) 2004 Ximian, Inc. http://www.ximian.com
8 using System
.Threading
;
9 using System
.Reflection
;
10 using System
.Reflection
.Emit
;
11 using System
.Configuration
.Assemblies
;
12 using NUnit
.Framework
;
14 namespace MonoTests
.System
.Reflection
{
17 /// Test Fixture for AssemblyAlgorithmIdAttribute class
20 public class AssemblyAlgorithmIdAttributeTest
: Assertion
22 private AssemblyBuilder dynAssembly
;
23 AssemblyName dynAsmName
= new AssemblyName ();
24 AssemblyAlgorithmIdAttribute attr
;
26 public AssemblyAlgorithmIdAttributeTest ()
28 //create a dynamic assembly with the required attribute
29 //and check for the validity
31 dynAsmName
.Name
= "TestAssembly";
33 dynAssembly
= Thread
.GetDomain ().DefineDynamicAssembly (
34 dynAsmName
,AssemblyBuilderAccess
.Run
37 // Set the required Attribute of the assembly.
38 Type attribute
= typeof (AssemblyAlgorithmIdAttribute
);
39 ConstructorInfo ctrInfo
= attribute
.GetConstructor (
40 new Type
[] { typeof (AssemblyHashAlgorithm) }
42 CustomAttributeBuilder attrBuilder
=
43 new CustomAttributeBuilder (
45 new object [1] { AssemblyHashAlgorithm.MD5 }
47 dynAssembly
.SetCustomAttribute (attrBuilder
);
48 object [] attributes
= dynAssembly
.GetCustomAttributes (true);
49 attr
= attributes
[0] as AssemblyAlgorithmIdAttribute
;
53 [CLSCompliant (false)] // because we are using uint
54 public void AlgorithmIdTest()
56 AssertEquals ("#Testing AlgorithmId",
58 (uint) AssemblyHashAlgorithm
.MD5
);
62 public void TypeIdTest ()
64 AssertEquals ("#testing Typeid",
66 typeof (AssemblyAlgorithmIdAttribute
)
72 public void MatchTestForTrue ()
74 AssertEquals ("#testing Match method-- for true",
79 public void MatchTestForFalse ()
81 AssertEquals ("#testing Match method-- for false",
82 attr
.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm
.SHA1
)),