2 // CodeObjectCreateExpressionTest.cs
3 // - Unit tests for System.CodeDom.CodeObjectCreateExpression
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
35 namespace MonoTests.System.CodeDom
38 public class CodeObjectCreateExpressionTest
41 public void Constructor0 ()
43 CodeObjectCreateExpression coce = new CodeObjectCreateExpression ();
45 Assert.IsNotNull (coce.CreateType, "#1");
46 Assert.AreEqual (typeof (void).FullName, coce.CreateType.BaseType, "#2");
47 Assert.IsNotNull (coce.Parameters, "#3");
48 Assert.AreEqual (0, coce.Parameters.Count, "#4");
50 CodeTypeReference type = new CodeTypeReference ("mono");
51 coce.CreateType = type;
52 Assert.IsNotNull (coce.CreateType, "#8");
53 Assert.AreSame (type, coce.CreateType, "#9");
55 coce.CreateType = null;
56 Assert.IsNotNull (coce.CreateType, "#10");
57 Assert.AreEqual (typeof (void).FullName, coce.CreateType.BaseType, "#11");
61 public void Constructor1 ()
63 CodeTypeReference type = new CodeTypeReference ("mono");
64 CodeExpression expression1 = new CodeExpression ();
65 CodeExpression expression2 = new CodeExpression ();
67 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
68 type, expression1, expression2);
69 Assert.IsNotNull (coce.CreateType, "#1");
70 Assert.AreSame (type, coce.CreateType, "#2");
71 Assert.IsNotNull (coce.Parameters, "#3");
72 Assert.AreEqual (2, coce.Parameters.Count, "#4");
73 Assert.AreEqual (0, coce.Parameters.IndexOf(expression1), "#5");
74 Assert.AreEqual (1, coce.Parameters.IndexOf(expression2), "#6");
76 coce = new CodeObjectCreateExpression ((CodeTypeReference) null,
78 Assert.IsNotNull (coce.CreateType, "#7");
79 Assert.AreEqual (typeof (void).FullName, coce.CreateType.BaseType, "#8");
80 Assert.IsNotNull (coce.Parameters, "#9");
81 Assert.AreEqual (1, coce.Parameters.Count, "#10");
82 Assert.AreEqual (0, coce.Parameters.IndexOf(expression1), "#11");
86 [ExpectedException (typeof (ArgumentNullException))]
87 public void Constructor1_NullParameter ()
89 CodeTypeReference type = new CodeTypeReference ("mono");
90 CodeExpression expression1 = new CodeExpression ();
92 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
93 type, expression1, (CodeExpression) null);
97 public void Constructor2 ()
99 string baseType = "mono";
100 CodeExpression expression1 = new CodeExpression ();
101 CodeExpression expression2 = new CodeExpression ();
103 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
104 baseType, expression1, expression2);
105 Assert.IsNotNull (coce.CreateType, "#1");
106 Assert.AreSame (baseType, coce.CreateType.BaseType, "#2");
107 Assert.IsNotNull (coce.Parameters, "#3");
108 Assert.AreEqual (2, coce.Parameters.Count, "#4");
109 Assert.AreEqual (0, coce.Parameters.IndexOf(expression1), "#5");
110 Assert.AreEqual (1, coce.Parameters.IndexOf(expression2), "#6");
112 coce = new CodeObjectCreateExpression ((string) null, expression2);
113 Assert.IsNotNull (coce.CreateType, "#7");
114 Assert.AreEqual (typeof (void).FullName, coce.CreateType.BaseType, "#8");
115 Assert.IsNotNull (coce.Parameters, "#9");
116 Assert.AreEqual (1, coce.Parameters.Count, "#10");
117 Assert.AreEqual (0, coce.Parameters.IndexOf(expression2), "#11");
121 [ExpectedException (typeof (ArgumentNullException))]
122 public void Constructor2_NullParameter ()
124 string baseType = "mono";
125 CodeExpression expression1 = new CodeExpression ();
127 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
128 baseType, expression1, (CodeExpression) null);
132 public void Constructor3 ()
134 Type baseType = typeof (int);
135 CodeExpression expression1 = new CodeExpression ();
136 CodeExpression expression2 = new CodeExpression ();
137 CodeExpression expression3 = new CodeExpression ();
139 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
140 baseType, expression1, expression2, expression3);
141 Assert.IsNotNull (coce.CreateType, "#1");
142 Assert.AreEqual (baseType.FullName, coce.CreateType.BaseType, "#2");
143 Assert.IsNotNull (coce.Parameters, "#3");
144 Assert.AreEqual (3, coce.Parameters.Count, "#4");
145 Assert.AreEqual (0, coce.Parameters.IndexOf(expression1), "#5");
146 Assert.AreEqual (1, coce.Parameters.IndexOf(expression2), "#6");
147 Assert.AreEqual (2, coce.Parameters.IndexOf(expression3), "#7");
151 [ExpectedException (typeof (ArgumentNullException))]
152 public void Constructor3_NullType ()
154 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
155 (Type) null, new CodeExpression ());
159 [ExpectedException (typeof (ArgumentNullException))]
160 public void Constructor3_NullParameter ()
162 Type baseType = typeof (int);
163 CodeExpression expression1 = new CodeExpression ();
165 CodeObjectCreateExpression coce = new CodeObjectCreateExpression (
166 baseType, expression1, (CodeExpression) null);