merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / various / EvaluationOrder.cs
1 //
2 // EvaluationOrder.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:
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.Xml;
30 using Microsoft.Build.BuildEngine;
31 using NUnit.Framework;
32
33 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
34         [TestFixture]
35         public class EvaluationOrder {
36                 private string GetItems (Project proj, string name)
37                 {
38                         BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
39                         string str = String.Empty;
40                         if (big == null)
41                                 return str;
42                         
43                         foreach (BuildItem bi in big) {
44                                 if (str == String.Empty)
45                                         str = bi.FinalItemSpec;
46                                 else 
47                                         str += ";" + bi.FinalItemSpec;
48                         }
49                         
50                         return str;
51                 }
52
53                 [Test]
54                 [Category ("NotWorking")]
55                 public void TestOrder0 ()
56                 {
57                         Engine engine = new Engine (Consts.BinPath);
58                         Project proj = engine.CreateNewProject ();
59
60                         string documentString = @"
61                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
62                                         <ItemGroup>
63                                                 <Item Include='A' />
64                                         </ItemGroup>
65
66                                         <PropertyGroup>
67                                                 <A>A</A>
68                                                 <Property>@(Item)$(A)$(B)</Property>
69                                         </PropertyGroup>
70                                 </Project>
71                         ";
72
73                         proj.LoadXml (documentString);
74
75                         Assert.AreEqual ("@(Item)A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
76                         Assert.AreEqual ("@(Item)$(A)$(B)", proj.EvaluatedProperties ["Property"].Value, "A2");
77                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
78                 }
79
80                 [Test]
81                 [Category ("NotWorking")]
82                 public void TestOrder1 ()
83                 {
84                         Engine engine = new Engine (Consts.BinPath);
85                         Project proj = engine.CreateNewProject ();
86
87                         string documentString = @"
88                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
89                                         <ItemGroup>
90                                                 <Item Include='A' />
91                                         </ItemGroup>
92
93                                         <PropertyGroup>
94                                                 <Property>@(Item)</Property>
95                                         </PropertyGroup>
96                                 </Project>
97                         ";
98
99                         proj.LoadXml (documentString);
100
101                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
102                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
103                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
104                 }
105
106                 [Test]
107                 [Category ("NotWorking")]
108                 public void TestOrder2 ()
109                 {
110                         Engine engine = new Engine (Consts.BinPath);
111                         Project proj = engine.CreateNewProject ();
112
113                         string documentString = @"
114                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
115                                         <PropertyGroup>
116                                                 <Property>@(Item)</Property>
117                                         </PropertyGroup>
118
119                                         <ItemGroup>
120                                                 <Item Include='A' />
121                                         </ItemGroup>
122                                 </Project>
123                         ";
124
125                         proj.LoadXml (documentString);
126
127                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
128                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
129                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
130                 }
131
132                 [Test]
133                 public void TestOrder3 ()
134                 {
135                         Engine engine = new Engine (Consts.BinPath);
136                         Project proj = engine.CreateNewProject ();
137
138                         string documentString = @"
139                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
140                                         <PropertyGroup>
141                                                 <Property>A</Property>
142                                         </PropertyGroup>
143
144                                         <ItemGroup>
145                                                 <Item Include='$(Property)' />
146                                         </ItemGroup>
147                                 </Project>
148                         ";
149
150                         proj.LoadXml (documentString);
151
152                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
153                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
154                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
155                 }
156
157                 [Test]
158                 public void TestOrder4 ()
159                 {
160                         Engine engine = new Engine (Consts.BinPath);
161                         Project proj = engine.CreateNewProject ();
162
163                         string documentString = @"
164                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
165                                         <ItemGroup>
166                                                 <Item Include='$(Property)' />
167                                         </ItemGroup>
168
169                                         <PropertyGroup>
170                                                 <Property>A</Property>
171                                         </PropertyGroup>
172                                 </Project>
173                         ";
174
175                         proj.LoadXml (documentString);
176
177                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
178                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
179                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
180                 }
181
182                 [Test]
183                 [Category ("NotWorking")]
184                 public void TestOrder5 ()
185                 {
186                         Engine engine = new Engine (Consts.BinPath);
187                         Project proj = engine.CreateNewProject ();
188
189                         string documentString = @"
190                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
191                                         <ItemGroup>
192                                                 <Item Include='$(Property)' />
193                                         </ItemGroup>
194
195                                         <PropertyGroup>
196                                                 <Property>A</Property>
197                                                 <Property2>@(Item)</Property2>
198                                         </PropertyGroup>
199                                 </Project>
200                         ";
201
202                         proj.LoadXml (documentString);
203
204                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
205                         Assert.AreEqual ("A", proj.EvaluatedProperties ["Property"].Value, "A2");
206                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
207                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].FinalValue, "A4");
208                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property2"].Value, "A5");
209                 }
210
211                 [Test]
212                 [Category ("NotWorking")]
213                 public void TestOrder6 ()
214                 {
215                         Engine engine = new Engine (Consts.BinPath);
216                         Project proj = engine.CreateNewProject ();
217
218                         string documentString = @"
219                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
220                                         <ItemGroup>
221                                                 <Item Include='A' />
222                                                 <Item2 Include='$(Property)' />
223                                         </ItemGroup>
224
225                                         <PropertyGroup>
226                                                 <Property>@(Item)</Property>
227                                         </PropertyGroup>
228                                 </Project>
229                         ";
230
231                         proj.LoadXml (documentString);
232
233                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].FinalValue, "A1");
234                         Assert.AreEqual ("@(Item)", proj.EvaluatedProperties ["Property"].Value, "A2");
235                         Assert.AreEqual ("A", GetItems (proj, "Item"), "A3");
236                         Assert.AreEqual ("A", GetItems (proj, "Item2"), "A4");
237                 }
238
239                 [Test]
240                 public void TestImportOrder1 ()
241                 {
242                         Engine engine = new Engine (Consts.BinPath);
243                         Project proj = engine.CreateNewProject ();
244
245                         string documentString = @"
246                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
247                                         <PropertyGroup>
248                                                 <Property>Test/resources/Import.csproj</Property>
249                                         </PropertyGroup>
250
251                                         <Import Project='$(Property)'/>
252                                 </Project>
253                         ";
254
255                         proj.LoadXml (documentString);
256
257                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
258                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
259                 }
260
261                 [Test]
262                 [ExpectedException (typeof (InvalidProjectFileException))]
263                 public void TestImportOrder2 ()
264                 {
265                         Engine engine = new Engine (Consts.BinPath);
266                         Project proj = engine.CreateNewProject ();
267
268                         string documentString = @"
269                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
270                                         <Import Project='$(Property)'/>
271
272                                         <PropertyGroup>
273                                                 <Property>Test/resources/Import.csproj</Property>
274                                         </PropertyGroup>
275                                 </Project>
276                         ";
277
278                         proj.LoadXml (documentString);
279
280                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
281                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
282                 }
283
284                 [Test]
285                 // NOTE: It will try to import "@(Item)" instead of Test/...
286                 [ExpectedException (typeof (InvalidProjectFileException))]
287                 [Category ("NotWorking")]
288                 public void TestImportOrder3 ()
289                 {
290                         Engine engine = new Engine (Consts.BinPath);
291                         Project proj = engine.CreateNewProject ();
292
293                         string documentString = @"
294                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
295                                         <ItemGroup>
296                                                 <Item Include='Test/resources/Import.csproj' />
297                                         </ItemGroup>
298
299                                         <Import Project='@(Item)'/>
300                                 </Project>
301                         ";
302
303                         proj.LoadXml (documentString);
304
305                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
306                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
307                 }
308
309                 [Test]
310                 // NOTE: It will try to import "@(Item)" instead of Test/...
311                 [ExpectedException (typeof (InvalidProjectFileException))]
312                 [Category ("NotWorking")]
313                 public void TestImportOrder4 ()
314                 {
315                         Engine engine = new Engine (Consts.BinPath);
316                         Project proj = engine.CreateNewProject ();
317
318                         string documentString = @"
319                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
320                                         <Import Project='@(Item)'/>
321
322                                         <ItemGroup>
323                                                 <Item Include='Test/resources/Import.csproj' />
324                                         </ItemGroup>
325                                 </Project>
326                         ";
327
328                         proj.LoadXml (documentString);
329
330                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
331                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
332                 }
333
334                 [Test]
335                 public void TestImportOrder5 ()
336                 {
337                         Engine engine = new Engine (Consts.BinPath);
338                         Project proj = engine.CreateNewProject ();
339
340                         string documentString = @"
341                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
342                                         <PropertyGroup>
343                                                 <ImportedProperty>AnotherValue</ImportedProperty>
344                                         </PropertyGroup>
345
346                                         <Import Project='Test/resources/Import.csproj'/>
347                                 </Project>
348                         ";
349
350                         proj.LoadXml (documentString);
351
352                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
353                         Assert.AreEqual ("Value", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
354                 }
355
356                 [Test]
357                 public void TestImportOrder6 ()
358                 {
359                         Engine engine = new Engine (Consts.BinPath);
360                         Project proj = engine.CreateNewProject ();
361
362                         string documentString = @"
363                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
364                                         <Import Project='Test/resources/Import.csproj'/>
365
366                                         <PropertyGroup>
367                                                 <ImportedProperty>AnotherValue</ImportedProperty>
368                                         </PropertyGroup>
369                                 </Project>
370                         ";
371
372                         proj.LoadXml (documentString);
373
374                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
375                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
376                 }
377
378                 [Test]
379                 public void TestImportOrder7 ()
380                 {
381                         Engine engine = new Engine (Consts.BinPath);
382                         Project proj = engine.CreateNewProject ();
383
384                         string documentString = @"
385                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
386                                         <Import Project='Test/resources/Import.csproj'/>
387
388                                         <PropertyGroup>
389                                                 <ImportedProperty>Another$(ImportedProperty)</ImportedProperty>
390                                         </PropertyGroup>
391                                 </Project>
392                         ";
393
394                         proj.LoadXml (documentString);
395
396                         Assert.AreEqual ("AnotherValue", proj.EvaluatedProperties ["ImportedProperty"].FinalValue, "A1");
397                         Assert.AreEqual ("Another$(ImportedProperty)", proj.EvaluatedProperties ["ImportedProperty"].Value, "A2");
398                 }
399
400                 [Test]
401                 public void TestUsingTaskOrder1 ()
402                 {
403                         Engine engine = new Engine (Consts.BinPath);
404                         Project proj = engine.CreateNewProject ();
405
406                         string documentString = @"
407                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
408                                         <PropertyGroup>
409                                                 <Property>Test\resources\TestTasks.dll</Property>
410                                         </PropertyGroup>
411
412                                         <UsingTask AssemblyFile='$(Property)' TaskName='TrueTestTask' />
413                                 </Project>
414                         ";
415
416                         proj.LoadXml (documentString);
417
418                         UsingTask [] ut = new UsingTask [1];
419                         proj.UsingTasks.CopyTo (ut, 0);
420
421                         Assert.AreEqual ("$(Property)", ut [0].AssemblyFile, "A1");
422                 }
423         }
424 }