In class/Microsoft.Build.Engine:
[mcs.git] / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / ImportTest.cs
blobc353b0400923ffdae98e5c5fc48bee2600d9d484
1 //
2 // ImportTest.cs
3 //
4 // Author:
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2006 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:
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.
28 using System;
29 using System.Collections;
30 using Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
34 using System.IO;
36 namespace MonoTests.Microsoft.Build.BuildEngine {
37 [TestFixture]
38 public class ImportTest {
40 Engine engine;
41 Project project;
43 [Test]
44 public void TestAdd1 ()
46 string first = @"
47 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
48 <Import Project='second.proj'/>
49 </Project>
51 using (StreamWriter sw = new StreamWriter ("Test/resources/first.proj")) {
52 sw.Write (first);
55 string second = @"
56 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
57 </Project>
59 using (StreamWriter sw = new StreamWriter ("Test/resources/second.proj")) {
60 sw.Write (second);
63 string documentString = @"
64 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
65 <Import Project='Test\resources\first.proj'/>
66 <Import Project='Test\resources\Import.csproj' Condition='false'/>
67 </Project>
70 engine = new Engine (Consts.BinPath);
72 project = engine.CreateNewProject ();
73 project.LoadXml (documentString);
75 Import[] t = new Import [2];
76 Assert.AreEqual (2, project.Imports.Count, "Number of imports");
77 project.Imports.CopyTo (t, 0);
79 string base_dir = Path.Combine (Environment.CurrentDirectory, Path.Combine ("Test", "resources"));
81 Assert.IsNull (t [0].Condition, "A1");
83 Assert.AreEqual (false, t[0].IsImported, "A5");
84 Assert.AreEqual ("Test\\resources\\first.proj", t[0].ProjectPath, "A6");
85 Assert.AreEqual (Path.Combine (base_dir, "first.proj"), t[0].EvaluatedProjectPath, "A7");
87 Assert.AreEqual (true, t[1].IsImported, "A2");
88 Assert.AreEqual ("second.proj", t[1].ProjectPath, "A3");
89 Assert.AreEqual (Path.Combine (base_dir, "second.proj"), t[1].EvaluatedProjectPath, "A4");
92 [Test]
93 [ExpectedException (typeof (InvalidProjectFileException))]
94 public void TestAdd2 ()
96 string documentString = @"
97 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
98 <Import Project=''/>
99 </Project>
102 engine = new Engine (Consts.BinPath);
104 project = engine.CreateNewProject ();
105 project.LoadXml (documentString);
108 [Test]
109 [Category ("NotWorking")]
110 public void TestAdd3 ()
112 string documentString = @"
113 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
114 <Import Project='Test/resources/SelfImport.csproj'/>
115 </Project>
118 engine = new Engine (Consts.BinPath);
120 project = engine.CreateNewProject ();
121 project.LoadXml (documentString);
123 Assert.AreEqual (1, project.Imports.Count, "A1");
126 [Test]
127 public void TestRelativeImport1 ()
129 string documentString = @"
130 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
131 <Import Project='Test/resources/RelativeImport1.csproj'/>
132 </Project>
135 engine = new Engine (Consts.BinPath);
137 project = engine.CreateNewProject ();
138 project.LoadXml (documentString);
140 Assert.AreEqual ("B", project.EvaluatedProperties ["A"].FinalValue, "A1");
143 [Test]
144 public void TestItems1 ()
146 string documentString = @"
147 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
148 <Import Project='Test/resources/Items.csproj'/>
149 </Project>
152 engine = new Engine (Consts.BinPath);
154 project = engine.CreateNewProject ();
155 project.LoadXml (documentString);
157 BuildItemGroup [] groups = new BuildItemGroup [1];
158 project.ItemGroups.CopyTo (groups, 0);
160 Assert.IsTrue (groups [0].IsImported, "A1");
161 Assert.AreEqual (1, groups [0].Count, "A2");
164 [Test]
165 [ExpectedException (typeof (InvalidProjectFileException))]
166 public void TestMissingImport1 ()
168 string documentString = @"
169 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
170 <Import Project='Test/resources/NonExistantProject.proj'/>
171 </Project>";
173 engine = new Engine (Consts.BinPath);
175 project = engine.CreateNewProject ();
176 project.LoadXml (documentString, ProjectLoadSettings.None);
179 [Test]
180 public void TestMissingImport2 ()
182 string documentString = @"
183 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
184 <Import Project='Test/resources/NonExistantProject.proj'/>
185 </Project>
188 engine = new Engine (Consts.BinPath);
190 project = engine.CreateNewProject ();
191 project.LoadXml (documentString, ProjectLoadSettings.IgnoreMissingImports);
193 Assert.AreEqual (1, project.Imports.Count, "A1");
196 [Test]
197 [ExpectedException (typeof (InvalidProjectFileException))]
198 public void TestMissingImportDefault ()
200 string documentString = @"
201 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
202 <Import Project='Test/resources/NonExistantProject.proj'/>
203 </Project>
206 engine = new Engine (Consts.BinPath);
208 project = engine.CreateNewProject ();
209 project.LoadXml (documentString);