AssemblyConfigurationAttributeTest.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // AssemblyConfigurationAttributeTest.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 NUnit.Framework;
  12. namespace MonoTests.System.Reflection {
  13. /// <summary>
  14. /// Test Fixture for AssemblyConfigurationAttribute class
  15. /// </summary>
  16. [TestFixture]
  17. public class AssemblyConfigurationAttributeTest
  18. {
  19. #if !MOBILE
  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. #endif
  72. [Test]
  73. public void CtorTest ()
  74. {
  75. var a = new AssemblyConfigurationAttribute ("abcd");
  76. Assert.AreEqual ("abcd", a.Configuration);
  77. }
  78. }
  79. }