using System;
using System.Collections;
+using System.Xml;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
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 ()
{
}
[Test]
- [ExpectedException (typeof (ArgumentNullException),
- "Parameter \"propertyName\" cannot be null.")]
+ [ExpectedException (typeof (ArgumentNullException))]
public void TestCtor2 ()
{
bp = new BuildProperty (null, "value");
}
[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");
}
[Test]
+ [Category ("NotWorking")]
public void TestClone3 ()
{
BuildProperty a,b;
</Project>
";
- engine = new Engine (binPath);
+ engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
}
[Test]
+ [Category ("NotWorking")]
public void TestClone4 ()
{
BuildProperty a,b;
</Project>
";
- engine = new Engine (binPath);
+ engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
}
[Test]
+ [Category ("NotWorking")]
public void TestClone5 ()
{
BuildProperty a,b;
</Project>
";
- engine = new Engine (binPath);
+ engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
}
[Test]
+ [Category ("NotWorking")]
public void TestClone6 ()
{
BuildProperty a,b;
</Project>
";
- engine = new Engine (binPath);
+ engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
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 ()
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");
+ }
+ }
+
}
}