2 // UsingTaskCollectionTest.cs
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 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 Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
35 namespace MonoTests.Microsoft.Build.BuildEngine {
37 public class UsingTaskCollectionTest {
43 public void TestAssemblyFile1 ()
45 string documentString = @"
46 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
48 AssemblyFile='Test/resources/TestTasks.dll'
49 TaskName='TrueTestTask'
54 engine = new Engine (Consts.BinPath);
56 project = engine.CreateNewProject ();
57 project.LoadXml (documentString);
59 Assert.AreEqual (1, project.UsingTasks.Count, "A1");
60 Assert.AreEqual (false, project.UsingTasks.IsSynchronized, "A2");
61 Assert.AreEqual (typeof (object), project.UsingTasks.SyncRoot.GetType (), "A3");
65 public void TestGetEnumerator ()
67 string documentString = @"
68 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
70 AssemblyFile='Test/resources/TestTasks.dll'
71 TaskName='TrueTestTask'
74 AssemblyFile='Test/resources/TestTasks.dll'
75 TaskName='FalseTestTask'
80 engine = new Engine (Consts.BinPath);
81 project = engine.CreateNewProject ();
82 project.LoadXml (documentString);
84 IEnumerator en = project.UsingTasks.GetEnumerator ();
87 Assert.AreEqual ("Test/resources/TestTasks.dll", ((UsingTask) en.Current).AssemblyFile, "A1");
88 Assert.AreEqual ("TrueTestTask", ((UsingTask) en.Current).TaskName, "A2");
92 Assert.AreEqual ("Test/resources/TestTasks.dll", ((UsingTask) en.Current).AssemblyFile, "A3");
93 Assert.AreEqual ("FalseTestTask", ((UsingTask) en.Current).TaskName, "A4");
95 Assert.IsFalse (en.MoveNext ());
99 [ExpectedException (typeof (ArgumentNullException))]
100 public void TestCopyTo1 ()
102 string documentString = @"
103 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
105 AssemblyFile='Test/resources/TestTasks.dll'
106 TaskName='TrueTestTask'
111 engine = new Engine (Consts.BinPath);
113 project = engine.CreateNewProject ();
114 project.LoadXml (documentString);
116 project.UsingTasks.CopyTo (null, 0);
120 [ExpectedException (typeof (ArgumentOutOfRangeException))]
121 public void TestCopyTo2 ()
123 string documentString = @"
124 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
126 AssemblyFile='Test/resources/TestTasks.dll'
127 TaskName='TrueTestTask'
132 engine = new Engine (Consts.BinPath);
134 project = engine.CreateNewProject ();
135 project.LoadXml (documentString);
137 project.UsingTasks.CopyTo (new UsingTask [1], -1);
141 [Ignore ("Throws InvalidCastException on MS NET 2.0")]
142 public void TestCopyTo3 ()
144 string documentString = @"
145 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
147 AssemblyFile='Test/resources/TestTasks.dll'
148 TaskName='TrueTestTask'
153 engine = new Engine (Consts.BinPath);
155 project = engine.CreateNewProject ();
156 project.LoadXml (documentString);
158 project.UsingTasks.CopyTo (new UsingTask [][] { new UsingTask [] {
163 [ExpectedException (typeof (ArgumentException))]
164 public void TestCopyTo4 ()
166 string documentString = @"
167 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
169 AssemblyFile='Test/resources/TestTasks.dll'
170 TaskName='TrueTestTask'
175 engine = new Engine (Consts.BinPath);
177 project = engine.CreateNewProject ();
178 project.LoadXml (documentString);
180 project.UsingTasks.CopyTo (new UsingTask [1], 2);
183 [ExpectedException (typeof (ArgumentException))]
184 public void TestCopyTo5 ()
186 string documentString = @"
187 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
189 AssemblyFile='Test/resources/TestTasks.dll'
190 TaskName='TrueTestTask'
195 engine = new Engine (Consts.BinPath);
197 project = engine.CreateNewProject ();
198 project.LoadXml (documentString);
200 project.UsingTasks.CopyTo (new UsingTask [1], 1);
204 public void TestCopyTo6 ()
206 string documentString = @"
207 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
209 AssemblyFile='Test/resources/TestTasks.dll'
210 TaskName='TrueTestTask'
215 engine = new Engine (Consts.BinPath);
217 project = engine.CreateNewProject ();
218 project.LoadXml (documentString);
220 UsingTask[] array = new UsingTask [1];
221 project.UsingTasks.CopyTo (array, 0);
223 Assert.AreEqual ("TrueTestTask", array [0].TaskName, "A1");
227 public void TestCopyTo7 ()
229 string documentString = @"
230 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
232 AssemblyFile='Test/resources/TestTasks.dll'
233 TaskName='TrueTestTask'
238 engine = new Engine (Consts.BinPath);
240 project = engine.CreateNewProject ();
241 project.LoadXml (documentString);
243 UsingTask [] array = new UsingTask [1];
244 project.UsingTasks.CopyTo ((Array) array, 0);