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.
29 using System.Collections;
30 using System.Collections.Generic;
32 using Microsoft.Build.BuildEngine;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
37 namespace MonoTests.Microsoft.Build.BuildEngine {
39 class TestLogger : Logger {
40 int target_started_events = 0;
41 int target_finished_events = 0;
43 public override void Initialize (IEventSource eventSource)
45 eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted);
46 eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished);
47 eventSource.MessageRaised += new BuildMessageEventHandler(Message);
48 eventSource.WarningRaised += new BuildWarningEventHandler(Warning);
51 void TargetStarted (object sender, TargetStartedEventArgs args)
53 target_started_events++;
56 void TargetFinished (object sender, TargetFinishedEventArgs args)
58 target_finished_events++;
61 void Message (object sender, BuildMessageEventArgs args)
65 void Warning (object sender, BuildWarningEventArgs args)
69 public int TargetStartedEvents { get { return target_started_events; } }
71 public int TargetFinishedEvents { get { return target_finished_events; } }
75 public class ProjectTest {
78 Import [] GetImports (ImportCollection ic)
80 List<Import> list = new List<Import> ();
81 foreach (Import i in ic)
83 return list.ToArray ();
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 ()
97 string documentString =
98 "<Project></Project>";
100 engine = new Engine (Consts.BinPath);
101 DateTime time = DateTime.Now;
102 project = engine.CreateNewProject ();
103 project.LoadXml (documentString);
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");
116 public void TestAssignment2 ()
120 string documentString =
121 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>";
123 engine = new Engine (Consts.BinPath);
124 DateTime time = DateTime.Now;
125 project = engine.CreateNewProject ();
126 project.LoadXml (documentString);
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");
139 [Category ("NotWorking")]
140 public void TestAddNewImport1 ()
145 string documentString = @"
146 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
150 <Import Project='Test/resources/Import.csproj' />
154 engine = new Engine (Consts.BinPath);
155 project = engine.CreateNewProject ();
156 project.LoadXml (documentString);
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");
164 [Ignore ("Too detailed probably (implementation specific)")]
165 public void TestAddNewItem1 ()
169 BuildItemGroup [] groups = new BuildItemGroup [1];
171 string documentString = @"
172 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
176 engine = new Engine (Consts.BinPath);
177 project = engine.CreateNewProject ();
178 project.LoadXml (documentString);
180 BuildItem item = project.AddNewItem ("A", "B");
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");
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");
200 public void TestAddNewItemGroup ()
205 string documentString = @"
206 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
210 engine = new Engine (Consts.BinPath);
211 project = engine.CreateNewProject ();
212 project.LoadXml (documentString);
214 BuildItemGroup big = project.AddNewItemGroup ();
215 Assert.IsNotNull (big, "A1");
216 Assert.AreEqual (String.Empty, big.Condition, "A2");
217 Assert.AreEqual (0, big.Count, "A3");
218 Assert.AreEqual (false, big.IsImported, "A4");
219 Assert.IsTrue (project.IsDirty, "A5");
223 public void TestAddNewPropertyGroup ()
228 string documentString = @"
229 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
233 engine = new Engine (Consts.BinPath);
234 project = engine.CreateNewProject ();
235 project.LoadXml (documentString);
237 BuildPropertyGroup bpg = project.AddNewPropertyGroup (false);
238 Assert.IsNotNull (bpg, "A1");
239 Assert.AreEqual (String.Empty, bpg.Condition, "A2");
240 Assert.AreEqual (0, bpg.Count, "A3");
241 Assert.AreEqual (false, bpg.IsImported, "A4");
242 Assert.IsTrue (project.IsDirty, "A5");
246 [Category ("NotWorking")]
247 public void TestBuild1 ()
251 IDictionary hashtable = new Hashtable ();
253 string documentString = @"
254 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
256 <Microsoft.Build.Tasks.Message Text='Text' />
261 engine = new Engine (Consts.BinPath);
262 project = engine.CreateNewProject ();
263 project.LoadXml (documentString);
265 Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
266 Assert.AreEqual (1, hashtable.Count, "A2");
270 public void TestBuild2 ()
275 string documentString = @"
276 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
277 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
278 <Message Text='text' />
283 engine = new Engine (Consts.BinPath);
284 TestLogger tl = new TestLogger ();
285 engine.RegisterLogger (tl);
286 project = engine.CreateNewProject ();
287 project.LoadXml (documentString);
292 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
293 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
297 public void TestBuild3 ()
302 string documentString = @"
303 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
304 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
305 <Message Text='text' />
310 engine = new Engine (Consts.BinPath);
311 TestLogger tl = new TestLogger ();
312 engine.RegisterLogger (tl);
313 project = engine.CreateNewProject ();
314 project.LoadXml (documentString);
316 project.Build (new string [1] { "T" }, null, BuildSettings.None);
317 project.Build (new string [1] { "T" }, null, BuildSettings.None);
319 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
320 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
324 [Category ("NotWorking")]
325 public void TestBuild4 ()
330 string documentString = @"
331 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
332 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
333 <Message Text='text' />
338 engine = new Engine (Consts.BinPath);
339 TestLogger tl = new TestLogger ();
340 engine.RegisterLogger (tl);
341 project = engine.CreateNewProject ();
342 project.LoadXml (documentString);
344 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
345 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
347 Assert.AreEqual (1, tl.TargetStartedEvents, "A1");
348 Assert.AreEqual (1, tl.TargetFinishedEvents, "A2");
352 public void TestBuild5 ()
357 string documentString = @"
358 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
362 engine = new Engine (Consts.BinPath);
363 project = engine.CreateNewProject ();
364 project.LoadXml (documentString);
366 Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
370 public void TestEvaluatedItems1 ()
375 string documentString = @"
376 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
379 <B Include='b' Condition='false' />
384 engine = new Engine (Consts.BinPath);
385 project = engine.CreateNewProject ();
386 project.LoadXml (documentString);
388 Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
390 BuildItem bi = project.EvaluatedItems [0];
395 BuildItemGroup [] big = new BuildItemGroup [1];
396 project.ItemGroups.CopyTo (big, 0);
397 Assert.AreEqual ("C", big [0] [0].Name, "A2");
398 Assert.AreEqual ("c", big [0] [0].Include, "A3");
402 public void TestEvaluatedItems2 ()
407 string documentString = @"
408 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
410 <A Include='a;b;c' />
415 engine = new Engine (Consts.BinPath);
416 project = engine.CreateNewProject ();
417 project.LoadXml (documentString);
419 BuildItemGroup [] big = new BuildItemGroup [1];
420 project.ItemGroups.CopyTo (big, 0);
422 Assert.AreEqual (3, project.EvaluatedItems.Count, "A1");
423 Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2");
424 Assert.AreEqual (1, big [0].Count, "A3");
426 BuildItem bi = project.EvaluatedItems [0];
430 Assert.AreEqual (3, big [0].Count, "A4");
431 Assert.AreEqual ("d", big [0] [0].Include, "A5");
432 Assert.AreEqual ("b", big [0] [1].Include, "A6");
433 Assert.AreEqual ("c", big [0] [2].Include, "A7");
437 [Category ("NotWorking")]
438 public void TestGetConditionedPropertyValues ()
443 string documentString = @"
444 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
445 <PropertyGroup Condition='true'>
447 <B Condition='true'>A</B>
450 <C Condition='true'>A</C>
451 <C Condition='false'>B</C>
452 <C Condition='!false'>C</C>
454 <E Condition="" '$(C)' == 'A' "">E</E>
459 engine = new Engine (Consts.BinPath);
460 project = engine.CreateNewProject ();
461 project.LoadXml (documentString);
463 Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1");
464 Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2");
465 Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3");
466 Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4");
467 Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5");
468 Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6");
472 [ExpectedException (typeof (ArgumentNullException))]
473 public void TestGetEvaluatedItemsByName1 ()
478 string documentString = @"
479 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
483 engine = new Engine (Consts.BinPath);
484 project = engine.CreateNewProject ();
485 project.LoadXml (documentString);
487 project.GetEvaluatedItemsByName (null);
491 public void TestGetEvaluatedItemsByName2 ()
496 string documentString = @"
497 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
500 <B Include='2' Condition='true' />
501 <C Include='3' Condition='false' />
506 engine = new Engine (Consts.BinPath);
507 project = engine.CreateNewProject ();
508 project.LoadXml (documentString);
512 big = project.GetEvaluatedItemsByName (String.Empty);
514 Assert.AreEqual (0, big.Count, "A1");
516 big = project.GetEvaluatedItemsByName ("A");
518 Assert.AreEqual (1, big.Count, "A2");
519 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
521 big = project.GetEvaluatedItemsByName ("B");
523 Assert.AreEqual (1, big.Count, "A4");
524 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
526 big = project.GetEvaluatedItemsByName ("C");
528 Assert.AreEqual (0, big.Count, "A6");
532 [ExpectedException (typeof (ArgumentNullException))]
533 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
538 string documentString = @"
539 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
543 engine = new Engine (Consts.BinPath);
544 project = engine.CreateNewProject ();
545 project.LoadXml (documentString);
547 project.GetEvaluatedItemsByNameIgnoringCondition (null);
551 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
556 string documentString = @"
557 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
560 <B Include='2' Condition='true' />
561 <C Include='3' Condition='false' />
566 engine = new Engine (Consts.BinPath);
567 project = engine.CreateNewProject ();
568 project.LoadXml (documentString);
572 big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
574 Assert.AreEqual (0, big.Count, "A1");
576 big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
578 Assert.AreEqual (1, big.Count, "A2");
579 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
581 big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
583 Assert.AreEqual (1, big.Count, "A4");
584 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
586 big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
588 Assert.AreEqual (1, big.Count, "A6");
589 Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
593 [ExpectedException (typeof (ArgumentNullException))]
594 public void TestGetEvaluatedProperty1 ()
599 string documentString = @"
600 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
604 engine = new Engine (Consts.BinPath);
605 project = engine.CreateNewProject ();
606 project.LoadXml (documentString);
608 project.GetEvaluatedProperty (null);
611 public void TestGetEvaluatedProperty2 ()
616 string documentString = @"
617 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
620 <B Condition='true'>2</B>
621 <C Condition='false'>3</C>
626 engine = new Engine (Consts.BinPath);
627 project = engine.CreateNewProject ();
628 project.LoadXml (documentString);
630 Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
631 Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
632 Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
636 public void TestGetProjectExtensions ()
641 string documentString = @"
642 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
649 engine = new Engine (Consts.BinPath);
650 project = engine.CreateNewProject ();
651 project.LoadXml (documentString);
653 Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1");
654 Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2");
655 Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3");
656 Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4");
660 public void TestGlobalProperties1 ()
665 string documentString = @"
666 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
670 engine = new Engine (Consts.BinPath);
671 project = engine.CreateNewProject ();
672 project.LoadXml (documentString);
674 Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
678 public void TestGlobalProperties2 ()
683 string documentString = @"
684 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
688 engine = new Engine (Consts.BinPath);
689 engine.GlobalProperties.SetProperty ("Property", "Value");
691 project = engine.CreateNewProject ();
692 project.LoadXml (documentString);
694 Assert.AreEqual (1, project.GlobalProperties.Count, "A1");
695 Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2");
696 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3");
697 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4");
698 Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2");
699 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3");
700 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4");
704 [Category ("NotDotNet")]
705 [ExpectedException (typeof (ArgumentNullException))]
706 public void TestGlobalProperties3 ()
711 string documentString = @"
712 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
716 engine = new Engine (Consts.BinPath);
717 project = engine.CreateNewProject ();
718 project.LoadXml (documentString);
720 project.GlobalProperties = null;
724 [Ignore ("needs rewriting")]
725 public void TestGlobalProperties4 ()
730 string documentString = @"
731 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
733 <Property>a</Property>
738 engine = new Engine (Consts.BinPath);
739 project = engine.CreateNewProject ();
740 project.LoadXml (documentString);
742 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
743 project.PropertyGroups.CopyTo (groups, 0);
745 project.GlobalProperties = groups [0];
746 project.GlobalProperties = project.EvaluatedProperties;
750 [Category ("NotDotNet")]
751 [ExpectedException (typeof (InvalidOperationException))]
752 public void TestGlobalProperties5 ()
757 string documentString = @"
758 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
760 <Property>a</Property>
765 engine = new Engine (Consts.BinPath);
766 project = engine.CreateNewProject ();
767 project.LoadXml (documentString);
769 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
770 project.PropertyGroups.CopyTo (groups, 0);
771 project.GlobalProperties = groups [0];
775 [ExpectedException (typeof (InvalidProjectFileException))]
776 public void TestLoad1 ()
781 string documentString = @"
782 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
787 engine = new Engine (Consts.BinPath);
788 project = engine.CreateNewProject ();
789 project.LoadXml (documentString);
793 [ExpectedException (typeof (InvalidProjectFileException))]
794 public void TestLoad2 ()
799 engine = new Engine (Consts.BinPath);
800 project = engine.CreateNewProject ();
801 project.LoadXml ("project_file_that_doesnt_exist");
805 public void TestParentEngine ()
810 engine = new Engine (Consts.BinPath);
811 project = engine.CreateNewProject ();
813 Assert.AreEqual (engine, project.ParentEngine, "A1");
817 [Category ("NotDotNet")]
818 [ExpectedException (typeof (ArgumentNullException))]
819 public void TestRemoveItemGroup1 ()
824 engine = new Engine (Consts.BinPath);
825 p1 = engine.CreateNewProject ();
827 p1.RemoveItemGroup (null);
831 [ExpectedException (typeof (InvalidOperationException),
832 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
833 [Category ("NotWorking")]
834 public void TestRemoveItemGroup2 ()
839 BuildItemGroup [] groups = new BuildItemGroup [1];
841 engine = new Engine (Consts.BinPath);
842 p1 = engine.CreateNewProject ();
843 p2 = engine.CreateNewProject ();
845 p1.AddNewItem ("A", "B");
846 p1.ItemGroups.CopyTo (groups, 0);
848 p2.RemoveItemGroup (groups [0]);
852 [Category ("NotDotNet")]
853 [ExpectedException (typeof (ArgumentNullException))]
854 public void TestRemoveItem1 ()
859 engine = new Engine (Consts.BinPath);
860 project = engine.CreateNewProject ();
862 project.RemoveItem (null);
866 [ExpectedException (typeof (InvalidOperationException),
867 "The object passed in is not part of the project.")]
868 public void TestRemoveItem2 ()
873 engine = new Engine (Consts.BinPath);
874 project = engine.CreateNewProject ();
876 project.RemoveItem (new BuildItem ("name", "include"));
880 [ExpectedException (typeof (InvalidOperationException),
881 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
882 public void TestRemoveItem3 ()
888 engine = new Engine (Consts.BinPath);
889 p1 = engine.CreateNewProject ();
890 p2 = engine.CreateNewProject ();
892 p1.AddNewItem ("A", "B");
894 p2.RemoveItem (p1.EvaluatedItems [0]);
898 [Category ("NotDotNet")]
899 [ExpectedException (typeof (InvalidOperationException))]
900 public void TestRemoveItem4 ()
906 engine = new Engine (Consts.BinPath);
907 p1 = engine.CreateNewProject ();
908 p2 = engine.CreateNewProject ();
910 p1.AddNewItem ("A", "B");
911 p1.AddNewItem ("A", "C");
913 p2.RemoveItem (p1.EvaluatedItems [0]);
917 public void TestRemoveItem5 ()
921 BuildItemGroup [] groups = new BuildItemGroup [1];
923 string documentString = @"
924 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
931 engine = new Engine (Consts.BinPath);
932 project = engine.CreateNewProject ();
933 project.LoadXml (documentString);
935 project.RemoveItem (project.EvaluatedItems [0]);
936 Assert.AreEqual (0, project.EvaluatedItems.Count, "A1");
937 project.ItemGroups.CopyTo (groups, 0);
938 Assert.IsNull (groups [0], "A2");
939 Assert.AreEqual (0, project.ItemGroups.Count, "A3");
943 [Category ("NotWorking")]
944 public void TestResetBuildStatus ()
949 string documentString = @"
950 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
951 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
952 <Message Text='text' />
957 engine = new Engine (Consts.BinPath);
958 TestLogger tl = new TestLogger ();
959 engine.RegisterLogger (tl);
960 project = engine.CreateNewProject ();
961 project.LoadXml (documentString);
964 project.ResetBuildStatus ();
965 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
967 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
968 Assert.AreEqual (2, tl.TargetFinishedEvents, "A1");
972 public void TestSchemaFile ()
977 string documentString = @"
978 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
982 engine = new Engine (Consts.BinPath);
983 project = engine.CreateNewProject ();
984 project.LoadXml (documentString);
986 Assert.IsNull (project.SchemaFile, "A1");
989 [Category ("NotDotNet")]
990 [ExpectedException (typeof (ArgumentNullException))]
991 public void TestSetProjectExtensions1 ()
996 string documentString = @"
997 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1001 engine = new Engine (Consts.BinPath);
1002 project = engine.CreateNewProject ();
1003 project.LoadXml (documentString);
1005 project.SetProjectExtensions (null, null);
1009 public void TestSetProjectExtensions2 ()
1014 string documentString = @"
1015 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1019 engine = new Engine (Consts.BinPath);
1020 project = engine.CreateNewProject ();
1021 project.LoadXml (documentString);
1023 project.SetProjectExtensions ("name", "1");
1024 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1025 project.SetProjectExtensions ("name", "2");
1026 Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2");
1027 Assert.IsTrue (project.IsDirty, "A3");
1031 public void TestSetProjectExtensions3 ()
1036 string documentString = @"
1037 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1039 </ProjectExtensions>
1043 engine = new Engine (Consts.BinPath);
1044 project = engine.CreateNewProject ();
1045 project.LoadXml (documentString);
1047 project.SetProjectExtensions ("name", "1");
1048 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1049 Assert.IsTrue (project.IsDirty, "A2");