[msbuild] implement CodeTaskFactory i.e. inline tasks.
[mono-project.git] / mcs / class / Microsoft.Build.Tasks / Test / Microsoft.Build.Tasks / CodeTaskFactoryTest.cs
blob16176dba1268d90fcc1d032f14ed0091dad041e9
1 //
2 // CodeTaskFactoryTest.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@xamarin.com>
6 //
7 // Copyright (C) 2014 Xamarin Inc.
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.
28 #if NET_4_0
29 using System;
30 using System.IO;
31 using System.Linq;
32 using System.Xml;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Tasks;
35 using NUnit.Framework;
36 using Microsoft.Build.Construction;
37 using Microsoft.Build.Evaluation;
38 using Microsoft.Build.Logging;
40 namespace MonoTests.Microsoft.Build.Tasks
42 [TestFixture]
43 public class CodeTaskFactoryTest
45 [Test]
46 public void EmptyFactory ()
48 var f = new CodeTaskFactory ();
49 Assert.AreEqual ("Code Task Factory", f.FactoryName, "Name");
50 Assert.IsNull (f.TaskType, "TaskType");
51 Assert.IsNull (f.CreateTask (null), "CreateTask");
54 [Test]
55 public void Hello ()
57 string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
58 <UsingTask
59 TaskName='DoNothing'
60 TaskFactory='CodeTaskFactory'
61 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
62 <ParameterGroup />
63 <Task>
64 <Code Type='Fragment' Language='cs'>
65 <![CDATA[
66 // Display ""Hello, world!""
67 Log.LogWarning(""Hello, world!"");
68 ]]> </Code>
69 </Task>
70 </UsingTask>
71 <Target Name='default'>
72 <DoNothing />
73 </Target>
74 </Project>";
75 var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
76 root.FullPath = "CodeTaskFactoryTest.Hello.proj";
77 var project = new Project (root);
78 Assert.IsTrue (project.Build (new ConsoleLogger (LoggerVerbosity.Diagnostic)), "Build");
81 [Test]
82 public void MultipleCodeElements ()
84 string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
85 <UsingTask
86 TaskName='DoNothing'
87 TaskFactory='CodeTaskFactory'
88 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
89 <ParameterGroup />
90 <Task>
91 <Code Type='Fragment' Language='cs'></Code>
92 <Code Type='Fragment' Language='cs'></Code>
93 </Task>
94 </UsingTask>
95 <Target Name='default'>
96 <DoNothing />
97 </Target>
98 </Project>";
99 var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
100 root.FullPath = "CodeTaskFactoryTest.MultipleCodeElements.proj";
101 var project = new Project (root);
102 Assert.IsFalse (project.Build (), "Build");
105 [Test]
106 public void InvalidLanguage ()
108 string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
109 <UsingTask
110 TaskName='DoNothing'
111 TaskFactory='CodeTaskFactory'
112 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
113 <ParameterGroup />
114 <Task>
115 <Code Type='Fragment' Language='ts'></Code>
116 </Task>
117 </UsingTask>
118 <Target Name='default'>
119 <DoNothing />
120 </Target>
121 </Project>";
122 var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
123 root.FullPath = "CodeTaskFactoryTest.InvalidLanguage.proj";
124 var project = new Project (root);
125 Assert.IsFalse (project.Build (), "Build");
128 [Test]
129 public void InvalidCSharp ()
131 string project_xml = @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
132 <UsingTask
133 TaskName='DoNothing'
134 TaskFactory='CodeTaskFactory'
135 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
136 <ParameterGroup />
137 <Task>
138 <Code Type='Fragment' Language='cs'>
139 ""Hello, world!""
140 </Code>
141 </Task>
142 </UsingTask>
143 <Target Name='default'>
144 <DoNothing />
145 </Target>
146 </Project>";
147 var root = ProjectRootElement.Create (XmlReader.Create (new StringReader (project_xml)));
148 root.FullPath = "CodeTaskFactoryTest.InvalidCSharp.proj";
149 var project = new Project (root);
150 Assert.IsFalse (project.Build (), "Build");
155 #endif