2 // CreatePropertyTest.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;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
37 namespace MonoTests.Microsoft.Build.Tasks {
40 public class CreatePropertyTest {
42 public void TestAssignment ()
44 CreateProperty cp = new CreateProperty ();
46 cp.Value = new string [1] { "1" };
48 Assert.AreEqual ("1", cp.Value [0], "A1");
49 Assert.AreEqual ("1", cp.ValueSetByTask [0], "A2");
53 public void TestExecution1 ()
58 string documentString = @"
59 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
65 <CreateProperty Value='$(A)$(B)' >
71 TaskParameter='ValueSetByTask'
72 PropertyName='ValueSetByTask'
79 engine = new Engine (Consts.BinPath);
80 project = engine.CreateNewProject ();
81 project.LoadXml (documentString);
82 Assert.IsTrue (project.Build ("1"), "A1");
84 Assert.AreEqual ("12", project.EvaluatedProperties ["Value"].Value, "A2");
85 Assert.AreEqual ("12", project.EvaluatedProperties ["Value"].FinalValue, "A3");
86 Assert.AreEqual ("12", project.EvaluatedProperties ["ValueSetByTask"].Value, "A4");
87 Assert.AreEqual ("12", project.EvaluatedProperties ["ValueSetByTask"].FinalValue, "A5");
91 public void TestExecution2 () {
95 string documentString = @"
96 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
98 <Second Include=""Abc""/>
99 <IG Include=""@(Second)""/></ItemGroup>
104 <CreateProperty Value='$(C)' >
106 TaskParameter='Value'
110 TaskParameter='ValueSetByTask'
111 PropertyName='ValueSetByTask'
118 engine = new Engine (Consts.BinPath);
119 project = engine.CreateNewProject ();
120 project.LoadXml (documentString);
121 Assert.IsTrue (project.Build ("1"), "A1");
123 Assert.AreEqual ("Abc", project.EvaluatedProperties["Value"].Value, "A2");
124 Assert.AreEqual ("Abc", project.EvaluatedProperties["Value"].FinalValue, "A3");
125 Assert.AreEqual ("Abc", project.EvaluatedProperties["ValueSetByTask"].Value, "A4");
126 Assert.AreEqual ("Abc", project.EvaluatedProperties["ValueSetByTask"].FinalValue, "A5");
127 Assert.AreEqual ("@(IG)", project.EvaluatedProperties["C"].FinalValue, "A6");
131 public void TestEmptyPropertyValue ()
136 string documentString = @"
137 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
142 <Message Text='Before: $(A)'/>
143 <CreateProperty Value=''>
145 TaskParameter='Value'
149 <Message Text='After: $(A)'/>
154 engine = new Engine (Consts.BinPath);
156 TestMessageLogger testLogger = new TestMessageLogger ();
157 engine.RegisterLogger (testLogger);
159 project = engine.CreateNewProject ();
160 project.LoadXml (documentString);
161 if (!project.Build ("1")) {
162 testLogger.DumpMessages ();
163 Assert.Fail ("Build failed");
166 testLogger.CheckLoggedMessageHead ("Before: 1", "A1");
167 testLogger.CheckLoggedMessageHead ("After: ", "A2");
168 Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected messages found");