1 // AssemblyAlgorithmIdAttributeTest.cs
3 // Author: Vineeth N <nvineeth@yahoo.com>
5 // (C) 2004 Ximian, Inc. http://www.ximian.com
9 using System
.Threading
;
10 using System
.Reflection
;
11 using System
.Reflection
.Emit
;
12 using System
.Configuration
.Assemblies
;
13 using NUnit
.Framework
;
15 namespace MonoTests
.System
.Reflection
{
18 /// Test Fixture for AssemblyAlgorithmIdAttribute class
21 public class AssemblyAlgorithmIdAttributeTest
24 private AssemblyBuilder dynAssembly
;
25 AssemblyName dynAsmName
= new AssemblyName ();
26 AssemblyAlgorithmIdAttribute attr
;
28 public AssemblyAlgorithmIdAttributeTest ()
30 //create a dynamic assembly with the required attribute
31 //and check for the validity
33 dynAsmName
.Name
= "TestAssembly";
35 dynAssembly
= Thread
.GetDomain ().DefineDynamicAssembly (
36 dynAsmName
,AssemblyBuilderAccess
.Run
39 // Set the required Attribute of the assembly.
40 Type attribute
= typeof (AssemblyAlgorithmIdAttribute
);
41 ConstructorInfo ctrInfo
= attribute
.GetConstructor (
42 new Type
[] { typeof (AssemblyHashAlgorithm) }
44 CustomAttributeBuilder attrBuilder
=
45 new CustomAttributeBuilder (
47 new object [1] { AssemblyHashAlgorithm.MD5 }
49 dynAssembly
.SetCustomAttribute (attrBuilder
);
50 object [] attributes
= dynAssembly
.GetCustomAttributes (true);
51 attr
= attributes
[0] as AssemblyAlgorithmIdAttribute
;
55 public void AlgorithmIdTest()
59 (uint) AssemblyHashAlgorithm
.MD5
, "#1");
63 public void TypeIdTest ()
67 typeof (AssemblyAlgorithmIdAttribute
), "#1"
73 public void MatchTestForTrue ()
80 public void MatchTestForFalse ()
83 attr
.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm
.SHA1
)),
89 public void CtorTest ()
91 var a
= new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm
.SHA256
);
92 Assert
.AreEqual ((uint)AssemblyHashAlgorithm
.SHA256
, a
.AlgorithmId
);