AssemblyAlgorithmIdAttributeTest.cs 2.0 KB

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