5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 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 Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
35 public class EvaluationOrder {
36 string GetItems (Project proj, string name)
38 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39 string str = String.Empty;
43 foreach (BuildItem bi in big) {
44 if (str == String.Empty)
45 str = bi.FinalItemSpec;
47 str += ";" + bi.FinalItemSpec;
54 public void TestOrder0 ()
56 Engine engine = new Engine (Consts.BinPath);
57 Project proj = engine.CreateNewProject ();
59 string documentString = @"
60 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
67 <Property>@(Item)$(A)$(B)</Property>
72 proj.LoadXml (documentString);
74 Assert.AreEqual ("@(Item)A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
75 Assert.AreEqual ("@(Item)$(A)$(B)", proj.EvaluatedProperties ["Property"].Value, "A2");
76 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
80 public void TestOrder1 ()
82 Engine engine = new Engine (Consts.BinPath);
83 Project proj = engine.CreateNewProject ();
85 string documentString = @"
86 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
92 <Property>@(Item)</Property>
97 proj.LoadXml (documentString);
99 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
100 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
101 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
105 public void TestOrder2 ()
107 Engine engine = new Engine (Consts.BinPath);
108 Project proj = engine.CreateNewProject ();
110 string documentString = @"
111 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
113 <Property>@(Item)</Property>
122 proj.LoadXml (documentString);
124 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
125 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
126 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
130 public void TestOrder3 ()
132 Engine engine = new Engine (Consts.BinPath);
133 Project proj = engine.CreateNewProject ();
135 string documentString = @"
136 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
138 <Property>A</Property>
142 <Item Include='$(Property)' />
147 proj.LoadXml (documentString);
149 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
150 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
151 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
155 public void TestOrder4 ()
157 Engine engine = new Engine (Consts.BinPath);
158 Project proj = engine.CreateNewProject ();
160 string documentString = @"
161 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
163 <Item Include='$(Property)' />
167 <Property>A</Property>
172 proj.LoadXml (documentString);
174 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
175 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
176 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
180 public void TestOrder5 ()
182 Engine engine = new Engine (Consts.BinPath);
183 Project proj = engine.CreateNewProject ();
185 string documentString = @"
186 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
188 <Item Include='$(Property)' />
192 <Property>A</Property>
193 <Property2>@(Item)</Property2>
198 proj.LoadXml (documentString);
200 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
201 Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
202 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
203 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].FinalValue, "A4");
204 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].Value, "A5");
208 [Category ("NotWorking")]
209 public void TestOrder6 ()
211 Engine engine = new Engine (Consts.BinPath);
212 Project proj = engine.CreateNewProject ();
214 string documentString = @"
215 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
218 <Item2 Include='$(Property)' />
222 <Property>@(Item)</Property>
227 proj.LoadXml (documentString);
229 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
230 Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
231 Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
232 Assert.AreEqual ("A", GetItems (proj, "Item2"), "A4");
236 [Category ("NotDotNet")]
237 public void TestImportOrder1 ()
239 Engine engine = new Engine (Consts.BinPath);
240 Project proj = engine.CreateNewProject ();
242 string documentString = @"
243 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
245 <Property>Test/resources/Import.csproj</Property>
248 <Import Project='$(Property)'/>
252 proj.LoadXml (documentString);
254 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
255 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
259 [Category ("NotDotNet")]
260 [ExpectedException (typeof (InvalidProjectFileException))]
261 public void TestImportOrder2 ()
263 Engine engine = new Engine (Consts.BinPath);
264 Project proj = engine.CreateNewProject ();
266 string documentString = @"
267 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
268 <Import Project='$(Property)'/>
271 <Property>Test/resources/Import.csproj</Property>
276 proj.LoadXml (documentString);
278 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
279 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
283 // NOTE: It will try to import "@(Item)" instead of Test/...
284 [ExpectedException (typeof (InvalidProjectFileException))]
285 public void TestImportOrder3 ()
287 Engine engine = new Engine (Consts.BinPath);
288 Project proj = engine.CreateNewProject ();
290 string documentString = @"
291 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
293 <Item Include='Test/resources/Import.csproj' />
296 <Import Project='@(Item)'/>
300 proj.LoadXml (documentString);
302 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
303 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
307 // NOTE: It will try to import "@(Item)" instead of Test/...
308 [ExpectedException (typeof (InvalidProjectFileException))]
309 public void TestImportOrder4 ()
311 Engine engine = new Engine (Consts.BinPath);
312 Project proj = engine.CreateNewProject ();
314 string documentString = @"
315 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
316 <Import Project='@(Item)'/>
319 <Item Include='Test/resources/Import.csproj' />
324 proj.LoadXml (documentString);
326 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
327 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
331 [Category ("NotDotNet")]
332 public void TestImportOrder5 ()
334 Engine engine = new Engine (Consts.BinPath);
335 Project proj = engine.CreateNewProject ();
337 string documentString = @"
338 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
340 <ImportedProperty>AnotherValue</ImportedProperty>
343 <Import Project='Test/resources/Import.csproj'/>
347 proj.LoadXml (documentString);
349 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
350 Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
354 [Category ("NotDotNet")]
355 public void TestImportOrder6 ()
357 Engine engine = new Engine (Consts.BinPath);
358 Project proj = engine.CreateNewProject ();
360 string documentString = @"
361 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
362 <Import Project='Test/resources/Import.csproj'/>
365 <ImportedProperty>AnotherValue</ImportedProperty>
370 proj.LoadXml (documentString);
372 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
373 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
377 [Category ("NotDotNet")]
378 public void TestImportOrder7 ()
380 Engine engine = new Engine (Consts.BinPath);
381 Project proj = engine.CreateNewProject ();
383 string documentString = @"
384 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
385 <Import Project='Test/resources/Import.csproj'/>
388 <ImportedProperty>Another$(ImportedProperty)</ImportedProperty>
393 proj.LoadXml (documentString);
395 Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
396 Assert.AreEqual ("Another$(ImportedProperty)", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
400 public void TestUsingTaskOrder1 ()
402 Engine engine = new Engine (Consts.BinPath);
403 Project proj = engine.CreateNewProject ();
405 string documentString = @"
406 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
408 <Property>Test\resources\TestTasks.dll</Property>
411 <UsingTask AssemblyFile='$(Property)' TaskName='TrueTestTask' />
415 proj.LoadXml (documentString);
417 UsingTask [] ut = new UsingTask [1];
418 proj.UsingTasks.CopyTo (ut, 0);
420 Assert.AreEqual ("$(Property)", ut [0].AssemblyFile, "A1");