2 // InvalidProjectFileExceptionTest.cs:
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System.Reflection;
31 using System.Runtime.Serialization;
33 using Microsoft.Build.BuildEngine;
34 using NUnit.Framework;
36 namespace MonoTests.Microsoft.Build.BuildEngine {
38 public class InvalidProjectFileExceptionTest {
40 public void TestCtorMessage ()
42 InvalidProjectFileException ipfe;
43 string message = "message";
45 ipfe = new InvalidProjectFileException (message);
47 Assert.AreEqual (message, ipfe.Message, "Message");
51 public void TestCtorProjectFile ()
53 InvalidProjectFileException ipfe;
54 string projectFile = "projectFile";
57 int endLineNumber = 3;
58 int endColumnNumber = 4;
59 string message = "message";
60 string errorSubcategory = "errorSubcategory";
61 string errorCode = "CS0000";
62 string helpKeyword = "helpKeyword";
64 ipfe = new InvalidProjectFileException (projectFile, lineNumber, columnNumber, endLineNumber, endColumnNumber,
65 message, errorSubcategory, errorCode, helpKeyword);
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");
80 public void TestCtorMessageException ()
82 string message = "message";
83 Exception e = new Exception ("Exception message");
85 new InvalidProjectFileException (message, e);
89 public void TestCtorNode ()
91 // FIXME: we need to load xml file to load something with non-empty XmlElement.BaseUri
93 XmlDocument xd = new XmlDocument ();
95 InvalidProjectFileException ipfe;
97 string message = "message";
98 string errorSubcategory = "errorSubcategory";
99 string errorCode = "CS0000";
100 string helpKeyword = "helpKeyword";
102 ipfe = new InvalidProjectFileException (null, message, errorSubcategory, errorCode, helpKeyword);
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");
112 [ExpectedException (typeof (ArgumentNullException))]
113 public void TestGetObjectData1 ()
115 InvalidProjectFileException ipfe = new InvalidProjectFileException ();
116 ipfe.GetObjectData (null, new StreamingContext ());
120 public void TestGetObjectData2 ()
122 StreamingContext sc = new StreamingContext ();
123 SerializationInfo si = new SerializationInfo (typeof (InvalidProjectFileException), new FormatterConverter ());
124 InvalidProjectFileException ipfe;
125 string projectFile = "projectFile";
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";
135 ipfe = new InvalidProjectFileException (projectFile, lineNumber, columnNumber, endLineNumber, endColumnNumber,
136 message, errorSubcategory, errorCode, helpKeyword);
137 ipfe.GetObjectData (si, sc);
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");