Merge pull request #2388 from BrzVlad/feature-los-caching
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / BuildItemGroupTest.cs
1 //
2 // BuildItemGroupTest.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.Xml;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Utilities;
34 using NUnit.Framework;
35
36 namespace MonoTests.Microsoft.Build.BuildEngine {
37         [TestFixture]
38         public class BuildItemGroupTest {
39                 [Test]
40                 public void TestCtor ()
41                 {
42                         BuildItemGroup big = new BuildItemGroup ();
43
44                         Assert.AreEqual (String.Empty, big.Condition, "A1");
45                         Assert.AreEqual (0, big.Count, "A2");
46                         Assert.IsFalse (big.IsImported, "A3");
47                 }
48
49                 [Test]
50                 public void TestAddNewItem1 ()
51                 {
52                         string name = "name";
53                         string include = "a;b;c";
54                         
55                         BuildItemGroup big = new BuildItemGroup ();
56                         BuildItem bi = big.AddNewItem (name, include);
57
58                         Assert.AreEqual (String.Empty, bi.Condition, "A1");
59                         Assert.AreEqual (String.Empty, bi.Exclude, "A2");
60                         Assert.AreEqual (include, bi.FinalItemSpec, "A3");
61                         Assert.AreEqual (include, bi.Include, "A4");
62                         Assert.IsFalse (bi.IsImported, "A5");
63                         Assert.AreEqual (name, bi.Name, "A6");
64                         Assert.AreEqual (1, big.Count, "A7");
65                 }
66
67                 [Test]
68                 public void TestAddNewItem2 ()
69                 {
70                         Engine engine;
71                         Project project;
72                         string name = "name";
73                         string include = "$(Property)";
74                         
75                         string documentString = @"
76                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
77                                         <PropertyGroup>
78                                                 <Property>a</Property>
79                                         </PropertyGroup>
80                                 </Project>
81                         ";
82                         
83                         engine = new Engine (Consts.BinPath);
84                         project = engine.CreateNewProject ();
85                         project.LoadXml (documentString);
86
87                         BuildItem bi = project.EvaluatedItems.AddNewItem (name, include, true);
88
89                         Assert.AreEqual (String.Empty, bi.Condition, "A1");
90                         Assert.AreEqual (String.Empty, bi.Exclude, "A2");
91                         Assert.AreEqual (include, bi.FinalItemSpec, "A3");
92                         Assert.AreEqual (Utilities.Escape (include), bi.Include, "A4");
93                         Assert.IsFalse (bi.IsImported, "A5");
94                         Assert.AreEqual (name, bi.Name, "A6");
95
96                         bi = project.EvaluatedItems.AddNewItem (name, include, false);
97
98                         Assert.AreEqual (String.Empty, bi.Condition, "A7");
99                         Assert.AreEqual (String.Empty, bi.Exclude, "A8");
100                         Assert.AreEqual (include, bi.FinalItemSpec, "A9");
101                         Assert.AreEqual (include, bi.Include, "A10");
102                         Assert.IsFalse (bi.IsImported, "A11");
103                         Assert.AreEqual (name, bi.Name, "A12");
104                 }
105
106                 [Test]
107                 public void TestAddNewItem3 ()
108                 {
109                         Engine engine;
110                         Project project;
111                         string name = "name";
112                         string include = "$(Property)";
113
114                         string documentString = @"
115                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
116                                         <PropertyGroup>
117                                                 <Property>a</Property>
118                                         </PropertyGroup>
119                                 </Project>
120                         ";
121
122                         engine = new Engine (Consts.BinPath);
123                         project = engine.CreateNewProject ();
124                         project.LoadXml (documentString);
125
126                         BuildItem bi = project.EvaluatedItems.AddNewItem (name, include, true);
127
128                         Assert.AreEqual (String.Empty, bi.Condition, "A1");
129                         Assert.AreEqual (String.Empty, bi.Exclude, "A2");
130                         Assert.AreEqual (include, bi.FinalItemSpec, "A3");
131                         Assert.AreEqual (Utilities.Escape (include), bi.Include, "A4");
132                         Assert.IsFalse (bi.IsImported, "A5");
133                         Assert.AreEqual (name, bi.Name, "A6");
134
135                         bi = project.EvaluatedItems.AddNewItem (name, include, false);
136
137                         Assert.AreEqual (String.Empty, bi.Condition, "A7");
138                         Assert.AreEqual (String.Empty, bi.Exclude, "A8");
139                         Assert.AreEqual (include, bi.FinalItemSpec, "A9");
140                         Assert.AreEqual (include, bi.Include, "A10");
141                         Assert.IsFalse (bi.IsImported, "A11");
142                         Assert.AreEqual (name, bi.Name, "A12");
143
144                         Assert.AreEqual (0, project.EvaluatedItems.Count, "A13");
145
146                         project.GlobalProperties.SetProperty ("a", "b");
147
148                         Assert.AreEqual (0, project.EvaluatedItems.Count, "A14");
149                 }
150
151                 [Test]
152                 public void TestAddNewItem4 ()
153                 {
154                         Engine engine;
155                         Project project;
156
157                         string documentString = @"
158                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
159                                 </Project>
160                         ";
161
162                         engine = new Engine (Consts.BinPath);
163                         project = engine.CreateNewProject ();
164                         project.LoadXml (documentString);
165
166                         project.EvaluatedItems.AddNewItem ("I1", "Value");
167
168                         BuildItem bi = project.EvaluatedItems.AddNewItem ("I2", "@(I1)");
169
170                         Assert.AreEqual ("@(I1)", bi.FinalItemSpec, "A1");
171                         Assert.AreEqual ("@(I1)", bi.Include, "A2");
172                         Assert.AreEqual (0, project.EvaluatedItems.Count, "A3");
173                 }
174
175                 [Test]
176                 public void TestAddNewItem5 ()
177                 {
178                         BuildItemGroup big = new BuildItemGroup ();
179
180                         big.AddNewItem ("I1", "Value");
181
182                         BuildItem bi = big.AddNewItem ("I2", "@(I1)");
183
184                         Assert.AreEqual ("@(I1)", bi.FinalItemSpec, "A1");
185                         Assert.AreEqual ("@(I1)", bi.Include, "A2");
186                         Assert.AreEqual (2, big.Count, "A3");
187                 }
188
189                 [Test]
190                 public void TestAddNewItem6 ()
191                 {
192                         Engine engine;
193                         Project project;
194                         string name = "name";
195                         string include = "include";
196                         BuildItemGroup [] groups = new BuildItemGroup [1];
197
198                         string documentString = @"
199                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
200                                         <ItemGroup />
201                                 </Project>
202                         ";
203
204                         engine = new Engine (Consts.BinPath);
205                         project = engine.CreateNewProject ();
206                         project.LoadXml (documentString);
207
208                         project.ItemGroups.CopyTo (groups, 0);
209                         BuildItem bi = groups [0].AddNewItem (name, include, true);
210
211                         Assert.AreEqual (String.Empty, bi.Condition, "A1");
212                         Assert.AreEqual (String.Empty, bi.Exclude, "A2");
213                         Assert.AreEqual (include, bi.FinalItemSpec, "A3");
214                         Assert.AreEqual (Utilities.Escape (include), bi.Include, "A4");
215                         Assert.IsFalse (bi.IsImported, "A5");
216                         Assert.AreEqual (name, bi.Name, "A6");
217                         //Assert.AreSame (bi, groups [0] [0], "A7");
218                         Assert.IsTrue (object.ReferenceEquals (bi, groups [0][0]), "A7");
219                         //Assert.AreNotSame (bi, project.EvaluatedItems [0], "A8");
220                         Assert.IsFalse (object.ReferenceEquals (bi, project.EvaluatedItems [0]), "A8");
221                 }
222
223                 [Test]
224                 public void TestClear1 ()
225                 {
226                         BuildItemGroup big = new BuildItemGroup ();
227                         big.AddNewItem ("a", "a");
228                         big.AddNewItem ("b", "a");
229
230                         Assert.AreEqual (2, big.Count, "A1");
231                         
232                         big.Clear ();
233
234                         Assert.AreEqual (0, big.Count, "A2");
235                 }
236
237                 [Test]
238                 public void TestClear2 ()
239                 {
240                         Engine engine;
241                         Project project;
242                         XmlDocument xd;
243                         XmlNode node;
244                         string documentString = @"
245                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
246                                         <ItemGroup>
247                                                 <Item Include='a' />
248                                         </ItemGroup>
249                                 </Project>
250                         ";
251
252                         engine = new Engine (Consts.BinPath);
253                         project = engine.CreateNewProject ();
254                         project.LoadXml (documentString);
255
256                         xd = new XmlDocument ();
257                         xd.LoadXml (project.Xml);
258                         node = xd.SelectSingleNode ("tns:Project/tns:ItemGroup/*", TestNamespaceManager.NamespaceManager);
259                         Assert.IsNotNull (node, "A1");
260
261                         BuildItemGroup [] big = new BuildItemGroup [1];
262                         project.ItemGroups.CopyTo (big, 0);
263                         big [0].Clear ();
264
265                         Assert.AreEqual (0, big [0].Count, "A2");
266                         xd = new XmlDocument ();
267                         xd.LoadXml (project.Xml);
268                         node = xd.SelectSingleNode ("tns:Project/tns:ItemGroup/*", TestNamespaceManager.NamespaceManager);
269                         Assert.IsNull (node, "A3");
270                 }
271                 [Test]
272                 [Category ("NotWorking")]
273                 public void TestClone1 ()
274                 {
275                         BuildItemGroup big = new BuildItemGroup ();
276                         big.AddNewItem ("a", "a");
277                         big.AddNewItem ("b", "a");
278
279                         BuildItemGroup big2 = big.Clone (false);
280                         BuildItem[] items = big2.ToArray ();
281
282                         Assert.AreEqual (2, big2.Count, "A1");
283
284                         Assert.AreEqual (String.Empty, items [0].Condition, "A2");
285                         Assert.AreEqual (String.Empty, items [0].Exclude, "A3");
286                         Assert.AreEqual ("a", items [0].FinalItemSpec, "A4");
287                         Assert.AreEqual ("a", items [0].Include, "A5");
288                         Assert.IsFalse (items [0].IsImported, "A6");
289                         Assert.AreEqual ("a", items [0].Name, "A7");
290                         
291                         Assert.AreEqual (String.Empty, items [1].Condition, "A8");
292                         Assert.AreEqual (String.Empty, items [1].Exclude, "A9");
293                         Assert.AreEqual ("a", items [1].FinalItemSpec, "A10");
294                         Assert.AreEqual ("a", items [1].Include, "A11");
295                         Assert.IsFalse (items [1].IsImported, "A12");
296                         Assert.AreEqual ("b", items [1].Name, "A13");
297                 }
298
299                 [Test]
300                 [Category ("NotWorking")]
301                 public void TestClone2 ()
302                 {
303                         BuildItemGroup big = new BuildItemGroup ();
304                         big.AddNewItem ("a", "a");
305                         big.AddNewItem ("b", "a");
306
307                         BuildItemGroup big2 = big.Clone (true);
308                         BuildItem[] items = big2.ToArray ();
309
310                         Assert.AreEqual (2, big2.Count, "A1");
311
312                         Assert.AreEqual (String.Empty, items [0].Condition, "A2");
313                         Assert.AreEqual (String.Empty, items [0].Exclude, "A3");
314                         Assert.AreEqual ("a", items [0].FinalItemSpec, "A4");
315                         Assert.AreEqual ("a", items [0].Include, "A5");
316                         Assert.IsFalse (items [0].IsImported, "A6");
317                         Assert.AreEqual ("a", items [0].Name, "A7");
318                         
319                         Assert.AreEqual (String.Empty, items [1].Condition, "A8");
320                         Assert.AreEqual (String.Empty, items [1].Exclude, "A9");
321                         Assert.AreEqual ("a", items [1].FinalItemSpec, "A10");
322                         Assert.AreEqual ("a", items [1].Include, "A11");
323                         Assert.IsFalse (items [1].IsImported, "A12");
324                         Assert.AreEqual ("b", items [1].Name, "A13");
325                 }
326
327                 [Test]
328                 [Category ("NotWorking")]
329                 public void TestClone3 ()
330                 {
331                         Engine engine;
332                         Project project;
333                         
334                         string documentString = @"
335                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
336                                         <ItemGroup>
337                                                 <Item Include='a' />
338                                         </ItemGroup>
339                                 </Project>
340                         ";
341
342                         engine = new Engine (Consts.BinPath);
343                         project = engine.CreateNewProject ();
344                         project.LoadXml (documentString);
345
346                         BuildItemGroup big2 = project.EvaluatedItems.Clone (false);
347                         BuildItem[] items = big2.ToArray ();
348
349                         Assert.AreEqual (1, big2.Count, "A1");
350
351                         Assert.AreEqual (String.Empty, items [0].Condition, "A2");
352                         Assert.AreEqual (String.Empty, items [0].Exclude, "A3");
353                         Assert.AreEqual ("a", items [0].FinalItemSpec, "A4");
354                         Assert.AreEqual ("a", items [0].Include, "A5");
355                         Assert.IsFalse (items [0].IsImported, "A6");
356                         Assert.AreEqual ("Item", items [0].Name, "A7");
357                 }
358
359                 [Test]
360                 [Category ("NotWorking")]
361                 public void TestClone4 ()
362                 {
363                         Engine engine;
364                         Project project;
365                         
366                         string documentString = @"
367                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
368                                         <ItemGroup>
369                                                 <Item Include='a' />
370                                         </ItemGroup>
371                                 </Project>
372                         ";
373
374                         engine = new Engine (Consts.BinPath);
375                         project = engine.CreateNewProject ();
376                         project.LoadXml (documentString);
377
378                         BuildItemGroup big2 = project.EvaluatedItems.Clone (true);
379                         BuildItem[] items = big2.ToArray ();
380
381                         Assert.AreEqual (1, big2.Count, "A1");
382
383                         Assert.AreEqual (String.Empty, items [0].Condition, "A2");
384                         Assert.AreEqual (String.Empty, items [0].Exclude, "A3");
385                         Assert.AreEqual ("a", items [0].FinalItemSpec, "A4");
386                         Assert.AreEqual ("a", items [0].Include, "A5");
387                         Assert.IsFalse (items [0].IsImported, "A6");
388                         Assert.AreEqual ("Item", items [0].Name, "A7");
389                 }
390
391                 // A shallow clone of this object cannot be created
392                 [Test]
393                 [ExpectedException (typeof (InvalidOperationException))]
394                 public void TestClone5 ()
395                 {
396                         Engine engine;
397                         Project project;
398                         
399                         string documentString = @"
400                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
401                                         <ItemGroup>
402                                                 <Item Include='a' />
403                                         </ItemGroup>
404                                 </Project>
405                         ";
406
407                         engine = new Engine (Consts.BinPath);
408                         project = engine.CreateNewProject ();
409                         project.LoadXml (documentString);
410
411                         BuildItemGroup[] groups = new BuildItemGroup [1];
412                         project.ItemGroups.CopyTo (groups, 0);
413                         
414                         groups [0].Clone (false);
415                 }
416
417                 [Test]
418                 [Category ("NotWorking")]
419                 public void TestClone6 ()
420                 {
421                         Engine engine;
422                         Project project;
423                         
424                         string documentString = @"
425                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
426                                         <ItemGroup>
427                                                 <Item Include='a' />
428                                         </ItemGroup>
429                                 </Project>
430                         ";
431
432                         engine = new Engine (Consts.BinPath);
433                         project = engine.CreateNewProject ();
434                         project.LoadXml (documentString);
435
436                         BuildItemGroup[] groups = new BuildItemGroup [1];
437                         project.ItemGroups.CopyTo (groups, 0);
438                         
439                         BuildItemGroup big2 = groups [0].Clone (true);
440                         BuildItem[] items = big2.ToArray ();
441
442                         Assert.AreEqual (1, big2.Count, "A1");
443
444                         Assert.AreEqual (String.Empty, items [0].Condition, "A2");
445                         Assert.AreEqual (String.Empty, items [0].Exclude, "A3");
446                         Assert.AreEqual ("a", items [0].FinalItemSpec, "A4");
447                         Assert.AreEqual ("a", items [0].Include, "A5");
448                         Assert.IsFalse (items [0].IsImported, "A6");
449                         Assert.AreEqual ("Item", items [0].Name, "A7");
450                 }
451
452                 [Test]
453                 public void TestCondition1 ()
454                 {
455                         Engine engine;
456                         Project project;
457
458                         string documentString = @"
459                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
460                                         <ItemGroup Condition='true' >
461                                                 <Item Include='a' />
462                                         </ItemGroup>
463                                 </Project>
464                         ";
465
466                         engine = new Engine (Consts.BinPath);
467                         project = engine.CreateNewProject ();
468                         project.LoadXml (documentString);
469
470                         BuildItemGroup [] groups = new BuildItemGroup [1];
471                         project.ItemGroups.CopyTo (groups, 0);
472
473                         Assert.AreEqual ("true", groups [0].Condition, "A1");
474                         Assert.IsFalse (groups [0].IsImported, "A2");
475                 }
476
477                 // Cannot set a condition on an object not represented by an XML element in the project file.
478                 [Test]
479                 [ExpectedException (typeof (InvalidOperationException))]
480                 public void TestCondition2 ()
481                 {
482                         BuildItemGroup big = new BuildItemGroup ();
483
484                         big.Condition = "true";
485                 }
486
487                 [Test]
488                 public void TestCondition3 ()
489                 {
490                         Engine engine;
491                         Project project;
492
493                         string documentString = @"
494                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
495                                         <ItemGroup Condition='true' >
496                                         </ItemGroup>
497                                 </Project>
498                         ";
499
500                         engine = new Engine (Consts.BinPath);
501                         project = engine.CreateNewProject ();
502                         project.LoadXml (documentString);
503
504                         BuildItemGroup [] groups = new BuildItemGroup [1];
505                         project.ItemGroups.CopyTo (groups, 0);
506
507                         Assert.AreEqual ("true", groups [0].Condition, "A1");
508                         groups [0].Condition = "false";
509
510                         Assert.AreEqual ("false", groups [0].Condition, "A2");
511                 }
512
513                 [Test]
514                 public void TestGetEnumerator ()
515                 {
516                         BuildItemGroup big = new BuildItemGroup ();
517                         big.AddNewItem ("a", "c");
518                         big.AddNewItem ("b", "d");
519
520                         IEnumerator e = big.GetEnumerator ();
521                         e.MoveNext ();
522                         Assert.AreEqual ("a", ((BuildItem) e.Current).Name, "A1");
523                         Assert.AreEqual ("c", ((BuildItem) e.Current).FinalItemSpec, "A2");
524                         e.MoveNext ();
525                         Assert.AreEqual ("b", ((BuildItem) e.Current).Name, "A3");
526                         Assert.AreEqual ("d", ((BuildItem) e.Current).FinalItemSpec, "A4");
527                         
528                         Assert.IsFalse (e.MoveNext ());
529                 }
530
531                 [Test]
532                 public void TestRemoveItem1 ()
533                 {
534                         BuildItemGroup big = new BuildItemGroup ();
535
536                         big.AddNewItem ("a", "b");
537                         BuildItem b = big.AddNewItem ("b", "c");
538                         big.AddNewItem ("c", "d");
539
540                         big.RemoveItem (b);
541
542                         BuildItem[] items = big.ToArray ();
543                         Assert.AreEqual (2, big.Count, "A1");
544                         Assert.AreEqual ("a", items [0].Name, "A2");
545                         Assert.AreEqual ("c", items [1].Name, "A3");
546                 }
547
548                 [Test]
549                 // NOTE: maybe it should throw an exception?
550                 // at the moment it probably doesn't find a "null" element
551                 public void TestRemoveItem2 ()
552                 {
553                         BuildItemGroup big = new BuildItemGroup ();
554
555                         big.RemoveItem (null);
556                 }
557
558                 [Test]
559                 public void TestRemoveItem3 ()
560                 {
561                         Engine engine;
562                         Project project;
563                         XmlDocument xd;
564                         XmlNode node;
565
566                         string documentString = @"
567                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
568                                         <ItemGroup>
569                                                 <A Include='B'/>
570                                         </ItemGroup>
571                                 </Project>
572                         ";
573
574                         engine = new Engine (Consts.BinPath);
575                         project = engine.CreateNewProject ();
576                         project.LoadXml (documentString);
577
578                         BuildItemGroup [] groups = new BuildItemGroup [1];
579                         project.ItemGroups.CopyTo (groups, 0);
580
581                         groups [0].RemoveItem (groups [0] [0]);
582                         Assert.AreEqual (0, groups [0].Count, "A1");
583                         Assert.AreEqual (1, project.ItemGroups.Count, "A2");
584
585                         xd = new XmlDocument ();
586                         xd.LoadXml (project.Xml);
587                         node = xd.SelectSingleNode ("tns:Project/tns:ItemGroup/tns:A", TestNamespaceManager.NamespaceManager);
588                         Assert.IsNull (node, "A3");
589                 }
590
591                 [Test]
592                 public void TestRemoveItemAt1 ()
593                 {
594                         BuildItemGroup big = new BuildItemGroup ();
595
596                         big.AddNewItem ("a", "b");
597                         big.AddNewItem ("b", "c");
598                         big.AddNewItem ("c", "d");
599
600                         big.RemoveItemAt (1);
601
602                         BuildItem[] items = big.ToArray ();
603                         Assert.AreEqual (2, big.Count, "A1");
604                         Assert.AreEqual ("a", items [0].Name, "A2");
605                         Assert.AreEqual ("c", items [1].Name, "A3");
606                 }
607
608                 [Test]
609                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
610                 public void TestRemoveItemAt2 ()
611                 {
612                         BuildItemGroup big = new BuildItemGroup ();
613
614                         big.AddNewItem ("a", "b");
615                         big.AddNewItem ("b", "c");
616                         big.AddNewItem ("c", "d");
617
618                         big.RemoveItemAt (-1);
619                 }
620
621                 [Test]
622                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
623                 public void TestRemoveItemAt3 ()
624                 {
625                         BuildItemGroup big = new BuildItemGroup ();
626
627                         big.AddNewItem ("a", "b");
628                         big.AddNewItem ("b", "c");
629                         big.AddNewItem ("c", "d");
630
631                         big.RemoveItemAt (3);
632                 }
633
634                 [Test]
635                 public void TestRemoveItemAt4 ()
636                 {
637                         Engine engine;
638                         Project project;
639                         XmlDocument xd;
640                         XmlNode node;
641
642                         string documentString = @"
643                                 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
644                                         <ItemGroup>
645                                                 <A Include='D'/>
646                                                 <B Include='D'/>
647                                                 <C Include='D'/>
648                                         </ItemGroup>
649                                 </Project>
650                         ";
651
652                         engine = new Engine (Consts.BinPath);
653                         project = engine.CreateNewProject ();
654                         project.LoadXml (documentString);
655
656                         BuildItemGroup [] groups = new BuildItemGroup [1];
657                         project.ItemGroups.CopyTo (groups, 0);
658
659                         groups [0].RemoveItemAt (1);
660                         Assert.AreEqual (2, groups [0].Count, "A1");
661                         Assert.AreEqual (1, project.ItemGroups.Count, "A2");
662
663                         xd = new XmlDocument ();
664                         xd.LoadXml (project.Xml);
665                         node = xd.SelectSingleNode ("tns:Project/tns:ItemGroup/tns:B", TestNamespaceManager.NamespaceManager);
666                         Assert.IsNull (node, "A3");
667                         Assert.IsTrue (project.IsDirty, "A4");
668                 }
669
670                 [Test]
671                 public void TestToArray1 ()
672                 {
673                         BuildItemGroup big = new BuildItemGroup ();
674
675                         BuildItem[] items = big.ToArray ();
676
677                         Assert.AreEqual (0, items.Length, "A1");
678
679                         big.AddNewItem ("a", "b");
680                         big.AddNewItem ("c", "d");
681
682                         items = big.ToArray ();
683
684                         Assert.AreEqual ("a", items [0].Name, "A2");
685                         Assert.AreEqual ("c", items [1].Name, "A3");
686                 }
687
688                 [Test]
689                 public void TestIndexer1 ()
690                 {
691                         BuildItemGroup big = new BuildItemGroup ();
692                         big.AddNewItem ("a", "b");
693                         big.AddNewItem ("c", "d");
694
695                         Assert.AreEqual ("a", big [0].Name, "A1");
696                         Assert.AreEqual ("c", big [1].Name, "A2");
697                 }
698
699                 [Test]
700                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
701                 public void TestIndexer2 ()
702                 {
703                         BuildItemGroup big = new BuildItemGroup ();
704                         Assert.IsNotNull (big [0], "A1");
705                 }
706
707                 [Test]
708                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
709                 public void TestIndexer3 ()
710                 {
711                         BuildItemGroup big = new BuildItemGroup ();
712                         Assert.IsNotNull (big [-1], "A1");
713                 }
714         }
715 }