**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.Reflection / AssemblyAlgorithmIdAttributeTest.cs
blobc7e91af28f09f9c51970437a004ff472a3bf6d6f
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;
14 namespace MonoTests.System.Reflection {
16 /// <summary>
17 /// Test Fixture for AssemblyAlgorithmIdAttribute class
18 /// </summary>
19 [TestFixture]
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 (
44 ctrInfo,
45 new object [1] { AssemblyHashAlgorithm.MD5 }
47 dynAssembly.SetCustomAttribute (attrBuilder);
48 object [] attributes = dynAssembly.GetCustomAttributes (true);
49 attr = attributes [0] as AssemblyAlgorithmIdAttribute;
52 [Test]
53 [CLSCompliant (false)] // because we are using uint
54 public void AlgorithmIdTest()
56 AssertEquals ("#Testing AlgorithmId",
57 attr.AlgorithmId,
58 (uint) AssemblyHashAlgorithm.MD5);
61 [Test]
62 public void TypeIdTest ()
64 AssertEquals ("#testing Typeid",
65 attr.TypeId,
66 typeof (AssemblyAlgorithmIdAttribute)
71 [Test]
72 public void MatchTestForTrue ()
74 AssertEquals ("#testing Match method-- for true",
75 attr.Match (attr),
76 true);
78 [Test]
79 public void MatchTestForFalse ()
81 AssertEquals ("#testing Match method-- for false",
82 attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),
83 false);