2 // CodeCastExpressionTest.cs
3 // - Unit tests for System.CodeDom.CodeCastExpression
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 CodeCastExpressionTest
41 public void Constructor0 ()
43 CodeCastExpression cce = new CodeCastExpression ();
44 Assert.IsNull (cce.Expression, "#1");
45 Assert.IsNotNull (cce.TargetType, "#2");
46 Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#3");
48 CodeExpression expression = new CodeExpression ();
49 cce.Expression = expression;
50 Assert.IsNotNull (cce.Expression, "#4");
51 Assert.AreSame (expression, cce.Expression, "#5");
53 cce.Expression = null;
54 Assert.IsNull (cce.Expression, "#6");
56 CodeTypeReference type = new CodeTypeReference ("mono");
57 cce.TargetType = type;
58 Assert.IsNotNull (cce.TargetType, "#7");
59 Assert.AreSame (type, cce.TargetType, "#8");
61 cce.TargetType = null;
62 Assert.IsNotNull (cce.TargetType, "#9");
63 Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#10");
67 public void Constructor1 ()
69 CodeTypeReference type1 = new CodeTypeReference ("mono1");
70 CodeExpression expression1 = new CodeExpression ();
72 CodeCastExpression cce = new CodeCastExpression (type1, expression1);
73 Assert.IsNotNull (cce.Expression, "#1");
74 Assert.AreSame (expression1, cce.Expression, "#2");
75 Assert.IsNotNull (cce.TargetType, "#3");
76 Assert.AreSame (type1, cce.TargetType, "#4");
78 cce.Expression = null;
79 Assert.IsNull (cce.Expression, "#5");
81 CodeExpression expression2 = new CodeExpression ();
82 cce.Expression = expression2;
83 Assert.IsNotNull (cce.Expression, "#6");
84 Assert.AreSame (expression2, cce.Expression, "#7");
86 cce.TargetType = null;
87 Assert.IsNotNull (cce.TargetType, "#8");
88 Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#9");
90 CodeTypeReference type2 = new CodeTypeReference ("mono2");
91 cce.TargetType = type2;
92 Assert.IsNotNull (cce.TargetType, "#10");
93 Assert.AreSame (type2, cce.TargetType, "#11");
95 cce = new CodeCastExpression ((CodeTypeReference) null, (CodeExpression) null);
96 Assert.IsNull (cce.Expression, "#12");
97 Assert.IsNotNull (cce.TargetType, "#13");
98 Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#14");
102 public void Constructor2 ()
104 string baseType = "mono";
105 CodeExpression expression = new CodeExpression ();
107 CodeCastExpression cce = new CodeCastExpression (baseType, expression);
108 Assert.IsNotNull (cce.Expression, "#1");
109 Assert.AreSame (expression, cce.Expression, "#2");
110 Assert.IsNotNull (cce.TargetType, "#3");
111 Assert.AreEqual (baseType, cce.TargetType.BaseType, "#4");
113 cce = new CodeCastExpression ((string) null, expression);
114 Assert.IsNotNull (cce.Expression, "#5");
115 Assert.AreSame (expression, cce.Expression, "#6");
116 Assert.IsNotNull (cce.TargetType, "#7");
117 Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#8");
121 public void Constructor3 ()
123 Type type = typeof (int);
124 CodeExpression expression = new CodeExpression ();
126 CodeCastExpression cce = new CodeCastExpression (type, expression);
127 Assert.IsNotNull (cce.Expression, "#1");
128 Assert.AreSame (expression, cce.Expression, "#2");
129 Assert.IsNotNull (cce.TargetType, "#3");
130 Assert.AreEqual (type.FullName, cce.TargetType.BaseType, "#4");
132 cce = new CodeCastExpression (type, (CodeExpression) null);
133 Assert.IsNull (cce.Expression, "#5");
134 Assert.IsNotNull (cce.TargetType, "#6");
135 Assert.AreEqual (type.FullName, cce.TargetType.BaseType, "#7");
139 [ExpectedException (typeof (ArgumentNullException))]
140 public void Constructor3_NullType ()
142 CodeCastExpression cce = new CodeCastExpression ((Type) null,
143 new CodeExpression ());