Merge pull request #778 from cmorris98/master
[mono.git] / mcs / class / Microsoft.Build / Test / Microsoft.Build.Evaluation / ProjectItemDefinitionTest.cs
1 //
2 // ProjectItemDefinitionTest.cs
3 //
4 // Author:
5 //   Atsushi Enomoto (atsushi@xamarin.com)
6 //
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
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.IO;
30 using System.Linq;
31 using System.Xml;
32 using Microsoft.Build.Construction;
33 using Microsoft.Build.Evaluation;
34 using Microsoft.Build.Execution;
35 using NUnit.Framework;
36 using System.Collections.Generic;
37
38 namespace MonoTests.Microsoft.Build.Evaluation
39 {
40         [TestFixture]
41         public class ProjectItemDefinitionTest
42         {
43                 [Test]
44                 public void Properties ()
45                 {
46                         string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
47   <ItemDefinitionGroup>
48     <Foo>
49         <prop1>value1</prop1>
50         <prop2>value1</prop2>
51     </Foo>
52     <!-- This one is merged into existing Foo definition above. -->
53     <Foo>
54         <prop1>valueX1</prop1><!-- this one overrides value1. -->
55         <prop3>value3</prop3>
56     </Foo>
57   </ItemDefinitionGroup>
58 </Project>";
59                         var xml = XmlReader.Create (new StringReader (project_xml));
60                         var root = ProjectRootElement.Create (xml);
61                         var proj = new Project (root);
62                         Assert.AreEqual (1, proj.ItemDefinitions.Count, "#1"); // Foo
63                         var def = proj.ItemDefinitions ["Foo"];
64                         Assert.AreEqual ("Foo", def.ItemType, "#1x");
65                         Assert.AreEqual (3, def.MetadataCount, "#2");
66                         var md1 = def.Metadata.First (m => m.Name == "prop1");
67                         Assert.AreEqual ("Foo", md1.ItemType, "#2x");
68                         Assert.AreEqual ("valueX1", md1.UnevaluatedValue, "#3");
69                         // FIXME: enable it once we implemented it.
70                         //Assert.AreEqual ("valueX1", md1.EvaluatedValue, "#4");
71                         Assert.IsNotNull (md1.Predecessor, "#5");
72                         Assert.AreEqual ("value1", md1.Predecessor.UnevaluatedValue, "#6");
73                         // FIXME: enable it once we implemented it.
74                         //Assert.AreEqual ("value1", md1.Predecessor.EvaluatedValue, "#7");
75                 }
76                 
77                 [Test]
78                 public void Condition ()
79                 {
80                         string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
81   <ItemDefinitionGroup>
82     <I Condition='{0}'>
83       <DefinedMetadata>X</DefinedMetadata>
84     </I>
85   </ItemDefinitionGroup>
86   <ItemGroup>
87    <I Include='foo' />
88   </ItemGroup>
89 </Project>";
90                         var reader = XmlReader.Create (new StringReader (string.Format (xml, "True")));
91                         var root = ProjectRootElement.Create (reader);
92                         var proj = new Project (root);
93                         var i = proj.GetItems ("I").First ();
94                         Assert.AreEqual ("X", i.GetMetadataValue ("DefinedMetadata"), "#1");
95                         
96                         reader = XmlReader.Create (new StringReader (string.Format (xml, "False")));
97                         root = ProjectRootElement.Create (reader);
98                         proj = new Project (root);
99                         i = proj.GetItems ("I").First ();
100                         Assert.AreEqual (string.Empty, i.GetMetadataValue ("DefinedMetadata"), "#2");
101                 }
102         }
103 }
104