2 // CodeTaskFactoryTest.cs
5 // Atsushi Enomoto <atsushi@xamarin.com>
7 // Copyright (C) 2014 Xamarin Inc.
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.
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
43 public class CodeTaskFactoryTest
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");
57 string project_xml
= @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
60 TaskFactory='CodeTaskFactory'
61 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
64 <Code Type='Fragment' Language='cs'>
66 // Display ""Hello, world!""
67 Log.LogWarning(""Hello, world!"");
71 <Target Name='default'>
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");
82 public void MultipleCodeElements ()
84 string project_xml
= @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
87 TaskFactory='CodeTaskFactory'
88 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
91 <Code Type='Fragment' Language='cs'></Code>
92 <Code Type='Fragment' Language='cs'></Code>
95 <Target Name='default'>
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");
106 public void InvalidLanguage ()
108 string project_xml
= @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
111 TaskFactory='CodeTaskFactory'
112 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
115 <Code Type='Fragment' Language='ts'></Code>
118 <Target Name='default'>
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");
129 public void InvalidCSharp ()
131 string project_xml
= @"<Project ToolsVersion='4.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
134 TaskFactory='CodeTaskFactory'
135 AssemblyFile='$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll' >
138 <Code Type='Fragment' Language='cs'>
143 <Target Name='default'>
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");