CodeAttributeDeclarationTest.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // CodeAttributeDeclarationTest.cs
  3. // - Unit tests for System.CodeDom.CodeAttributeDeclaration
  4. //
  5. // Author:
  6. // Gert Driesen <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.CodeDom;
  32. namespace MonoTests.System.CodeDom
  33. {
  34. [TestFixture]
  35. public class CodeAttributeDeclarationTest
  36. {
  37. [Test]
  38. public void NullName ()
  39. {
  40. CodeAttributeDeclaration cad = new CodeAttributeDeclaration ((string) null);
  41. Assert.IsNotNull (cad.Name, "#1");
  42. Assert.AreEqual (string.Empty, cad.Name, "#2");
  43. #if NET_2_0
  44. Assert.IsNotNull (cad.AttributeType, "#3");
  45. Assert.AreEqual (typeof(void).FullName, cad.AttributeType.BaseType, "#4");
  46. #endif
  47. Assert.IsNotNull (cad.Arguments, "#5");
  48. Assert.AreEqual (0, cad.Arguments.Count, "#6");
  49. cad.Name = null;
  50. Assert.IsNotNull (cad.Name, "#7");
  51. Assert.AreEqual (string.Empty, cad.Name, "#8");
  52. #if NET_2_0
  53. Assert.IsNotNull (cad.AttributeType, "#9");
  54. Assert.AreEqual (typeof(void).FullName, cad.AttributeType.BaseType, "#10");
  55. #endif
  56. }
  57. [Test]
  58. public void Constructor0 ()
  59. {
  60. CodeAttributeDeclaration cad = new CodeAttributeDeclaration ();
  61. Assert.IsNotNull (cad.Name, "#1");
  62. Assert.AreEqual (string.Empty, cad.Name, "#2");
  63. #if NET_2_0
  64. Assert.IsNull (cad.AttributeType, "#3");
  65. #endif
  66. Assert.IsNotNull (cad.Arguments, "#4");
  67. Assert.AreEqual (0, cad.Arguments.Count, "#5");
  68. }
  69. [Test]
  70. public void Constructor1 ()
  71. {
  72. CodeAttributeDeclaration cad = new CodeAttributeDeclaration ("mono");
  73. Assert.AreEqual (0, cad.Arguments.Count, "#1");
  74. Assert.AreEqual ("mono", cad.Name, "#2");
  75. #if NET_2_0
  76. Assert.IsNotNull (cad.AttributeType, "#3");
  77. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#4");
  78. #endif
  79. }
  80. [Test]
  81. public void Constructor2 ()
  82. {
  83. CodeAttributeDeclaration cad = new CodeAttributeDeclaration ("mono", new CodeAttributeArgument ());
  84. Assert.AreEqual (1, cad.Arguments.Count, "#1");
  85. Assert.AreEqual ("mono", cad.Name, "#2");
  86. #if NET_2_0
  87. Assert.IsNotNull (cad.AttributeType, "#3");
  88. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#4");
  89. #endif
  90. cad.Name = null;
  91. Assert.AreEqual (1, cad.Arguments.Count, "#5");
  92. Assert.AreEqual (string.Empty, cad.Name, "#6");
  93. #if NET_2_0
  94. Assert.IsNotNull (cad.AttributeType, "#7");
  95. Assert.AreEqual (typeof(void).FullName, cad.AttributeType.BaseType, "#8");
  96. #endif
  97. }
  98. #if NET_2_0
  99. [Test]
  100. public void Constructor3 ()
  101. {
  102. CodeAttributeDeclaration cad = new CodeAttributeDeclaration (new CodeTypeReference ("mono"));
  103. Assert.AreEqual (0, cad.Arguments.Count, "#1");
  104. Assert.AreEqual ("mono", cad.Name, "#2");
  105. Assert.IsNotNull (cad.AttributeType, "#3");
  106. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#4");
  107. cad.Name = null;
  108. Assert.AreEqual (0, cad.Arguments.Count, "#5");
  109. Assert.AreEqual (string.Empty, cad.Name, "#6");
  110. Assert.AreEqual (typeof(void).FullName, cad.AttributeType.BaseType, "#7");
  111. cad.Name = "mono";
  112. Assert.AreEqual (0, cad.Arguments.Count, "#8");
  113. Assert.AreEqual ("mono", cad.Name, "#9");
  114. Assert.IsNotNull (cad.AttributeType, "#10");
  115. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#11");
  116. cad = new CodeAttributeDeclaration ((CodeTypeReference) null);
  117. Assert.AreEqual (0, cad.Arguments.Count, "#12");
  118. Assert.AreEqual (string.Empty, cad.Name, "#13");
  119. Assert.IsNull (cad.AttributeType, "#14");
  120. }
  121. [Test]
  122. public void Constructor4 ()
  123. {
  124. CodeAttributeDeclaration cad = new CodeAttributeDeclaration (new CodeTypeReference ("mono"),
  125. new CodeAttributeArgument (), new CodeAttributeArgument ());
  126. Assert.AreEqual (2, cad.Arguments.Count, "#1");
  127. Assert.AreEqual ("mono", cad.Name, "#2");
  128. Assert.IsNotNull (cad.AttributeType, "#3");
  129. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#4");
  130. cad.Name = null;
  131. Assert.AreEqual (2, cad.Arguments.Count, "#5");
  132. Assert.AreEqual (string.Empty, cad.Name, "#6");
  133. Assert.AreEqual (typeof(void).FullName, cad.AttributeType.BaseType, "#7");
  134. cad.Name = "mono";
  135. Assert.AreEqual (2, cad.Arguments.Count, "#8");
  136. Assert.AreEqual ("mono", cad.Name, "#9");
  137. Assert.IsNotNull (cad.AttributeType, "#10");
  138. Assert.AreEqual ("mono", cad.AttributeType.BaseType, "#11");
  139. cad = new CodeAttributeDeclaration ((CodeTypeReference) null,
  140. new CodeAttributeArgument ());
  141. Assert.AreEqual (1, cad.Arguments.Count, "#12");
  142. Assert.AreEqual (string.Empty, cad.Name, "#13");
  143. Assert.IsNull (cad.AttributeType, "#14");
  144. }
  145. #endif
  146. }
  147. }