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 [Category ("NotWorking")]
201 public void TestAddNewItem2 ()
206 engine = new Engine (Consts.BinPath);
207 project = engine.CreateNewProject ();
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");
213 Assert.AreEqual (3, project.EvaluatedItems.Count, "A3");
217 public void TestAddNewItem3 ()
221 BuildItemGroup [] groups = new BuildItemGroup [4];
223 string documentString = @"
224 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
238 engine = new Engine (Consts.BinPath);
239 project = engine.CreateNewProject ();
240 project.LoadXml (documentString);
242 project.AddNewItem ("B", "b");
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");
251 public void TestAddNewItemGroup ()
256 string documentString = @"
257 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
261 engine = new Engine (Consts.BinPath);
262 project = engine.CreateNewProject ();
263 project.LoadXml (documentString);
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");
274 public void TestAddNewPropertyGroup ()
279 string documentString = @"
280 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
284 engine = new Engine (Consts.BinPath);
285 project = engine.CreateNewProject ();
286 project.LoadXml (documentString);
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");
297 [Category ("NotWorking")]
298 public void TestBuild1 ()
302 IDictionary hashtable = new Hashtable ();
304 string documentString = @"
305 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
307 <Microsoft.Build.Tasks.Message Text='Text' />
312 engine = new Engine (Consts.BinPath);
313 project = engine.CreateNewProject ();
314 project.LoadXml (documentString);
316 Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
317 Assert.AreEqual (1, hashtable.Count, "A2");
321 public void TestBuild2 ()
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' />
334 engine = new Engine (Consts.BinPath);
335 TestLogger tl = new TestLogger ();
336 engine.RegisterLogger (tl);
337 project = engine.CreateNewProject ();
338 project.LoadXml (documentString);
343 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
344 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
348 public void TestBuild3 ()
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' />
361 engine = new Engine (Consts.BinPath);
362 TestLogger tl = new TestLogger ();
363 engine.RegisterLogger (tl);
364 project = engine.CreateNewProject ();
365 project.LoadXml (documentString);
367 project.Build (new string [1] { "T" }, null, BuildSettings.None);
368 project.Build (new string [1] { "T" }, null, BuildSettings.None);
370 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
371 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
375 [Category ("NotWorking")]
376 public void TestBuild4 ()
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' />
389 engine = new Engine (Consts.BinPath);
390 TestLogger tl = new TestLogger ();
391 engine.RegisterLogger (tl);
392 project = engine.CreateNewProject ();
393 project.LoadXml (documentString);
395 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
396 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
398 Assert.AreEqual (1, tl.TargetStartedEvents, "A1");
399 Assert.AreEqual (1, tl.TargetFinishedEvents, "A2");
403 public void TestBuild5 ()
408 string documentString = @"
409 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
413 engine = new Engine (Consts.BinPath);
414 project = engine.CreateNewProject ();
415 project.LoadXml (documentString);
417 Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
421 public void TestEvaluatedItems1 ()
426 string documentString = @"
427 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
430 <B Include='b' Condition='false' />
435 engine = new Engine (Consts.BinPath);
436 project = engine.CreateNewProject ();
437 project.LoadXml (documentString);
439 Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
441 BuildItem bi = project.EvaluatedItems [0];
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");
453 public void TestEvaluatedItems2 ()
458 string documentString = @"
459 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
461 <A Include='a;b;c' />
466 engine = new Engine (Consts.BinPath);
467 project = engine.CreateNewProject ();
468 project.LoadXml (documentString);
470 BuildItemGroup [] big = new BuildItemGroup [1];
471 project.ItemGroups.CopyTo (big, 0);
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");
477 BuildItem bi = project.EvaluatedItems [0];
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");
488 [Category ("NotWorking")]
489 public void TestGetConditionedPropertyValues ()
494 string documentString = @"
495 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
496 <PropertyGroup Condition='true'>
498 <B Condition='true'>A</B>
501 <C Condition='true'>A</C>
502 <C Condition='false'>B</C>
503 <C Condition='!false'>C</C>
505 <E Condition="" '$(C)' == 'A' "">E</E>
510 engine = new Engine (Consts.BinPath);
511 project = engine.CreateNewProject ();
512 project.LoadXml (documentString);
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");
523 [ExpectedException (typeof (ArgumentNullException))]
524 public void TestGetEvaluatedItemsByName1 ()
529 string documentString = @"
530 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
534 engine = new Engine (Consts.BinPath);
535 project = engine.CreateNewProject ();
536 project.LoadXml (documentString);
538 project.GetEvaluatedItemsByName (null);
542 public void TestGetEvaluatedItemsByName2 ()
547 string documentString = @"
548 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
551 <B Include='2' Condition='true' />
552 <C Include='3' Condition='false' />
557 engine = new Engine (Consts.BinPath);
558 project = engine.CreateNewProject ();
559 project.LoadXml (documentString);
563 big = project.GetEvaluatedItemsByName (String.Empty);
565 Assert.AreEqual (0, big.Count, "A1");
567 big = project.GetEvaluatedItemsByName ("A");
569 Assert.AreEqual (1, big.Count, "A2");
570 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
572 big = project.GetEvaluatedItemsByName ("B");
574 Assert.AreEqual (1, big.Count, "A4");
575 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
577 big = project.GetEvaluatedItemsByName ("C");
579 Assert.AreEqual (0, big.Count, "A6");
583 [ExpectedException (typeof (ArgumentNullException))]
584 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
589 string documentString = @"
590 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
594 engine = new Engine (Consts.BinPath);
595 project = engine.CreateNewProject ();
596 project.LoadXml (documentString);
598 project.GetEvaluatedItemsByNameIgnoringCondition (null);
602 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
607 string documentString = @"
608 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
611 <B Include='2' Condition='true' />
612 <C Include='3' Condition='false' />
617 engine = new Engine (Consts.BinPath);
618 project = engine.CreateNewProject ();
619 project.LoadXml (documentString);
623 big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
625 Assert.AreEqual (0, big.Count, "A1");
627 big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
629 Assert.AreEqual (1, big.Count, "A2");
630 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
632 big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
634 Assert.AreEqual (1, big.Count, "A4");
635 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
637 big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
639 Assert.AreEqual (1, big.Count, "A6");
640 Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
644 [ExpectedException (typeof (ArgumentNullException))]
645 public void TestGetEvaluatedProperty1 ()
650 string documentString = @"
651 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
655 engine = new Engine (Consts.BinPath);
656 project = engine.CreateNewProject ();
657 project.LoadXml (documentString);
659 project.GetEvaluatedProperty (null);
662 public void TestGetEvaluatedProperty2 ()
667 string documentString = @"
668 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
671 <B Condition='true'>2</B>
672 <C Condition='false'>3</C>
677 engine = new Engine (Consts.BinPath);
678 project = engine.CreateNewProject ();
679 project.LoadXml (documentString);
681 Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
682 Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
683 Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
687 public void TestGetProjectExtensions ()
692 string documentString = @"
693 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
700 engine = new Engine (Consts.BinPath);
701 project = engine.CreateNewProject ();
702 project.LoadXml (documentString);
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");
711 public void TestGlobalProperties1 ()
716 string documentString = @"
717 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
721 engine = new Engine (Consts.BinPath);
722 project = engine.CreateNewProject ();
723 project.LoadXml (documentString);
725 Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
729 public void TestGlobalProperties2 ()
734 string documentString = @"
735 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
739 engine = new Engine (Consts.BinPath);
740 engine.GlobalProperties.SetProperty ("Property", "Value");
742 project = engine.CreateNewProject ();
743 project.LoadXml (documentString);
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");
755 [Category ("NotDotNet")]
756 [ExpectedException (typeof (ArgumentNullException))]
757 public void TestGlobalProperties3 ()
762 string documentString = @"
763 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
767 engine = new Engine (Consts.BinPath);
768 project = engine.CreateNewProject ();
769 project.LoadXml (documentString);
771 project.GlobalProperties = null;
775 [Ignore ("needs rewriting")]
776 public void TestGlobalProperties4 ()
781 string documentString = @"
782 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
784 <Property>a</Property>
789 engine = new Engine (Consts.BinPath);
790 project = engine.CreateNewProject ();
791 project.LoadXml (documentString);
793 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
794 project.PropertyGroups.CopyTo (groups, 0);
796 project.GlobalProperties = groups [0];
797 project.GlobalProperties = project.EvaluatedProperties;
801 [Category ("NotDotNet")]
802 [ExpectedException (typeof (InvalidOperationException))]
803 public void TestGlobalProperties5 ()
808 string documentString = @"
809 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
811 <Property>a</Property>
816 engine = new Engine (Consts.BinPath);
817 project = engine.CreateNewProject ();
818 project.LoadXml (documentString);
820 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
821 project.PropertyGroups.CopyTo (groups, 0);
822 project.GlobalProperties = groups [0];
826 [ExpectedException (typeof (InvalidProjectFileException))]
827 public void TestLoad1 ()
832 string documentString = @"
833 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
838 engine = new Engine (Consts.BinPath);
839 project = engine.CreateNewProject ();
840 project.LoadXml (documentString);
844 [ExpectedException (typeof (InvalidProjectFileException))]
845 public void TestLoad2 ()
850 engine = new Engine (Consts.BinPath);
851 project = engine.CreateNewProject ();
852 project.LoadXml ("project_file_that_doesnt_exist");
856 public void TestParentEngine ()
861 engine = new Engine (Consts.BinPath);
862 project = engine.CreateNewProject ();
864 Assert.AreEqual (engine, project.ParentEngine, "A1");
868 [Category ("NotDotNet")]
869 [ExpectedException (typeof (ArgumentNullException))]
870 public void TestRemoveItemGroup1 ()
875 engine = new Engine (Consts.BinPath);
876 p1 = engine.CreateNewProject ();
878 p1.RemoveItemGroup (null);
882 [ExpectedException (typeof (InvalidOperationException),
883 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
884 [Category ("NotWorking")]
885 public void TestRemoveItemGroup2 ()
890 BuildItemGroup [] groups = new BuildItemGroup [1];
892 engine = new Engine (Consts.BinPath);
893 p1 = engine.CreateNewProject ();
894 p2 = engine.CreateNewProject ();
896 p1.AddNewItem ("A", "B");
897 p1.ItemGroups.CopyTo (groups, 0);
899 p2.RemoveItemGroup (groups [0]);
903 [Category ("NotDotNet")]
904 [ExpectedException (typeof (ArgumentNullException))]
905 public void TestRemoveItem1 ()
910 engine = new Engine (Consts.BinPath);
911 project = engine.CreateNewProject ();
913 project.RemoveItem (null);
917 [ExpectedException (typeof (InvalidOperationException),
918 "The object passed in is not part of the project.")]
919 public void TestRemoveItem2 ()
924 engine = new Engine (Consts.BinPath);
925 project = engine.CreateNewProject ();
927 project.RemoveItem (new BuildItem ("name", "include"));
931 [ExpectedException (typeof (InvalidOperationException),
932 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
933 public void TestRemoveItem3 ()
939 engine = new Engine (Consts.BinPath);
940 p1 = engine.CreateNewProject ();
941 p2 = engine.CreateNewProject ();
943 p1.AddNewItem ("A", "B");
945 p2.RemoveItem (p1.EvaluatedItems [0]);
949 [Category ("NotDotNet")]
950 [ExpectedException (typeof (InvalidOperationException))]
951 public void TestRemoveItem4 ()
957 engine = new Engine (Consts.BinPath);
958 p1 = engine.CreateNewProject ();
959 p2 = engine.CreateNewProject ();
961 p1.AddNewItem ("A", "B");
962 p1.AddNewItem ("A", "C");
964 p2.RemoveItem (p1.EvaluatedItems [0]);
968 public void TestRemoveItem5 ()
972 BuildItemGroup [] groups = new BuildItemGroup [1];
974 string documentString = @"
975 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
982 engine = new Engine (Consts.BinPath);
983 project = engine.CreateNewProject ();
984 project.LoadXml (documentString);
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");
994 [Category ("NotWorking")]
995 public void TestResetBuildStatus ()
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' />
1008 engine = new Engine (Consts.BinPath);
1009 TestLogger tl = new TestLogger ();
1010 engine.RegisterLogger (tl);
1011 project = engine.CreateNewProject ();
1012 project.LoadXml (documentString);
1014 project.Build ("T");
1015 project.ResetBuildStatus ();
1016 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1018 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
1019 Assert.AreEqual (2, tl.TargetFinishedEvents, "A1");
1023 public void TestSchemaFile ()
1028 string documentString = @"
1029 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1033 engine = new Engine (Consts.BinPath);
1034 project = engine.CreateNewProject ();
1035 project.LoadXml (documentString);
1037 Assert.IsNull (project.SchemaFile, "A1");
1040 [Category ("NotDotNet")]
1041 [ExpectedException (typeof (ArgumentNullException))]
1042 public void TestSetProjectExtensions1 ()
1047 string documentString = @"
1048 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1052 engine = new Engine (Consts.BinPath);
1053 project = engine.CreateNewProject ();
1054 project.LoadXml (documentString);
1056 project.SetProjectExtensions (null, null);
1060 public void TestSetProjectExtensions2 ()
1065 string documentString = @"
1066 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1070 engine = new Engine (Consts.BinPath);
1071 project = engine.CreateNewProject ();
1072 project.LoadXml (documentString);
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");
1082 public void TestSetProjectExtensions3 ()
1087 string documentString = @"
1088 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1090 </ProjectExtensions>
1094 engine = new Engine (Consts.BinPath);
1095 project = engine.CreateNewProject ();
1096 project.LoadXml (documentString);
1098 project.SetProjectExtensions ("name", "1");
1099 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1100 Assert.IsTrue (project.IsDirty, "A2");