AssemblyAlgorithmIdAttributeTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // AssemblyAlgorithmIdAttributeTest.cs
  2. //
  3. // Author: Vineeth N <[email protected]>
  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;
  13. namespace MonoTests.System.Reflection {
  14. /// <summary>
  15. /// Test Fixture for AssemblyAlgorithmIdAttribute class
  16. /// </summary>
  17. [TestFixture]
  18. public class AssemblyAlgorithmIdAttributeTest : Assertion
  19. {
  20. private AssemblyBuilder dynAssembly;
  21. AssemblyName dynAsmName = new AssemblyName ();
  22. AssemblyAlgorithmIdAttribute attr;
  23. public AssemblyAlgorithmIdAttributeTest ()
  24. {
  25. //create a dynamic assembly with the required attribute
  26. //and check for the validity
  27. dynAsmName.Name = "TestAssembly";
  28. dynAssembly = Thread.GetDomain ().DefineDynamicAssembly (
  29. dynAsmName,AssemblyBuilderAccess.Run
  30. );
  31. // Set the required Attribute of the assembly.
  32. Type attribute = typeof (AssemblyAlgorithmIdAttribute);
  33. ConstructorInfo ctrInfo = attribute.GetConstructor (
  34. new Type [] { typeof (AssemblyHashAlgorithm) }
  35. );
  36. CustomAttributeBuilder attrBuilder =
  37. new CustomAttributeBuilder (
  38. ctrInfo,
  39. new object [1] { AssemblyHashAlgorithm.MD5 }
  40. );
  41. dynAssembly.SetCustomAttribute (attrBuilder);
  42. object [] attributes = dynAssembly.GetCustomAttributes (true);
  43. attr = attributes [0] as AssemblyAlgorithmIdAttribute;
  44. }
  45. [Test]
  46. public void AlgorithmIdTest()
  47. {
  48. AssertEquals ("#Testing AlgorithmId",
  49. attr.AlgorithmId,
  50. (uint) AssemblyHashAlgorithm.MD5);
  51. }
  52. [Test]
  53. public void TypeIdTest ()
  54. {
  55. AssertEquals ("#testing Typeid",
  56. attr.TypeId,
  57. typeof (AssemblyAlgorithmIdAttribute)
  58. );
  59. }
  60. [Test]
  61. public void MatchTestForTrue ()
  62. {
  63. AssertEquals ("#testing Match method-- for true",
  64. attr.Match (attr),
  65. true);
  66. }
  67. [Test]
  68. public void MatchTestForFalse ()
  69. {
  70. AssertEquals ("#testing Match method-- for false",
  71. attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),
  72. false);
  73. }
  74. }
  75. }