Merge pull request #217 from QuickJack/master
[mono.git] / mcs / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / ResolveAssemblyReferenceTest.cs
1 //
2 // ResolveAssemblyReferenceTest.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.Tasks;
33 using Microsoft.Build.Utilities;
34 using NUnit.Framework;
35
36 namespace MonoTests.Microsoft.Build.Tasks {
37
38         [TestFixture]
39         public class ResolveAssemblyReferenceTest {
40
41                 Engine engine;
42                 Project project;
43                 BuildItemGroup big;
44
45                 [Test]
46                 [Ignore ("it won't succeed if mono is not installed")]
47                 public void TestGac1 ()
48                 {
49                         string documentString = @"
50                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
51                                         <ItemGroup>
52                                                 <Reference Include='System' />
53                                         </ItemGroup>
54                                         <PropertyGroup>
55                                                 <SearchPaths>
56                                                         {CandidateAssemblyFiles};
57                                                         $(ReferencePath);
58                                                         {HintPathFromItem};
59                                                         {TargetFrameworkDirectory};
60                                                         {AssemblyFolders};
61                                                         {GAC};
62                                                         {RawFileName};
63                                                         $(OutputPath)
64                                                 </SearchPaths>
65                                         </PropertyGroup>
66                                         <Target Name='A'>
67                                                 <ResolveAssemblyReference
68                                                         Assemblies='@(Reference)'
69                                                         SearchPaths='$(SearchPaths)'
70                                                 >
71                                                         <Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
72                                                 </ResolveAssemblyReference>
73                                         </Target>
74                                 </Project>
75                         ";
76                         
77                         engine = new Engine (Consts.BinPath);
78                         project = engine.CreateNewProject ();
79                         project.LoadXml (documentString);
80
81                         Assert.IsTrue (project.Build ("A"), "A1");
82                         big = project.GetEvaluatedItemsByName ("ResolvedFiles");
83                         Assert.AreEqual (1, big.Count, "A2");
84                         Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
85                 }
86
87                 [Test]
88                 [Ignore ("it won't succeed if mono is not installed")]
89                 public void TestHintPath1 ()
90                 {
91                         string documentString = @"
92                                 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
93                                         <ItemGroup>
94                                                 <Reference Include='test'>
95                                                         <HintPath>Test\resources\test.dll</HintPath>
96                                                 </Reference>
97                                         </ItemGroup>
98                                         <PropertyGroup>
99                                                 <SearchPaths>
100                                                         {CandidateAssemblyFiles};
101                                                         $(ReferencePath);
102                                                         {HintPathFromItem};
103                                                         {TargetFrameworkDirectory};
104                                                         {AssemblyFolders};
105                                                         {GAC};
106                                                         {RawFileName};
107                                                         $(OutputPath)
108                                                 </SearchPaths>
109                                         </PropertyGroup>
110                                         <Target Name='A'>
111                                                 <ResolveAssemblyReference
112                                                         Assemblies='@(Reference)'
113                                                         SearchPaths='$(SearchPaths)'
114                                                 >
115                                                         <Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
116                                                 </ResolveAssemblyReference>
117                                         </Target>
118                                 </Project>
119                         ";
120                         
121                         engine = new Engine (Consts.BinPath);
122                         project = engine.CreateNewProject ();
123                         project.LoadXml (documentString);
124
125                         Assert.IsTrue (project.Build ("A"), "A1");
126                         big = project.GetEvaluatedItemsByName ("ResolvedFiles");
127                         Assert.AreEqual (1, big.Count, "A2");
128                         Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
129                 }
130         }
131