fixed tests
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / ProjectTest.cs
1 //
2 // ProjectTest.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.Collections;
30 using System.Collections.Generic;
31 using System.Xml;
32 using Microsoft.Build.BuildEngine;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
36
37 namespace MonoTests.Microsoft.Build.BuildEngine {
38
39         class TestLogger : Logger {
40                 int target_started_events = 0;
41                 int target_finished_events = 0;
42
43                 public override void Initialize (IEventSource eventSource)
44                 {
45                         eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted);
46                         eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished);
47                         eventSource.MessageRaised += new BuildMessageEventHandler(Message);
48                         eventSource.WarningRaised += new BuildWarningEventHandler(Warning);
49                 }
50
51                 void TargetStarted (object sender, TargetStartedEventArgs args)
52                 {
53                         target_started_events++;
54                 }
55
56                 void TargetFinished (object sender, TargetFinishedEventArgs args)
57                 {
58                         target_finished_events++;
59                 }
60
61                 void Message (object sender, BuildMessageEventArgs args)
62                 {
63                 }
64                 
65                 void Warning (object sender, BuildWarningEventArgs args)
66                 {
67                 }
68
69                 public int TargetStartedEvents { get { return target_started_events; } }
70
71                 public int TargetFinishedEvents { get { return target_finished_events; } }
72         }
73
74         [TestFixture]
75         public class ProjectTest {
76
77                 /*
78                 Import [] GetImports (ImportCollection ic)
79                 {
80                         List<Import> list = new List<Import> ();
81                         foreach (Import i in ic)
82                                 list.Add (i);
83                         return list.ToArray ();
84                 }
85                 */
86
87                 [Test]
88                 [ExpectedException (typeof (InvalidProjectFileException),
89                 @"The default XML namespace of the project must be the MSBuild XML namespace." + 
90                 " If the project is authored in the MSBuild 2003 format, please add " +
91                 "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" to the <Project> element. " +
92                 "If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.  ")]
93                 public void TestAssignment1 ()
94                 {
95                         Engine engine;
96                         Project project;
97                         string documentString =
98                                 "<Project></Project>";
99                         
100                         engine = new Engine (Consts.BinPath);
101                         DateTime time = DateTime.Now;
102                         project = engine.CreateNewProject ();
103                         project.LoadXml (documentString);
104
105                         Assert.AreEqual (true, project.BuildEnabled, "A1");
106                         Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
107                         Assert.AreEqual (String.Empty, project.FullFileName, "A3");
108                         Assert.AreEqual (false, project.IsDirty, "A4");
109                         Assert.AreEqual (false, project.IsValidated, "A5");
110                         Assert.AreEqual (engine, project.ParentEngine, "A6");
111                         Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
112                         Assert.IsTrue (String.Empty != project.Xml, "A8");
113                 }
114
115                 [Test]
116                 public void TestAssignment2 ()
117                 {
118                         Engine engine;
119                         Project project;
120                         string documentString =
121                                 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>";
122                         
123                         engine = new Engine (Consts.BinPath);
124                         DateTime time = DateTime.Now;
125                         project = engine.CreateNewProject ();
126                         project.LoadXml (documentString);
127
128                         Assert.AreEqual (true, project.BuildEnabled, "A1");
129                         Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
130                         Assert.AreEqual (String.Empty, project.FullFileName, "A3");
131                         Assert.AreEqual (true, project.IsDirty, "A4");
132                         Assert.AreEqual (false, project.IsValidated, "A5");
133                         Assert.AreEqual (engine, project.ParentEngine, "A6");
134                         Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
135                         Assert.IsTrue (String.Empty != project.Xml, "A8");
136                 }
137
138                 [Test]
139                 [Category ("NotWorking")]
140                 public void TestAddNewImport1 ()
141                 {
142                         Engine engine;
143                         Project project;
144
145                         string documentString = @"
146                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
147                                         <PropertyGroup />
148                                         <ItemGroup />
149                                         <Target Name='a' />
150                                         <Import Project='Test/resources/Import.csproj' />
151                                 </Project>
152                         ";
153
154                         engine = new Engine (Consts.BinPath);
155                         project = engine.CreateNewProject ();
156                         project.LoadXml (documentString);
157
158                         project.AddNewImport ("a", "true");
159                         // reevaluation wasn't caused by anything so it has only old import
160                         Assert.AreEqual (1, project.Imports.Count, "A1");
161                 }
162
163                 [Test]
164                 [Ignore ("Too detailed probably (implementation specific)")]
165                 public void TestAddNewItem1 ()
166                 {
167                         Engine engine;
168                         Project project;
169                         BuildItemGroup [] groups = new BuildItemGroup [1];
170
171                         string documentString = @"
172                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
173                                 </Project>
174                         ";
175
176                         engine = new Engine (Consts.BinPath);
177                         project = engine.CreateNewProject ();
178                         project.LoadXml (documentString);
179
180                         BuildItem item = project.AddNewItem ("A", "B");
181
182                         Assert.AreEqual (1, project.ItemGroups.Count, "A1");
183                         project.ItemGroups.CopyTo (groups, 0);
184                         Assert.AreEqual (1, groups [0].Count, "A2");
185                         Assert.AreEqual ("B", groups [0] [0].Include, "A3");
186                         Assert.AreEqual ("B", groups [0] [0].FinalItemSpec, "A4");
187                         Assert.AreEqual ("A", groups [0] [0].Name, "A5");
188                         //Assert.AreNotSame (item, groups [0] [0], "A6");
189                         Assert.IsFalse (object.ReferenceEquals (item, groups [0] [0]), "A6");
190
191                         Assert.AreEqual (1, project.EvaluatedItems.Count, "A7");
192                         Assert.AreEqual ("B", project.EvaluatedItems [0].Include, "A8");
193                         Assert.AreEqual ("B", project.EvaluatedItems [0].FinalItemSpec, "A9");
194                         Assert.AreEqual ("A", project.EvaluatedItems [0].Name, "A10");
195                         //Assert.AreNotSame (item, project.EvaluatedItems [0], "A11");
196                         Assert.IsFalse (object.ReferenceEquals (item, project.EvaluatedItems [0]), "A11");
197                 }
198
199                 [Test]
200                 [Category ("NotWorking")]
201                 public void TestAddNewItem2 ()
202                 {
203                         Engine engine;
204                         Project project;
205
206                         engine = new Engine (Consts.BinPath);
207                         project = engine.CreateNewProject ();
208
209                         BuildItem item = project.AddNewItem ("A", "a;b;c");
210                         Assert.AreEqual ("a;b;c", item.Include, "A1");
211                         Assert.AreEqual ("a", item.FinalItemSpec, "A2");
212
213                         Assert.AreEqual (3, project.EvaluatedItems.Count, "A3");
214                 }
215
216                 [Test]
217                 public void TestAddNewItem3 ()
218                 {
219                         Engine engine;
220                         Project project;
221                         BuildItemGroup [] groups = new BuildItemGroup [4];
222
223                         string documentString = @"
224                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
225                                         <ItemGroup />
226                                         <ItemGroup>
227                                                 <A Include='a'/>
228                                         </ItemGroup>
229                                         <ItemGroup>
230                                                 <B Include='a'/>
231                                         </ItemGroup>
232                                         <ItemGroup>
233                                                 <B Include='a'/>
234                                         </ItemGroup>
235                                 </Project>
236                         ";
237
238                         engine = new Engine (Consts.BinPath);
239                         project = engine.CreateNewProject ();
240                         project.LoadXml (documentString);
241
242                         project.AddNewItem ("B", "b");
243
244                         project.ItemGroups.CopyTo (groups, 0);
245                         Assert.AreEqual (0, groups [0].Count, "A1");
246                         Assert.AreEqual (1, groups [1].Count, "A2");
247                         Assert.AreEqual (1, groups [2].Count, "A3");
248                         Assert.AreEqual (2, groups [3].Count, "A4");
249                 }
250                 [Test]
251                 public void TestAddNewItemGroup ()
252                 {
253                         Engine engine;
254                         Project project;
255
256                         string documentString = @"
257                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
258                                 </Project>
259                         ";
260
261                         engine = new Engine (Consts.BinPath);
262                         project = engine.CreateNewProject ();
263                         project.LoadXml (documentString);
264
265                         BuildItemGroup big = project.AddNewItemGroup ();
266                         Assert.IsNotNull (big, "A1");
267                         Assert.AreEqual (String.Empty, big.Condition, "A2");
268                         Assert.AreEqual (0, big.Count, "A3");
269                         Assert.AreEqual (false, big.IsImported, "A4");
270                         Assert.IsTrue (project.IsDirty, "A5");
271                 }
272
273                 [Test]
274                 public void TestAddNewPropertyGroup ()
275                 {
276                         Engine engine;
277                         Project project;
278
279                         string documentString = @"
280                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
281                                 </Project>
282                         ";
283
284                         engine = new Engine (Consts.BinPath);
285                         project = engine.CreateNewProject ();
286                         project.LoadXml (documentString);
287
288                         BuildPropertyGroup bpg = project.AddNewPropertyGroup (false);
289                         Assert.IsNotNull (bpg, "A1");
290                         Assert.AreEqual (String.Empty, bpg.Condition, "A2");
291                         Assert.AreEqual (0, bpg.Count, "A3");
292                         Assert.AreEqual (false, bpg.IsImported, "A4");
293                         Assert.IsTrue (project.IsDirty, "A5");
294                 }
295
296                 [Test]
297                 [Category ("NotWorking")]
298                 public void TestBuild1 ()
299                 {
300                         Engine engine;
301                         Project project;
302                         IDictionary hashtable = new Hashtable ();
303                         
304                         string documentString = @"
305                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
306                                         <Target Name='Main'>
307                                                 <Microsoft.Build.Tasks.Message Text='Text' />
308                                         </Target>
309                                 </Project>
310                         ";
311                         
312                         engine = new Engine (Consts.BinPath);
313                         project = engine.CreateNewProject ();
314                         project.LoadXml (documentString);
315
316                         Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
317                         Assert.AreEqual (1, hashtable.Count, "A2");
318                 }
319
320                 [Test]
321                 public void TestBuild2 ()
322                 {
323                         Engine engine;
324                         Project project;
325
326                         string documentString = @"
327                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
328                                         <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
329                                                 <Message Text='text' />
330                                         </Target>
331                                 </Project>
332                         ";
333
334                         engine = new Engine (Consts.BinPath);
335                         TestLogger tl = new TestLogger ();
336                         engine.RegisterLogger (tl);
337                         project = engine.CreateNewProject ();
338                         project.LoadXml (documentString);
339
340                         project.Build ("T");
341                         project.Build ("T");
342
343                         Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
344                         Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
345                 }
346
347                 [Test]
348                 public void TestBuild3 ()
349                 {
350                         Engine engine;
351                         Project project;
352
353                         string documentString = @"
354                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
355                                         <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
356                                                 <Message Text='text' />
357                                         </Target>
358                                 </Project>
359                         ";
360
361                         engine = new Engine (Consts.BinPath);
362                         TestLogger tl = new TestLogger ();
363                         engine.RegisterLogger (tl);
364                         project = engine.CreateNewProject ();
365                         project.LoadXml (documentString);
366
367                         project.Build (new string [1] { "T" }, null, BuildSettings.None);
368                         project.Build (new string [1] { "T" }, null, BuildSettings.None);
369
370                         Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
371                         Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
372                 }
373
374                 [Test]
375                 [Category ("NotWorking")]
376                 public void TestBuild4 ()
377                 {
378                         Engine engine;
379                         Project project;
380
381                         string documentString = @"
382                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
383                                         <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
384                                                 <Message Text='text' />
385                                         </Target>
386                                 </Project>
387                         ";
388
389                         engine = new Engine (Consts.BinPath);
390                         TestLogger tl = new TestLogger ();
391                         engine.RegisterLogger (tl);
392                         project = engine.CreateNewProject ();
393                         project.LoadXml (documentString);
394
395                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
396                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
397
398                         Assert.AreEqual (1, tl.TargetStartedEvents, "A1");
399                         Assert.AreEqual (1, tl.TargetFinishedEvents, "A2");
400                 }
401
402                 [Test]
403                 public void TestBuild5 ()
404                 {
405                         Engine engine;
406                         Project project;
407
408                         string documentString = @"
409                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
410                                 </Project>
411                         ";
412
413                         engine = new Engine (Consts.BinPath);
414                         project = engine.CreateNewProject ();
415                         project.LoadXml (documentString);
416
417                         Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
418                 }
419
420                 [Test]
421                 public void TestEvaluatedItems1 ()
422                 {
423                         Engine engine;
424                         Project project;
425
426                         string documentString = @"
427                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
428                                         <ItemGroup>
429                                                 <A Include='a' />
430                                                 <B Include='b' Condition='false' />
431                                         </ItemGroup>
432                                 </Project>
433                         ";
434
435                         engine = new Engine (Consts.BinPath);
436                         project = engine.CreateNewProject ();
437                         project.LoadXml (documentString);
438
439                         Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
440
441                         BuildItem bi = project.EvaluatedItems [0];
442
443                         bi.Name = "C";
444                         bi.Include = "c";
445
446                         BuildItemGroup [] big = new BuildItemGroup [1];
447                         project.ItemGroups.CopyTo (big, 0);
448                         Assert.AreEqual ("C", big [0] [0].Name, "A2");
449                         Assert.AreEqual ("c", big [0] [0].Include, "A3");
450                 }
451
452                 [Test]
453                 public void TestEvaluatedItems2 ()
454                 {
455                         Engine engine;
456                         Project project;
457
458                         string documentString = @"
459                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
460                                         <ItemGroup>
461                                                 <A Include='a;b;c' />
462                                         </ItemGroup>
463                                 </Project>
464                         ";
465
466                         engine = new Engine (Consts.BinPath);
467                         project = engine.CreateNewProject ();
468                         project.LoadXml (documentString);
469
470                         BuildItemGroup [] big = new BuildItemGroup [1];
471                         project.ItemGroups.CopyTo (big, 0);
472
473                         Assert.AreEqual (3, project.EvaluatedItems.Count, "A1");
474                         Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2");
475                         Assert.AreEqual (1, big [0].Count, "A3");
476
477                         BuildItem bi = project.EvaluatedItems [0];
478
479                         bi.Include = "d";
480
481                         Assert.AreEqual (3, big [0].Count, "A4");
482                         Assert.AreEqual ("d", big [0] [0].Include, "A5");
483                         Assert.AreEqual ("b", big [0] [1].Include, "A6");
484                         Assert.AreEqual ("c", big [0] [2].Include, "A7");
485                 }
486
487                 [Test]
488                 [Category ("NotWorking")]
489                 public void TestGetConditionedPropertyValues ()
490                 {
491                         Engine engine;
492                         Project project;
493
494                         string documentString = @"
495                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
496                                         <PropertyGroup Condition='true'>
497                                                 <A>A</A>
498                                                 <B Condition='true'>A</B>
499                                         </PropertyGroup>
500                                         <PropertyGroup>
501                                                 <C Condition='true'>A</C>
502                                                 <C Condition='false'>B</C>
503                                                 <C Condition='!false'>C</C>
504                                                 <D>A</D>
505                                                 <E Condition="" '$(C)' == 'A' "">E</E>
506                                         </PropertyGroup>
507                                 </Project>
508                         ";
509
510                         engine = new Engine (Consts.BinPath);
511                         project = engine.CreateNewProject ();
512                         project.LoadXml (documentString);
513
514                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1");
515                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2");
516                         Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3");
517                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4");
518                         Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5");
519                         Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6");
520                 }
521
522                 [Test]
523                 [ExpectedException (typeof (ArgumentNullException))]
524                 public void TestGetEvaluatedItemsByName1 ()
525                 {
526                         Engine engine;
527                         Project project;
528
529                         string documentString = @"
530                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
531                                 </Project>
532                         ";
533
534                         engine = new Engine (Consts.BinPath);
535                         project = engine.CreateNewProject ();
536                         project.LoadXml (documentString);
537
538                         project.GetEvaluatedItemsByName (null);
539                 }
540
541                 [Test]
542                 public void TestGetEvaluatedItemsByName2 ()
543                 {
544                         Engine engine;
545                         Project project;
546
547                         string documentString = @"
548                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
549                                         <ItemGroup>
550                                                 <A Include='1' />
551                                                 <B Include='2' Condition='true' />
552                                                 <C Include='3' Condition='false' />
553                                         </ItemGroup>
554                                 </Project>
555                         ";
556
557                         engine = new Engine (Consts.BinPath);
558                         project = engine.CreateNewProject ();
559                         project.LoadXml (documentString);
560
561                         BuildItemGroup big;
562
563                         big = project.GetEvaluatedItemsByName (String.Empty);
564
565                         Assert.AreEqual (0, big.Count, "A1");
566
567                         big = project.GetEvaluatedItemsByName ("A");
568
569                         Assert.AreEqual (1, big.Count, "A2");
570                         Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
571
572                         big = project.GetEvaluatedItemsByName ("B");
573
574                         Assert.AreEqual (1, big.Count, "A4");
575                         Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
576
577                         big = project.GetEvaluatedItemsByName ("C");
578
579                         Assert.AreEqual (0, big.Count, "A6");
580                 }
581
582                 [Test]
583                 [ExpectedException (typeof (ArgumentNullException))]
584                 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
585                 {
586                         Engine engine;
587                         Project project;
588
589                         string documentString = @"
590                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
591                                 </Project>
592                         ";
593
594                         engine = new Engine (Consts.BinPath);
595                         project = engine.CreateNewProject ();
596                         project.LoadXml (documentString);
597
598                         project.GetEvaluatedItemsByNameIgnoringCondition (null);
599                 }
600
601                 [Test]
602                 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
603                 {
604                         Engine engine;
605                         Project project;
606
607                         string documentString = @"
608                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
609                                         <ItemGroup>
610                                                 <A Include='1' />
611                                                 <B Include='2' Condition='true' />
612                                                 <C Include='3' Condition='false' />
613                                         </ItemGroup>
614                                 </Project>
615                         ";
616
617                         engine = new Engine (Consts.BinPath);
618                         project = engine.CreateNewProject ();
619                         project.LoadXml (documentString);
620
621                         BuildItemGroup big;
622
623                         big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
624
625                         Assert.AreEqual (0, big.Count, "A1");
626
627                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
628
629                         Assert.AreEqual (1, big.Count, "A2");
630                         Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
631
632                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
633
634                         Assert.AreEqual (1, big.Count, "A4");
635                         Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
636
637                         big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
638
639                         Assert.AreEqual (1, big.Count, "A6");
640                         Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
641                 }
642
643                 [Test]
644                 [ExpectedException (typeof (ArgumentNullException))]
645                 public void TestGetEvaluatedProperty1 ()
646                 {
647                         Engine engine;
648                         Project project;
649
650                         string documentString = @"
651                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
652                                 </Project>
653                         ";
654
655                         engine = new Engine (Consts.BinPath);
656                         project = engine.CreateNewProject ();
657                         project.LoadXml (documentString);
658
659                         project.GetEvaluatedProperty (null);
660                 }
661                 [Test]
662                 public void TestGetEvaluatedProperty2 ()
663                 {
664                         Engine engine;
665                         Project project;
666
667                         string documentString = @"
668                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
669                                         <PropertyGroup>
670                                                 <A>1</A>
671                                                 <B Condition='true'>2</B>
672                                                 <C Condition='false'>3</C>
673                                         </PropertyGroup>
674                                 </Project>
675                         ";
676
677                         engine = new Engine (Consts.BinPath);
678                         project = engine.CreateNewProject ();
679                         project.LoadXml (documentString);
680
681                         Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
682                         Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
683                         Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
684                 }
685
686                 [Test]
687                 public void TestGetProjectExtensions ()
688                 {
689                         Engine engine;
690                         Project project;
691
692                         string documentString = @"
693                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
694                                         <ProjectExtensions>
695                                                 <Node>Text</Node>
696                                         </ProjectExtensions>
697                                 </Project>
698                         ";
699
700                         engine = new Engine (Consts.BinPath);
701                         project = engine.CreateNewProject ();
702                         project.LoadXml (documentString);
703
704                         Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1");
705                         Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2");
706                         Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3");
707                         Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4");
708                 }
709
710                 [Test]
711                 public void TestGlobalProperties1 ()
712                 {
713                         Engine engine;
714                         Project project;
715                         
716                         string documentString = @"
717                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
718                                 </Project>
719                         ";
720                         
721                         engine = new Engine (Consts.BinPath);
722                         project = engine.CreateNewProject ();
723                         project.LoadXml (documentString);
724
725                         Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
726                 }
727
728                 [Test]
729                 public void TestGlobalProperties2 ()
730                 {
731                         Engine engine;
732                         Project project;
733                         
734                         string documentString = @"
735                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
736                                 </Project>
737                         ";
738                         
739                         engine = new Engine (Consts.BinPath);
740                         engine.GlobalProperties.SetProperty ("Property", "Value");
741                         
742                         project = engine.CreateNewProject ();
743                         project.LoadXml (documentString);
744
745                         Assert.AreEqual (1, project.GlobalProperties.Count, "A1");
746                         Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2");
747                         Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3");
748                         Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4");
749                         Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2");
750                         Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3");
751                         Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4");
752                 }
753
754                 [Test]
755                 [Category ("NotDotNet")]
756                 [ExpectedException (typeof (ArgumentNullException))]
757                 public void TestGlobalProperties3 ()
758                 {
759                         Engine engine;
760                         Project project;
761                         
762                         string documentString = @"
763                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
764                                 </Project>
765                         ";
766                         
767                         engine = new Engine (Consts.BinPath);
768                         project = engine.CreateNewProject ();
769                         project.LoadXml (documentString);
770
771                         project.GlobalProperties = null;
772                 }
773
774                 [Test]
775                 [Ignore ("needs rewriting")]
776                 public void TestGlobalProperties4 ()
777                 {
778                         Engine engine;
779                         Project project;
780                         
781                         string documentString = @"
782                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
783                                         <PropertyGroup>
784                                                 <Property>a</Property>
785                                         </PropertyGroup>
786                                 </Project>
787                         ";
788                         
789                         engine = new Engine (Consts.BinPath);
790                         project = engine.CreateNewProject ();
791                         project.LoadXml (documentString);
792
793                         BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
794                         project.PropertyGroups.CopyTo (groups, 0);
795
796                         project.GlobalProperties = groups [0];
797                         project.GlobalProperties = project.EvaluatedProperties;
798                 }
799
800                 [Test]
801                 [Category ("NotDotNet")]
802                 [ExpectedException (typeof (InvalidOperationException))]
803                 public void TestGlobalProperties5 ()
804                 {
805                         Engine engine;
806                         Project project;
807                         
808                         string documentString = @"
809                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
810                                         <PropertyGroup>
811                                                 <Property>a</Property>
812                                         </PropertyGroup>
813                                 </Project>
814                         ";
815                         
816                         engine = new Engine (Consts.BinPath);
817                         project = engine.CreateNewProject ();
818                         project.LoadXml (documentString);
819
820                         BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
821                         project.PropertyGroups.CopyTo (groups, 0);
822                         project.GlobalProperties = groups [0];
823                 }
824
825                 [Test]
826                 [ExpectedException (typeof (InvalidProjectFileException))]
827                 public void TestLoad1 ()
828                 {
829                         Engine engine;
830                         Project project;
831
832                         string documentString = @"
833                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
834                                         <PropertyGroup>
835                                 </Project>
836                         ";
837
838                         engine = new Engine (Consts.BinPath);
839                         project = engine.CreateNewProject ();
840                         project.LoadXml (documentString);
841                 }
842
843                 [Test]
844                 [ExpectedException (typeof (InvalidProjectFileException))]
845                 public void TestLoad2 ()
846                 {
847                         Engine engine;
848                         Project project;
849
850                         engine = new Engine (Consts.BinPath);
851                         project = engine.CreateNewProject ();
852                         project.LoadXml ("project_file_that_doesnt_exist");
853                 }
854
855                 [Test]
856                 public void TestParentEngine ()
857                 {
858                         Engine engine;
859                         Project project;
860                         
861                         engine = new Engine (Consts.BinPath);
862                         project = engine.CreateNewProject ();
863
864                         Assert.AreEqual (engine, project.ParentEngine, "A1");
865                 }
866
867                 [Test]
868                 [Category ("NotDotNet")]
869                 [ExpectedException (typeof (ArgumentNullException))]
870                 public void TestRemoveItemGroup1 ()
871                 {
872                         Engine engine;
873                         Project p1;
874
875                         engine = new Engine (Consts.BinPath);
876                         p1 = engine.CreateNewProject ();
877
878                         p1.RemoveItemGroup (null);
879                 }
880
881                 [Test]
882                 [ExpectedException (typeof (InvalidOperationException),
883                                         "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
884                 [Category ("NotWorking")]
885                 public void TestRemoveItemGroup2 ()
886                 {
887                         Engine engine;
888                         Project p1;
889                         Project p2;
890                         BuildItemGroup [] groups  = new BuildItemGroup [1];
891
892                         engine = new Engine (Consts.BinPath);
893                         p1 = engine.CreateNewProject ();
894                         p2 = engine.CreateNewProject ();
895
896                         p1.AddNewItem ("A", "B");
897                         p1.ItemGroups.CopyTo (groups, 0);
898
899                         p2.RemoveItemGroup (groups [0]);
900                 }
901
902                 [Test]
903                 [Category ("NotDotNet")]
904                 [ExpectedException (typeof (ArgumentNullException))]
905                 public void TestRemoveItem1 ()
906                 {
907                         Engine engine;
908                         Project project;
909
910                         engine = new Engine (Consts.BinPath);
911                         project = engine.CreateNewProject ();
912
913                         project.RemoveItem (null);
914                 }
915
916                 [Test]
917                 [ExpectedException (typeof (InvalidOperationException),
918                         "The object passed in is not part of the project.")]
919                 public void TestRemoveItem2 ()
920                 {
921                         Engine engine;
922                         Project project;
923
924                         engine = new Engine (Consts.BinPath);
925                         project = engine.CreateNewProject ();
926
927                         project.RemoveItem (new BuildItem ("name", "include"));
928                 }
929
930                 [Test]
931                 [ExpectedException (typeof (InvalidOperationException),
932                                         "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
933                 public void TestRemoveItem3 ()
934                 {
935                         Engine engine;
936                         Project p1;
937                         Project p2;
938
939                         engine = new Engine (Consts.BinPath);
940                         p1 = engine.CreateNewProject ();
941                         p2 = engine.CreateNewProject ();
942
943                         p1.AddNewItem ("A", "B");
944
945                         p2.RemoveItem (p1.EvaluatedItems [0]);
946                 }
947
948                 [Test]
949                 [Category ("NotDotNet")]
950                 [ExpectedException (typeof (InvalidOperationException))]
951                 public void TestRemoveItem4 ()
952                 {
953                         Engine engine;
954                         Project p1;
955                         Project p2;
956
957                         engine = new Engine (Consts.BinPath);
958                         p1 = engine.CreateNewProject ();
959                         p2 = engine.CreateNewProject ();
960
961                         p1.AddNewItem ("A", "B");
962                         p1.AddNewItem ("A", "C");
963
964                         p2.RemoveItem (p1.EvaluatedItems [0]);
965                 }
966
967                 [Test]
968                 public void TestRemoveItem5 ()
969                 {
970                         Engine engine;
971                         Project project;
972                         BuildItemGroup [] groups = new BuildItemGroup [1];
973
974                         string documentString = @"
975                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
976                                         <ItemGroup>
977                                                 <A Include='a'/>
978                                         </ItemGroup>
979                                 </Project>
980                         ";
981
982                         engine = new Engine (Consts.BinPath);
983                         project = engine.CreateNewProject ();
984                         project.LoadXml (documentString);
985
986                         project.RemoveItem (project.EvaluatedItems [0]);
987                         Assert.AreEqual (0, project.EvaluatedItems.Count, "A1");
988                         project.ItemGroups.CopyTo (groups, 0);
989                         Assert.IsNull (groups [0], "A2");
990                         Assert.AreEqual (0, project.ItemGroups.Count, "A3");
991                 }
992
993                 [Test]
994                 [Category ("NotWorking")]
995                 public void TestResetBuildStatus ()
996                 {
997                         Engine engine;
998                         Project project;
999
1000                         string documentString = @"
1001                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1002                                         <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
1003                                                 <Message Text='text' />
1004                                         </Target>
1005                                 </Project>
1006                         ";
1007
1008                         engine = new Engine (Consts.BinPath);
1009                         TestLogger tl = new TestLogger ();
1010                         engine.RegisterLogger (tl);
1011                         project = engine.CreateNewProject ();
1012                         project.LoadXml (documentString);
1013
1014                         project.Build ("T");
1015                         project.ResetBuildStatus ();
1016                         project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1017
1018                         Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
1019                         Assert.AreEqual (2, tl.TargetFinishedEvents, "A1");
1020                 }
1021                 
1022                 [Test]
1023                 public void TestSchemaFile ()
1024                 {
1025                         Engine engine;
1026                         Project project;
1027                         
1028                         string documentString = @"
1029                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1030                                 </Project>
1031                         ";
1032                         
1033                         engine = new Engine (Consts.BinPath);
1034                         project = engine.CreateNewProject ();
1035                         project.LoadXml (documentString);
1036
1037                         Assert.IsNull (project.SchemaFile, "A1");
1038                 }
1039                 [Test]
1040                 [Category ("NotDotNet")]
1041                 [ExpectedException (typeof (ArgumentNullException))]
1042                 public void TestSetProjectExtensions1 ()
1043                 {
1044                         Engine engine;
1045                         Project project;
1046
1047                         string documentString = @"
1048                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1049                                 </Project>
1050                         ";
1051
1052                         engine = new Engine (Consts.BinPath);
1053                         project = engine.CreateNewProject ();
1054                         project.LoadXml (documentString);
1055
1056                         project.SetProjectExtensions (null, null);
1057                 }
1058
1059                 [Test]
1060                 public void TestSetProjectExtensions2 ()
1061                 {
1062                         Engine engine;
1063                         Project project;
1064
1065                         string documentString = @"
1066                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1067                                 </Project>
1068                         ";
1069
1070                         engine = new Engine (Consts.BinPath);
1071                         project = engine.CreateNewProject ();
1072                         project.LoadXml (documentString);
1073
1074                         project.SetProjectExtensions ("name", "1");
1075                         Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1076                         project.SetProjectExtensions ("name", "2");
1077                         Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2");
1078                         Assert.IsTrue (project.IsDirty, "A3");
1079                 }
1080
1081                 [Test]
1082                 public void TestSetProjectExtensions3 ()
1083                 {
1084                         Engine engine;
1085                         Project project;
1086
1087                         string documentString = @"
1088                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1089                                         <ProjectExtensions>
1090                                         </ProjectExtensions>
1091                                 </Project>
1092                         ";
1093
1094                         engine = new Engine (Consts.BinPath);
1095                         project = engine.CreateNewProject ();
1096                         project.LoadXml (documentString);
1097
1098                         project.SetProjectExtensions ("name", "1");
1099                         Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1100                         Assert.IsTrue (project.IsDirty, "A2");
1101                 }
1102         }
1103 }