Merge pull request #1909 from esdrubal/reflection
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / InvalidProjectFileExceptionTest.cs
1 //
2 // InvalidProjectFileExceptionTest.cs:
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 // 
7 // (C) 2005 Marek Sieradzki
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 using System;
29 using System.IO;
30 using System.Reflection;
31 using System.Runtime.Serialization;
32 using System.Xml;
33 using Microsoft.Build.BuildEngine;
34 using NUnit.Framework;
35
36 namespace MonoTests.Microsoft.Build.BuildEngine {
37         [TestFixture]
38         public class InvalidProjectFileExceptionTest {
39                 [Test]
40                 public void TestCtorMessage ()
41                 {
42                         InvalidProjectFileException ipfe;
43                         string message = "message";
44                         
45                         ipfe = new InvalidProjectFileException (message);
46                         
47                         Assert.AreEqual (message, ipfe.Message, "Message");
48                 }
49                 
50                 [Test]
51                 public void TestCtorProjectFile ()
52                 {
53                         InvalidProjectFileException ipfe;
54                         string projectFile = "projectFile";
55                         int lineNumber = 1;
56                         int columnNumber = 2;
57                         int endLineNumber = 3;
58                         int endColumnNumber = 4;
59                         string message = "message";
60                         string errorSubcategory = "errorSubcategory";
61                         string errorCode = "CS0000";
62                         string helpKeyword = "helpKeyword";
63                         
64                         ipfe = new InvalidProjectFileException (projectFile, lineNumber, columnNumber, endLineNumber, endColumnNumber,
65                                 message, errorSubcategory, errorCode, helpKeyword);
66                         
67                         Assert.AreEqual (projectFile, ipfe.ProjectFile, "A1");
68                         Assert.AreEqual (lineNumber, ipfe.LineNumber, "A2");
69                         Assert.AreEqual (columnNumber, ipfe.ColumnNumber, "A3");
70                         Assert.AreEqual (endLineNumber, ipfe.EndLineNumber, "A4");
71                         Assert.AreEqual (endColumnNumber, ipfe.EndColumnNumber, "A5");
72                         Assert.AreEqual (message, ipfe.BaseMessage, "A6");
73                         Assert.AreEqual (message + "  " + projectFile, ipfe.Message, "A7");
74                         Assert.AreEqual (errorSubcategory, ipfe.ErrorSubcategory, "A8");
75                         Assert.AreEqual (errorCode, ipfe.ErrorCode, "A9");
76                         Assert.AreEqual (helpKeyword, ipfe.HelpKeyword, "A10");
77                 }
78                 
79                 [Test]
80                 public void TestCtorMessageException ()
81                 {
82                         string message = "message";
83                         Exception e = new Exception ("Exception message");
84                         
85                         new InvalidProjectFileException (message, e);
86                 }
87                 
88                 [Test]
89                 public void TestCtorNode ()
90                 {
91                         // FIXME: we need to load xml file to load something with non-empty XmlElement.BaseUri
92                         /*
93                         XmlDocument xd = new XmlDocument ();
94                         
95                         InvalidProjectFileException ipfe;
96
97                         string message = "message";
98                         string errorSubcategory = "errorSubcategory";
99                         string errorCode = "CS0000";
100                         string helpKeyword = "helpKeyword";
101                         
102                         ipfe = new InvalidProjectFileException (null, message, errorSubcategory, errorCode, helpKeyword);
103                         
104                         Assert.AreEqual (message, ipfe.BaseMessage, "A1");
105                         Assert.AreEqual (errorSubcategory, ipfe.ErrorSubcategory, "A2");
106                         Assert.AreEqual (errorCode, ipfe.ErrorCode, "A3");
107                         Assert.AreEqual (helpKeyword, ipfe.HelpKeyword, "A4");
108                         */
109                 }
110
111                 [Test]
112                 [ExpectedException (typeof (ArgumentNullException))]
113                 public void TestGetObjectData1 ()
114                 {
115                         InvalidProjectFileException ipfe = new InvalidProjectFileException ();
116                         ipfe.GetObjectData (null, new StreamingContext ());
117                 }
118
119                 [Test]
120                 public void TestGetObjectData2 ()
121                 {
122                         StreamingContext sc = new StreamingContext ();
123                         SerializationInfo si = new SerializationInfo (typeof (InvalidProjectFileException), new FormatterConverter ());
124                         InvalidProjectFileException ipfe;
125                         string projectFile = "projectFile";
126                         int lineNumber = 1;
127                         int columnNumber = 2;
128                         int endLineNumber = 3;
129                         int endColumnNumber = 4;
130                         string message = "message";
131                         string errorSubcategory = "errorSubcategory";
132                         string errorCode = "CS0000";
133                         string helpKeyword = "helpKeyword";
134
135                         ipfe = new InvalidProjectFileException (projectFile, lineNumber, columnNumber, endLineNumber, endColumnNumber,
136                                 message, errorSubcategory, errorCode, helpKeyword);
137                         ipfe.GetObjectData (si, sc);
138
139                         Assert.AreEqual (projectFile, si.GetString ("projectFile"), "A1");
140                         Assert.AreEqual (lineNumber, si.GetInt32 ("lineNumber"), "A2");
141                         Assert.AreEqual (columnNumber, si.GetInt32 ("columnNumber"), "A3");
142                         Assert.AreEqual (endLineNumber, si.GetInt32 ("endLineNumber"), "A4");
143                         Assert.AreEqual (endColumnNumber, si.GetInt32 ("endColumnNumber"), "A5");
144                         Assert.AreEqual (message, si.GetString ("Message"), "A6");
145                         Assert.AreEqual (errorSubcategory, si.GetString ("errorSubcategory"), "A7");
146                         Assert.AreEqual (errorCode, si.GetString ("errorCode"), "A8");
147                         Assert.AreEqual (helpKeyword, si.GetString ("helpKeyword"), "A9");
148                 }
149         }
150 }