System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / Microsoft.Build / Test / FunctionalTest.cs
1 //
2 // FunctionalTest.cs
3 //
4 // Author:
5 //   Leszek Ciesielski (skolima@gmail.com)
6 //
7 // (C) 2011 Leszek Ciesielski
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
29 using NUnit.Framework;
30 using System;
31 using System.Collections.Generic;
32 using System.Linq;
33 using System.Text;
34 using Microsoft.Build.Construction;
35 using Microsoft.Build.Evaluation;
36 using System.IO;
37 using System.Globalization;
38
39 namespace MonoTests.Microsoft.Build
40 {
41         [TestFixture]
42         public class FunctionalTest
43         {
44                 [Test]
45                 public void TestFullProjectGeneration ()
46                 {
47                         var project = ProjectRootElement.Create ();
48                         var projectFileName = String.Format ("Test{0}FunctionalTestProject.csproj",
49                                 Path.DirectorySeparatorChar);
50                         project.DefaultTargets = "Build";
51                         SetKnownProperties (project.AddPropertyGroup ());
52                         GenerateReferences (project.AddItemGroup ());
53                         GenerateCompileIncludes (project.AddItemGroup ());
54                         project.AddImport ("$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
55                         
56                         project.Save (projectFileName);
57                         Assert.AreEqual (projectGuid, GetProjectId (project), "#01");
58                         FileAssert.AreEqual (String.Format ("Test{0}FunctionalTestReferenceProject.csproj",
59                                 Path.DirectorySeparatorChar), String.Format ("Test{0}FunctionalTestProject.csproj",
60                                 Path.DirectorySeparatorChar), "#02");
61                 }
62
63                 [Test]
64                 public void TestLoadAndSave ()
65                 {
66                         var project = ProjectRootElement.Open ("Microsoft.Build.csproj");
67                         var projectFileName = String.Format ("Test{0}FunctionalTestProject2.csproj",
68                                 Path.DirectorySeparatorChar);
69                         project.Save (projectFileName);
70                         
71                         Assert.AreEqual (new Guid ("{B2012E7F-8F8D-4908-8045-413F2BD1022D}"), GetProjectId (project),
72                                 "#03");
73                         FileAssert.AreEqual ("Microsoft.Build.csproj", projectFileName, "#04");
74                 }
75
76                 [Test]
77                 public void TestLoadAndSave3 ()
78                 {
79                         var referenceProject = String.Format (
80                                 "Test{0}FunctionalTestReferenceProject3.csproj", Path.DirectorySeparatorChar);
81                         var project = ProjectRootElement.Open (referenceProject);
82                         var projectFileName = String.Format ("Test{0}FunctionalTestProject3.csproj",
83                                 Path.DirectorySeparatorChar);
84                         project.Save (projectFileName);
85
86                         Assert.AreEqual (new Guid ("{793B20A9-E263-4B54-BB31-305B602087CE}"), GetProjectId (project),
87                                 "#05");
88                         FileAssert.AreEqual (referenceProject, projectFileName, "#06");
89                 }
90
91                 public Guid GetProjectId (ProjectRootElement project)
92                 {
93                         var value = project.Properties.Where (p => p.Name == "ProjectGuid").First ().Value;
94                         return Guid.Parse (value);
95                 }
96
97                 void GenerateCompileIncludes (ProjectItemGroupElement itemGroup)
98                 {
99                         foreach (var include in new[] { "Test.cs", "Test2.cs", "Test3.cs" }) {
100                                 itemGroup.AddItem ("Compile", ProjectCollection.Escape (include),
101                                         new[] { new KeyValuePair<string, string> ("SubType", "Code") });
102                         }
103                         foreach (var resource in new[] { "Test.resx", "Test2.resx", "Test3.resx" }) {
104                                 itemGroup.AddItem ("EmbeddedResource", ProjectCollection.Escape (resource),
105                                         new[] { new KeyValuePair<string, string> ("LogicalName", "Name.Space.Test") });
106                         }
107                 }
108
109                 void GenerateReferences (ProjectItemGroupElement itemGroup)
110                 {
111                         foreach (var reference in new[] { "Test.dll", "Test2.dll", "Test3.dll" }) {
112                                 var name = Path.GetFileNameWithoutExtension (reference);
113                                 itemGroup.AddItem ("Reference", name, new[] {
114                                         new KeyValuePair<string, string> ("Name", name),
115                                         new KeyValuePair<string, string> ("HintPath",
116                                                 ProjectCollection.Escape (reference)) });
117                         }
118                         foreach (var reference in new[] { "mscorlib", "System", "System.Xml" }) {
119                                 itemGroup.AddItem ("Reference", reference);
120                         }
121                 }
122
123                 void SetKnownProperties (ProjectPropertyGroupElement properties)
124                 {
125                         properties.AddProperty ("AssemblyName", Path.GetFileNameWithoutExtension ("ZigZag.exe"));
126                         properties.AddProperty ("ProjectGuid", projectGuid.ToString ("B"));
127                         properties.AddProperty ("CheckForOverflowUnderflow", false.ToString ());
128                         properties.AddProperty ("CodePage", String.Empty);
129                         properties.AddProperty ("DebugSymbols", true.ToString ());
130                         properties.AddProperty ("DebugType", "Full");
131                         properties.AddProperty ("Optimize", false.ToString ());
132                         properties.AddProperty ("Platform", "AnyCPU");
133                         properties.AddProperty ("ProjectTypeGuids", projectTypeGuid.ToString ("B"));
134                         properties.AddProperty ("AllowUnsafeBlocks", false.ToString ());
135                         properties.AddProperty ("WarningLevel", "4");
136                         properties.AddProperty ("OutputPath", ProjectCollection.Escape ("bin\\Debug"));
137                         properties.AddProperty ("OutputType", "winexe");
138                         properties.AddProperty ("DefineConstants", "DEBUG,TRACE");
139                         properties.AddProperty ("TreatWarningsAsErrors", true.ToString ());
140                 }
141
142                 static readonly Guid projectTypeGuid = Guid.Parse ("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}");
143                 static readonly Guid projectGuid = Guid.Parse ("{362F36B0-B26C-42DE-8586-20DF66BD05E8}");
144         }
145 }