2 // ProjectItemDefinitionTest.cs
5 // Atsushi Enomoto (atsushi@xamarin.com)
7 // Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
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.
32 using Microsoft.Build.Construction;
33 using Microsoft.Build.Evaluation;
34 using Microsoft.Build.Execution;
35 using NUnit.Framework;
36 using System.Collections.Generic;
38 namespace MonoTests.Microsoft.Build.Evaluation
41 public class ProjectItemDefinitionTest
44 public void Properties ()
46 string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
52 <!-- This one is merged into existing Foo definition above. -->
54 <prop1>valueX1</prop1><!-- this one overrides value1. -->
57 </ItemDefinitionGroup>
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");
78 public void Condition ()
80 string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
83 <DefinedMetadata>X</DefinedMetadata>
85 </ItemDefinitionGroup>
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");
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");