5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 // Marek Safar (marek.safar@gmail.com)
8 // (C) 2006 Marek Sieradzki
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Microsoft.Build.BuildEngine;
32 using NUnit.Framework;
34 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
36 public class Properties {
43 Engine engine = new Engine (Consts.BinPath);
44 proj = engine.CreateNewProject ();
48 public void PropertyReference ()
50 string documentString = @"
51 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
53 <Config>debug</Config>
54 <ExpProp>$(Config)-$(Config)</ExpProp>
55 <ExpProp2> $(Config) $(Config) </ExpProp2>
56 <InvProp1>$(Config-$(Config)</InvProp1>
61 proj.LoadXml (documentString);
62 Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
63 Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
64 Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
65 Assert.AreEqual (" debug debug ", proj.GetEvaluatedProperty ("ExpProp2"), "A4");
66 Assert.AreEqual ("$(Config-$(Config)", proj.GetEvaluatedProperty ("InvProp1"), "A5");
70 [Category ("NotDotNet")]
71 public void PropertyReference2 ()
73 string documentString = @"
74 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
75 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
82 <StringTestTask Array='$(A)$(B)'>
83 <Output TaskParameter='Array' ItemName='Out' />
89 proj.LoadXml (documentString);
91 Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("Out").Count, "A1");
92 Assert.AreEqual ("AB", proj.GetEvaluatedItemsByName ("Out") [0].Include, "A2");
96 public void StringInstanceProperties ()
98 string documentString = @"
99 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
101 <Config>debug</Config>
102 <NullValue>null</NullValue>
103 <TargetValue> </TargetValue>
104 <Prop1>$(Config.Substring(0,3)) </Prop1>
105 <Prop2>$(Config.Length )</Prop2>
106 <Prop3>$(Config.StartsWith ('DE', System.StringComparison.OrdinalIgnoreCase))</Prop3>
107 <Prop4>$(NullValue.StartsWith ('Te', StringComparison.OrdinalIgnoreCase))</Prop4>
108 <Prop5>$(TargetValue.Trim('\\'))</Prop5>
113 proj.LoadXml (documentString);
114 Assert.AreEqual ("deb ", proj.GetEvaluatedProperty ("Prop1"), "#1");
115 Assert.AreEqual ("5", proj.GetEvaluatedProperty ("Prop2"), "#2");
116 Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop3"), "#3");
117 Assert.AreEqual ("False", proj.GetEvaluatedProperty ("Prop4"), "#4");
118 Assert.AreEqual ("", proj.GetEvaluatedProperty ("Prop5"), "#5");
122 public void AllowedFrameworkMembers ()
124 string documentString = @"
125 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
127 <Prop1>$([System.Byte]::MaxValue)</Prop1>
128 <Prop2>$([System.math]::Abs (-4.2) )</Prop2>
129 <Prop3>$([System.DateTime]::Today )</Prop3>
130 <Prop4>$([System.Char]::GetNumericValue('3'))</Prop4>
131 <Prop5>$([System.String]::Compare (Null, nUll))</Prop5>
132 <Prop6>$([System.Environment]::GetLogicalDrives ( ))</Prop6>
133 <Prop7>$([System.String]::Concat (`,`, `n`, `,`))</Prop7>
138 proj.LoadXml (documentString);
139 Assert.AreEqual ("255", proj.GetEvaluatedProperty ("Prop1"), "#1");
140 Assert.AreEqual ("4.2", proj.GetEvaluatedProperty ("Prop2"), "#2");
141 Assert.AreEqual (DateTime.Today.ToString (), proj.GetEvaluatedProperty ("Prop3"), "#3");
142 Assert.AreEqual ("3", proj.GetEvaluatedProperty ("Prop4"), "#4");
143 Assert.AreEqual ("0", proj.GetEvaluatedProperty ("Prop5"), "#5");
144 Assert.AreEqual (string.Join (";", Environment.GetLogicalDrives ()), proj.GetEvaluatedProperty ("Prop6"), "#6");
145 Assert.AreEqual (",n,", proj.GetEvaluatedProperty ("Prop7"), "#7");
149 public void InstanceMethodOnStaticProperty ()
151 string documentString = @"
152 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
154 <Prop1>$([System.DateTime]::Now.ToString(""yyyy.MM.dd""))</Prop1>
159 proj.LoadXml (documentString);
160 Assert.AreEqual (DateTime.Now.ToString ("yyyy.MM.dd"), proj.GetEvaluatedProperty ("Prop1"), "#1");
164 public void InstanceMemberOnStaticProperty ()
166 string documentString = @"
167 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
169 <Prop1>$([System.DateTime]::Now.Year)</Prop1>
174 proj.LoadXml (documentString);
175 Assert.AreEqual (DateTime.Now.Year.ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
179 public void InstanceMembersOnStaticMethod ()
181 string documentString = @"
182 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
184 <Prop1>$([System.String]::Concat('a', 'bb', 'c').Length.GetHashCode ())</Prop1>
190 proj.LoadXml (documentString);
191 Assert.AreEqual (4.GetHashCode ().ToString (), proj.GetEvaluatedProperty ("Prop1"), "#1");
195 public void MSBuildPropertyFunctions ()
197 string documentString = @"
198 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
200 <NumberOne>0.6</NumberOne>
201 <NumberTwo>6</NumberTwo>
202 <Prop1>$([MSBuild]::Add($(NumberOne), $(NumberTwo)))</Prop1>
207 proj.LoadXml (documentString);
208 Assert.AreEqual ("6.6", proj.GetEvaluatedProperty ("Prop1"), "#1");
212 public void Constructor ()
214 string documentString = @"
215 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
217 <NumberOne>0.6</NumberOne>
218 <NumberTwo>6</NumberTwo>
219 <Prop1>$([System.String]::new('value').EndsWith ('ue'))</Prop1>
224 proj.LoadXml (documentString);
225 Assert.AreEqual ("True", proj.GetEvaluatedProperty ("Prop1"), "#1");