[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeCastExpressionTest.cs
1 //
2 // CodeCastExpressionTest.cs
3 //      - Unit tests for System.CodeDom.CodeCastExpression
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
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
30 using NUnit.Framework;
31
32 using System;
33 using System.CodeDom;
34
35 namespace MonoTests.System.CodeDom
36 {
37         [TestFixture]
38         public class CodeCastExpressionTest
39         {
40                 [Test]
41                 public void Constructor0 ()
42                 {
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");
47
48                         CodeExpression expression = new CodeExpression ();
49                         cce.Expression = expression;
50                         Assert.IsNotNull (cce.Expression, "#4");
51                         Assert.AreSame (expression, cce.Expression, "#5");
52
53                         cce.Expression = null;
54                         Assert.IsNull (cce.Expression, "#6");
55
56                         CodeTypeReference type = new CodeTypeReference ("mono");
57                         cce.TargetType = type;
58                         Assert.IsNotNull (cce.TargetType, "#7");
59                         Assert.AreSame (type, cce.TargetType, "#8");
60
61                         cce.TargetType = null;
62                         Assert.IsNotNull (cce.TargetType, "#9");
63                         Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#10");
64                 }
65
66                 [Test]
67                 public void Constructor1 ()
68                 {
69                         CodeTypeReference type1 = new CodeTypeReference ("mono1");
70                         CodeExpression expression1 = new CodeExpression ();
71
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");
77
78                         cce.Expression = null;
79                         Assert.IsNull (cce.Expression, "#5");
80
81                         CodeExpression expression2 = new CodeExpression ();
82                         cce.Expression = expression2;
83                         Assert.IsNotNull (cce.Expression, "#6");
84                         Assert.AreSame (expression2, cce.Expression, "#7");
85
86                         cce.TargetType = null;
87                         Assert.IsNotNull (cce.TargetType, "#8");
88                         Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#9");
89
90                         CodeTypeReference type2 = new CodeTypeReference ("mono2");
91                         cce.TargetType = type2;
92                         Assert.IsNotNull (cce.TargetType, "#10");
93                         Assert.AreSame (type2, cce.TargetType, "#11");
94
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");
99                 }
100
101                 [Test]
102                 public void Constructor2 ()
103                 {
104                         string baseType = "mono";
105                         CodeExpression expression = new CodeExpression ();
106
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");
112
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");
118                 }
119
120                 [Test]
121                 public void Constructor3 ()
122                 {
123                         Type type = typeof (int);
124                         CodeExpression expression = new CodeExpression ();
125
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");
131
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");
136                 }
137
138                 [Test]
139                 [ExpectedException (typeof (ArgumentNullException))]
140                 public void Constructor3_NullType ()
141                 {
142                         CodeCastExpression cce = new CodeCastExpression ((Type) null,
143                                 new CodeExpression ());
144                 }
145         }
146 }