In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / ImportTest.cs
1 //
2 // ImportTest.cs
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2006 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 Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
34
35 namespace MonoTests.Microsoft.Build.BuildEngine {
36         [TestFixture]
37         public class ImportTest {
38                 
39                 Engine                  engine;
40                 Project                 project;
41                 
42                 [Test]
43                 public void TestAdd1 ()
44                 {
45                         string documentString = @"
46                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
47                                         <Import Project='Test/resources/Import.csproj'/>
48                                 </Project>
49                         ";
50
51                         engine = new Engine (Consts.BinPath);
52
53                         project = engine.CreateNewProject ();
54                         project.LoadXml (documentString);
55
56                         Import[] t = new Import [1];
57                         project.Imports.CopyTo (t, 0);
58
59                         Assert.IsNull (t [0].Condition, "A1");
60                         Assert.AreEqual (false, t [0].IsImported, "A2");
61                         Assert.AreEqual ("Test/resources/Import.csproj", t [0].ProjectPath, "A3");
62                         Assert.IsNotNull (t [0].EvaluatedProjectPath, "A4");
63                         // FIXME: why there is no IsNotEmpty () in Mono NUnit?
64                         Assert.IsTrue (String.Empty != t [0].EvaluatedProjectPath, "A5");
65                 }
66
67                 [Test]
68                 [ExpectedException (typeof (InvalidProjectFileException))]
69                 public void TestAdd2 ()
70                 {
71                         string documentString = @"
72                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
73                                         <Import Project=''/>
74                                 </Project>
75                         ";
76
77                         engine = new Engine (Consts.BinPath);
78
79                         project = engine.CreateNewProject ();
80                         project.LoadXml (documentString);
81                 }
82
83                 [Test]
84                 [Category ("NotWorking")]
85                 public void TestAdd3 ()
86                 {
87                         string documentString = @"
88                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
89                                         <Import Project='Test/resources/SelfImport.csproj'/>
90                                 </Project>
91                         ";
92
93                         engine = new Engine (Consts.BinPath);
94
95                         project = engine.CreateNewProject ();
96                         project.LoadXml (documentString);
97
98                         Assert.AreEqual (1, project.Imports.Count, "A1");
99                 }
100
101                 [Test]
102                 public void TestRelativeImport1 ()
103                 {
104                         string documentString = @"
105                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
106                                         <Import Project='Test/resources/RelativeImport1.csproj'/>
107                                 </Project>
108                         ";
109
110                         engine = new Engine (Consts.BinPath);
111
112                         project = engine.CreateNewProject ();
113                         project.LoadXml (documentString);
114
115                         Assert.AreEqual ("B", project.EvaluatedProperties ["A"].FinalValue, "A1");
116                 }
117
118                 [Test]
119                 public void TestItems1 ()
120                 {
121                         string documentString = @"
122                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
123                                         <Import Project='Test/resources/Items.csproj'/>
124                                 </Project>
125                         ";
126
127                         engine = new Engine (Consts.BinPath);
128
129                         project = engine.CreateNewProject ();
130                         project.LoadXml (documentString);
131
132                         BuildItemGroup [] groups = new BuildItemGroup [1];
133                         project.ItemGroups.CopyTo (groups, 0);
134
135                         Assert.IsTrue (groups [0].IsImported, "A1");
136                         Assert.AreEqual (1, groups [0].Count, "A2");
137                 }
138         }
139 }