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