AssemblyAlgorithmIdAttributeTest.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. [CLSCompliant (false)] // because we are using uint
  47. public void AlgorithmIdTest()
  48. {
  49. AssertEquals ("#Testing AlgorithmId",
  50. attr.AlgorithmId,
  51. (uint) AssemblyHashAlgorithm.MD5);
  52. }
  53. [Test]
  54. public void TypeIdTest ()
  55. {
  56. AssertEquals ("#testing Typeid",
  57. attr.TypeId,
  58. typeof (AssemblyAlgorithmIdAttribute)
  59. );
  60. }
  61. [Test]
  62. public void MatchTestForTrue ()
  63. {
  64. AssertEquals ("#testing Match method-- for true",
  65. attr.Match (attr),
  66. true);
  67. }
  68. [Test]
  69. public void MatchTestForFalse ()
  70. {
  71. AssertEquals ("#testing Match method-- for false",
  72. attr.Match (new AssemblyAlgorithmIdAttribute (AssemblyHashAlgorithm.SHA1)),
  73. false);
  74. }
  75. }
  76. }