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 public void TestClone3 ()
119 string documentString = @"
120 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
127 engine = new Engine (binPath);
129 project = engine.CreateNewProject ();
130 project.LoadXml (documentString);
132 a = project.EvaluatedProperties ["Name"];
133 Assert.AreEqual ("Value", a.Value, "A1");
137 b.Value = "AnotherValue";
138 Assert.AreEqual ("Value", a.Value, "A2");
142 public void TestClone4 ()
146 string documentString = @"
147 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
154 engine = new Engine (binPath);
156 project = engine.CreateNewProject ();
157 project.LoadXml (documentString);
159 a = project.EvaluatedProperties ["Name"];
160 Assert.AreEqual ("Value", a.Value, "A1");
164 b.Value = "AnotherValue";
165 Assert.AreEqual ("Value", a.Value, "A2");
169 public void TestClone5 ()
172 IList properties = new ArrayList ();
174 string documentString = @"
175 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
182 engine = new Engine (binPath);
184 project = engine.CreateNewProject ();
185 project.LoadXml (documentString);
187 foreach (BuildPropertyGroup bpg in project.PropertyGroups)
188 foreach (BuildProperty bpr in bpg)
189 properties.Add (bpr);
191 a = (BuildProperty) properties [0];
192 Assert.AreEqual ("Value", a.Value, "A1");
196 b.Value = "AnotherValue";
197 Assert.AreEqual ("Value", a.Value, "A2");
201 public void TestClone6 ()
204 IList properties = new ArrayList ();
206 string documentString = @"
207 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
214 engine = new Engine (binPath);
216 project = engine.CreateNewProject ();
217 project.LoadXml (documentString);
219 foreach (BuildPropertyGroup bpg in project.PropertyGroups)
220 foreach (BuildProperty bpr in bpg)
221 properties.Add (bpr);
223 a = (BuildProperty) properties [0];
224 Assert.AreEqual ("Value", a.Value, "A1");
228 b.Value = "AnotherValue";
229 Assert.AreEqual ("Value", a.Value, "A2");
233 public void TestOpExplicit ()
235 bp = new BuildProperty ("name", "value");
237 Assert.AreEqual ("value", (string) bp, "A1");
241 public void TestToString ()
243 bp = new BuildProperty ("name", "a;b");
244 Assert.AreEqual ("a;b", bp.ToString ());