AssemblyConfigurationAttributeTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // AssemblyConfigurationAttributeTest.cs
  2. //
  3. // Author: Vineeth N <[email protected]>
  4. //
  5. // (C) 2004 Ximian, Inc. http://www.ximian.com
  6. //
  7. #if !MOBILE
  8. using System;
  9. using System.Threading;
  10. using System.Reflection;
  11. using System.Reflection.Emit;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Reflection {
  14. /// <summary>
  15. /// Test Fixture for AssemblyConfigurationAttribute class
  16. /// </summary>
  17. [TestFixture]
  18. public class AssemblyConfigurationAttributeTest
  19. {
  20. private AssemblyBuilder dynAssembly;
  21. AssemblyName dynAsmName = new AssemblyName ();
  22. AssemblyConfigurationAttribute attr;
  23. public AssemblyConfigurationAttributeTest ()
  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 (AssemblyConfigurationAttribute);
  33. ConstructorInfo ctrInfo = attribute.GetConstructor (
  34. new Type [] { typeof (string) }
  35. );
  36. CustomAttributeBuilder attrBuilder =
  37. new CustomAttributeBuilder (ctrInfo, new object [1] { "Config" } );
  38. dynAssembly.SetCustomAttribute (attrBuilder);
  39. object [] attributes = dynAssembly.GetCustomAttributes (true);
  40. attr = attributes [0] as AssemblyConfigurationAttribute;
  41. }
  42. [Test]
  43. public void ConfigurationTest ()
  44. {
  45. Assert.AreEqual (
  46. attr.Configuration,
  47. "Config", "#1");
  48. }
  49. [Test]
  50. public void TypeIdTest ()
  51. {
  52. Assert.AreEqual (
  53. attr.TypeId,
  54. typeof (AssemblyConfigurationAttribute)
  55. , "#1");
  56. }
  57. [Test]
  58. public void MatchTestForTrue ()
  59. {
  60. Assert.AreEqual (
  61. attr.Match (attr),
  62. true, "#1");
  63. }
  64. [Test]
  65. public void MatchTestForFalse ()
  66. {
  67. Assert.AreEqual (
  68. attr.Match (new AssemblyConfigurationAttribute ("abcd")),
  69. false, "#1");
  70. }
  71. }
  72. }
  73. #endif