2 // BuildPropertyTest.cs
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 Marek Sieradzki
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.
29 using System.Collections;
30 using Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
35 namespace MonoTests.Microsoft.Build.BuildEngine {
37 public class BuildPropertyTest {
47 binPath = "../../tools/xbuild/xbuild";
51 public void TestCtor1 ()
54 string value = "value";
56 bp = new BuildProperty (name, value);
58 Assert.AreEqual (name, bp.Name, "A1");
59 Assert.AreEqual (value, bp.Value, "A2");
60 Assert.AreEqual (String.Empty, bp.Condition, "A3");
61 Assert.AreEqual (value, bp.FinalValue, "A4");
62 Assert.AreEqual (false, bp.IsImported, "A5");
63 Assert.AreEqual (value, bp.ToString (), "A6");
66 value = "$(AnotherProperty)";
68 bp = new BuildProperty (name, value);
70 Assert.AreEqual (name, bp.Name, "A7");
71 Assert.AreEqual (value, bp.Value, "A8");
72 Assert.AreEqual (String.Empty, bp.Condition, "A9");
73 Assert.AreEqual (value, bp.FinalValue, "A10");
74 Assert.AreEqual (false, bp.IsImported, "A11");
75 Assert.AreEqual (value, bp.ToString (), "A12");
79 [ExpectedException (typeof (ArgumentNullException),
80 "Parameter \"propertyName\" cannot be null.")]
81 public void TestCtor2 ()
83 bp = new BuildProperty (null, "value");
88 [ExpectedException (typeof (ArgumentNullException),
89 "Parameter \"propertyValue\" cannot be null.")]
90 public void TestCtor3 ()
92 bp = new BuildProperty ("name", null);
97 [ExpectedException (typeof (InvalidOperationException),
98 "A shallow clone of this object cannot be created.")]
99 public void TestClone1 ()
101 bp = new BuildProperty ("name", "value");
107 public void TestClone2 ()
109 bp = new BuildProperty ("name", "value");
115 [Ignore ("Not implemented")]
116 public void TestClone3 ()
120 string documentString = @"
121 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
128 engine = new Engine (binPath);
130 project = engine.CreateNewProject ();
131 project.LoadXml (documentString);
133 a = project.EvaluatedProperties ["Name"];
134 Assert.AreEqual ("Value", a.Value, "A1");
138 b.Value = "AnotherValue";
139 Assert.AreEqual ("Value", a.Value, "A2");
143 [Ignore ("Not implemented")]
144 public void TestClone4 ()
148 string documentString = @"
149 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
156 engine = new Engine (binPath);
158 project = engine.CreateNewProject ();
159 project.LoadXml (documentString);
161 a = project.EvaluatedProperties ["Name"];
162 Assert.AreEqual ("Value", a.Value, "A1");
166 b.Value = "AnotherValue";
167 Assert.AreEqual ("Value", a.Value, "A2");
171 [Ignore ("Not implemented")]
172 public void TestClone5 ()
175 IList properties = new ArrayList ();
177 string documentString = @"
178 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
185 engine = new Engine (binPath);
187 project = engine.CreateNewProject ();
188 project.LoadXml (documentString);
190 foreach (BuildPropertyGroup bpg in project.PropertyGroups)
191 foreach (BuildProperty bpr in bpg)
192 properties.Add (bpr);
194 a = (BuildProperty) properties [0];
195 Assert.AreEqual ("Value", a.Value, "A1");
199 b.Value = "AnotherValue";
200 Assert.AreEqual ("Value", a.Value, "A2");
204 [Ignore ("Not implemented")]
205 public void TestClone6 ()
208 IList properties = new ArrayList ();
210 string documentString = @"
211 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
218 engine = new Engine (binPath);
220 project = engine.CreateNewProject ();
221 project.LoadXml (documentString);
223 foreach (BuildPropertyGroup bpg in project.PropertyGroups)
224 foreach (BuildProperty bpr in bpg)
225 properties.Add (bpr);
227 a = (BuildProperty) properties [0];
228 Assert.AreEqual ("Value", a.Value, "A1");
232 b.Value = "AnotherValue";
233 Assert.AreEqual ("Value", a.Value, "A2");
237 public void TestOpExplicit ()
239 bp = new BuildProperty ("name", "value");
241 Assert.AreEqual ("value", (string) bp, "A1");
245 public void TestToString ()
247 bp = new BuildProperty ("name", "a;b");
248 Assert.AreEqual ("a;b", bp.ToString ());