[xbuild]: Support <PropertyGroup/ItemGroup> inside <Target>.
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / BuildPropertyTest.cs
index 24e811d6e4219445fe5df8f6272986163710e01d..f5f0472292b2b04b41d1b650685961fdde463480 100644 (file)
@@ -27,6 +27,7 @@
 
 using System;
 using System.Collections;
+using System.Xml;
 using Microsoft.Build.BuildEngine;
 using Microsoft.Build.Framework;
 using Microsoft.Build.Utilities;
@@ -37,16 +38,18 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
        public class BuildPropertyTest {
                
                BuildProperty   bp;
-               string          binPath;
                Engine          engine;
                Project         project;
-               
-               [SetUp]
-               public void SetUp ()
+
+               BuildProperty [] GetProperties (BuildPropertyGroup bpg)
                {
-                       binPath = "../../tools/xbuild/xbuild";
+                       BuildProperty [] arr = new BuildProperty [bpg.Count];
+                       int i = 0;
+                       foreach (BuildProperty bp in bpg)
+                               arr [i++] = bp;
+                       return arr;
                }
-               
+
                [Test]
                public void TestCtor1 ()
                {
@@ -76,8 +79,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
                
                [Test]
-               [ExpectedException (typeof (ArgumentNullException),
-                       "Parameter \"propertyName\" cannot be null.")]
+               [ExpectedException (typeof (ArgumentNullException))]
                public void TestCtor2 ()
                {
                        bp = new BuildProperty (null, "value");
@@ -85,17 +87,16 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
                
                [Test]
-               [ExpectedException (typeof (ArgumentNullException),
-                       "Parameter \"propertyValue\" cannot be null.")]
+               [ExpectedException (typeof (ArgumentNullException))]
                public void TestCtor3 ()
                {
                        bp = new BuildProperty ("name", null);
                        
                }
 
+               // A shallow clone of this object cannot be created.
                [Test]
-               [ExpectedException (typeof (InvalidOperationException),
-                       "A shallow clone of this object cannot be created.")]
+               [ExpectedException (typeof (InvalidOperationException))]
                public void TestClone1 ()
                {
                        bp = new BuildProperty ("name", "value");
@@ -112,6 +113,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
                
                [Test]
+               [Category ("NotWorking")]
                public void TestClone3 ()
                {
                        BuildProperty a,b;
@@ -124,7 +126,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                                 </Project>
                         ";
 
-                        engine = new Engine (binPath);
+                        engine = new Engine (Consts.BinPath);
 
                         project = engine.CreateNewProject ();
                         project.LoadXml (documentString);
@@ -139,6 +141,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
+               [Category ("NotWorking")]
                public void TestClone4 ()
                {
                        BuildProperty a,b;
@@ -151,7 +154,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                                 </Project>
                         ";
 
-                        engine = new Engine (binPath);
+                        engine = new Engine (Consts.BinPath);
 
                         project = engine.CreateNewProject ();
                         project.LoadXml (documentString);
@@ -166,6 +169,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
+               [Category ("NotWorking")]
                public void TestClone5 ()
                {
                        BuildProperty a,b;
@@ -179,7 +183,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                                 </Project>
                         ";
 
-                        engine = new Engine (binPath);
+                        engine = new Engine (Consts.BinPath);
 
                         project = engine.CreateNewProject ();
                         project.LoadXml (documentString);
@@ -198,6 +202,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
+               [Category ("NotWorking")]
                public void TestClone6 ()
                {
                        BuildProperty a,b;
@@ -211,7 +216,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                                 </Project>
                         ";
 
-                        engine = new Engine (binPath);
+                        engine = new Engine (Consts.BinPath);
 
                         project = engine.CreateNewProject ();
                         project.LoadXml (documentString);
@@ -228,14 +233,53 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        b.Value = "AnotherValue";
                        Assert.AreEqual ("Value", a.Value, "A2");
                }
-               
+
                [Test]
-               public void TestOpExplicit ()
+               [Category ("NotWorking")]
+               public void TestCondition1 ()
+               {
+                       string documentString = @"
+                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                       <PropertyGroup>
+                                               <Name>Value</Name>
+                                       </PropertyGroup>
+                                </Project>
+                        ";
+
+                       engine = new Engine (Consts.BinPath);
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (documentString);
+
+                       BuildProperty a = project.EvaluatedProperties ["Name"];
+
+                       a.Condition = "true";
+                       Assert.AreEqual ("true", a.Condition, "A1");
+               }
+
+               // Cannot set a condition on an object not represented by an XML element in the project file.
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void TestCondition2 ()
+               {
+                       BuildProperty a = new BuildProperty ("name", "value");
+                       a.Condition = "true";
+               }
+
+               [Test]
+               public void TestOpExplicit1 ()
                {
                        bp = new BuildProperty ("name", "value");
                        
                        Assert.AreEqual ("value", (string) bp, "A1");
                }
+
+               [Test]
+               public void TestOpExplicit2 ()
+               {
+                       BuildProperty bp = null;
+                       
+                       Assert.AreEqual (String.Empty, (string) bp, "A1");
+               }
                
                [Test]
                public void TestToString ()
@@ -243,5 +287,100 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        bp = new BuildProperty ("name", "a;b");
                        Assert.AreEqual ("a;b", bp.ToString ());
                }
+
+               [Test]
+               public void TestValue1 ()
+               {
+                       BuildProperty a;
+                       BuildPropertyGroup [] bpgs = new BuildPropertyGroup [1];
+                       BuildProperty [] props;
+
+                       string documentString = @"
+                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                       <PropertyGroup>
+                                               <Name>Value</Name>
+                                       </PropertyGroup>
+                                </Project>
+                        ";
+
+                       engine = new Engine (Consts.BinPath);
+
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (documentString);
+
+                       a = project.EvaluatedProperties ["Name"];
+                       a.Value = "$(something)";
+                       Assert.AreEqual ("$(something)", a.Value, "A1");
+
+                       project.PropertyGroups.CopyTo (bpgs, 0);
+                       props = GetProperties (bpgs [0]);
+                       Assert.AreEqual ("Value", props [0].Value, "A2");
+               }
+
+               [Test]
+               public void TestValue2 ()
+               {
+                       BuildPropertyGroup [] bpgs = new BuildPropertyGroup [1];
+                       BuildProperty [] props;
+                       XmlDocument xd;
+                       XmlNode node;
+
+                       string documentString = @"
+                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                       <PropertyGroup>
+                                               <Name>Value</Name>
+                                       </PropertyGroup>
+                                </Project>
+                        ";
+
+                       engine = new Engine (Consts.BinPath);
+
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (documentString);
+                       
+                       project.PropertyGroups.CopyTo (bpgs, 0);
+                       props = GetProperties (bpgs [0]);
+                       props [0].Value = "AnotherValue";
+
+                       xd = new XmlDocument ();
+                       xd.LoadXml (project.Xml);
+                       node = xd.SelectSingleNode ("tns:Project/tns:PropertyGroup/tns:Name", TestNamespaceManager.NamespaceManager);
+                       Assert.AreEqual ("AnotherValue", node.InnerText, "A1");
+               }
+
+               [Test]
+               [Category ("NotDotNet")]
+               public void TestValueXml ()
+               {
+                       BuildPropertyGroup [] bpgs = new BuildPropertyGroup [1];
+                       BuildProperty [] props;
+                       XmlDocument xd;
+                       XmlNode node;
+
+                       string documentString = @"
+                                       <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                                                       <PropertyGroup>
+                                                                       <Name>Value</Name>
+                                                       </PropertyGroup>
+                                       </Project>
+                       ";
+
+                       engine = new Engine (Consts.BinPath);
+
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (documentString);
+
+                       project.PropertyGroups.CopyTo (bpgs, 0);
+                       bpgs[0].AddNewProperty("XmlProp", "<XmlStuff></XmlStuff>");
+
+                       xd = new XmlDocument ();
+                       xd.LoadXml (project.Xml);
+                       node = xd.SelectSingleNode ("tns:Project/tns:PropertyGroup/tns:XmlProp/tns:XmlStuff", TestNamespaceManager.NamespaceManager);
+                       if (node == null) {
+                               Console.WriteLine (project.Xml);
+                               Assert.Fail ("Expected node to be non-null");
+                       }
+               }
+
        }
 }