Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 35e0bf3

Browse files
committed
add tests for bug by rework of DynamicValueUtility
bug :Conditional Tasks don't work anymore after upgrading from 1.8.4 to 1.9.48 (Bug #322)
1 parent dfd7888 commit 35e0bf3

File tree

2 files changed

+195
-3
lines changed

2 files changed

+195
-3
lines changed

project/UnitTests/Core/Tasks/DynamicValueUtilityTests.cs

Lines changed: 191 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void SplitPropertyIntoPartsMultipleValuesWithKey()
4848

4949
private void CheckPart(DynamicValueUtility.PropertyPart part, int position, string name, string keyName, string keyValue)
5050
{
51-
Assert.AreEqual(name, part.Name, string.Format(System.Globalization.CultureInfo.CurrentCulture,"Part name does not match [{0}]", position));
52-
Assert.AreEqual(keyName, part.KeyName, string.Format(System.Globalization.CultureInfo.CurrentCulture,"Part key name does not match [{0}]", position));
53-
Assert.AreEqual(keyValue, part.KeyValue, string.Format(System.Globalization.CultureInfo.CurrentCulture,"Part key value does not match [{0}]", position));
51+
Assert.AreEqual(name, part.Name, string.Format(System.Globalization.CultureInfo.CurrentCulture, "Part name does not match [{0}]", position));
52+
Assert.AreEqual(keyName, part.KeyName, string.Format(System.Globalization.CultureInfo.CurrentCulture, "Part key name does not match [{0}]", position));
53+
Assert.AreEqual(keyValue, part.KeyValue, string.Format(System.Globalization.CultureInfo.CurrentCulture, "Part key value does not match [{0}]", position));
5454
}
5555

5656
[Test]
@@ -170,6 +170,194 @@ public void ChangePropertyDifferentType()
170170
Assert.AreEqual(20, rootValue.Value, "Property not changed");
171171
}
172172

173+
[Test]
174+
public void DynamicUtilityNestedTasksWithParameters_EmptyReflectorTable()
175+
{
176+
var TaskSetupXml = GetNestedTasksWithParametersXML();
177+
var processedTaskXml = "<conditional>" +
178+
" <conditions>" +
179+
" <buildCondition>" +
180+
" <value>ForceBuild</value>" +
181+
" </buildCondition>" +
182+
" <compareCondition>" +
183+
" <value1></value1>" +
184+
" <value2>Yes</value2>" +
185+
" <evaluation>Equal</evaluation>" +
186+
" </compareCondition>" +
187+
" </conditions>" +
188+
" <tasks>" +
189+
" <exec>" +
190+
" <!-- if you want the task to fail, ping an unknown server -->" +
191+
" <executable>ping.exe</executable>" +
192+
" <buildArgs>localhost</buildArgs>" +
193+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
194+
" <description>Pinging a server</description>" +
195+
" </exec>" +
196+
" <conditional>" +
197+
" <conditions>" +
198+
" <compareCondition>" +
199+
" <value1></value1>" +
200+
" <value2>Yes</value2>" +
201+
" <evaluation>Equal</evaluation>" +
202+
" </compareCondition>" +
203+
" </conditions>" +
204+
" <tasks>" +
205+
" <exec>" +
206+
" <!-- if you want the task to fail, ping an unknown server -->" +
207+
" <executable>ping.exe</executable>" +
208+
" <buildArgs></buildArgs>" +
209+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
210+
" <description>Pinging a server</description>" +
211+
" </exec>" +
212+
" </tasks>" +
213+
" </conditional>" +
214+
" </tasks>" +
215+
" <dynamicValues>" +
216+
" <directValue>" +
217+
" <parameter>CommitBuild</parameter>" +
218+
" <property>conditions.compareCondition.value1</property>" +
219+
" </directValue>" +
220+
" <directValue>" +
221+
" <parameter>TagBuild</parameter>" +
222+
" <property>tasks.conditional.conditions.compareCondition.value1</property>" +
223+
" </directValue>" +
224+
" <directValue>" +
225+
" <parameter>TagVersion</parameter>" +
226+
" <property>tasks.conditional.tasks.exec.buildArgs</property>" +
227+
" </directValue>" +
228+
" </dynamicValues>" +
229+
"</conditional>";
230+
231+
var xdoc = new System.Xml.XmlDocument();
232+
xdoc.LoadXml(TaskSetupXml);
233+
Exortech.NetReflector.NetReflectorTypeTable typeTable = new Exortech.NetReflector.NetReflectorTypeTable();
234+
235+
var result = ThoughtWorks.CruiseControl.Core.Tasks.DynamicValueUtility.ConvertXmlToDynamicValues(typeTable, xdoc.DocumentElement, null);
236+
Console.WriteLine(result.OuterXml);
237+
238+
xdoc.LoadXml(processedTaskXml); // load in xdoc to ease comparing xml documents
239+
240+
Assert.AreEqual(xdoc.OuterXml, result.OuterXml);
241+
}
242+
243+
[Test]
244+
public void DynamicUtilityNestedTasksWithParameters_ReflectorTableInitialisedAsByServer()
245+
{
246+
var TaskSetupXml = GetNestedTasksWithParametersXML();
247+
var processedTaskXml = "<conditional>" +
248+
" <conditions>" +
249+
" <buildCondition>" +
250+
" <value>ForceBuild</value>" +
251+
" </buildCondition>" +
252+
" <compareCondition>" +
253+
" <value1></value1>" +
254+
" <value2>Yes</value2>" +
255+
" <evaluation>Equal</evaluation>" +
256+
" </compareCondition>" +
257+
" </conditions>" +
258+
" <tasks>" +
259+
" <exec>" +
260+
" <!-- if you want the task to fail, ping an unknown server -->" +
261+
" <executable>ping.exe</executable>" +
262+
" <buildArgs>localhost</buildArgs>" +
263+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
264+
" <description>Pinging a server</description>" +
265+
" </exec>" +
266+
" <conditional>" +
267+
" <conditions>" +
268+
" <compareCondition>" +
269+
" <value1></value1>" +
270+
" <value2>Yes</value2>" +
271+
" <evaluation>Equal</evaluation>" +
272+
" </compareCondition>" +
273+
" </conditions>" +
274+
" <tasks>" +
275+
" <exec>" +
276+
" <!-- if you want the task to fail, ping an unknown server -->" +
277+
" <executable>ping.exe</executable>" +
278+
" <buildArgs></buildArgs>" +
279+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
280+
" <description>Pinging a server</description>" +
281+
" </exec>" +
282+
" </tasks>" +
283+
" </conditional>" +
284+
" </tasks>" +
285+
" <dynamicValues>" +
286+
" <directValue>" +
287+
" <parameter>CommitBuild</parameter>" +
288+
" <property>conditions[1].value1</property>" +
289+
" </directValue>" +
290+
" <directValue>" +
291+
" <parameter>TagBuild</parameter>" +
292+
" <property>tasks[1].conditions[0].value1</property>" +
293+
" </directValue>" +
294+
" <directValue>" +
295+
" <parameter>TagVersion</parameter>" +
296+
" <property>tasks[1].tasks[0].buildArgs</property>" +
297+
" </directValue>" +
298+
" </dynamicValues>" +
299+
"</conditional>";
300+
301+
302+
var xdoc = new System.Xml.XmlDocument();
303+
xdoc.LoadXml(TaskSetupXml);
304+
305+
Objection.ObjectionStore objectionStore = new Objection.ObjectionStore();
306+
Exortech.NetReflector.NetReflectorTypeTable typeTable = Exortech.NetReflector.NetReflectorTypeTable.CreateDefault(new Objection.NetReflectorPlugin.ObjectionNetReflectorInstantiator(objectionStore));
307+
308+
var result = ThoughtWorks.CruiseControl.Core.Tasks.DynamicValueUtility.ConvertXmlToDynamicValues(typeTable, xdoc.DocumentElement, null);
309+
Console.WriteLine(result.OuterXml);
310+
311+
xdoc.LoadXml(processedTaskXml); // load in xdoc to ease comparing xml documents
312+
313+
Assert.AreEqual(xdoc.OuterXml, result.OuterXml);
314+
}
315+
316+
private string GetNestedTasksWithParametersXML()
317+
{
318+
return " <conditional>" +
319+
" <conditions>" +
320+
" <buildCondition>" +
321+
" <value>ForceBuild</value>" +
322+
" </buildCondition>" +
323+
" <compareCondition>" +
324+
" <value1>$[CommitBuild]</value1>" +
325+
" <value2>Yes</value2>" +
326+
" <evaluation>Equal</evaluation>" +
327+
" </compareCondition>" +
328+
" </conditions>" +
329+
" <tasks>" +
330+
" <exec>" +
331+
" <!-- if you want the task to fail, ping an unknown server -->" +
332+
" <executable>ping.exe</executable>" +
333+
" <buildArgs>localhost</buildArgs>" +
334+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
335+
" <description>Pinging a server</description>" +
336+
" </exec>" +
337+
" <conditional>" +
338+
" <conditions>" +
339+
" <compareCondition>" +
340+
" <value1>$[TagBuild]</value1>" +
341+
" <value2>Yes</value2>" +
342+
" <evaluation>Equal</evaluation>" +
343+
" </compareCondition>" +
344+
" </conditions>" +
345+
" <tasks>" +
346+
" <exec>" +
347+
" <!-- if you want the task to fail, ping an unknown server -->" +
348+
" <executable>ping.exe</executable>" +
349+
" <buildArgs>$[TagVersion]</buildArgs>" +
350+
" <buildTimeoutSeconds>15</buildTimeoutSeconds>" +
351+
" <description>Pinging a server</description>" +
352+
" </exec> " +
353+
" </tasks>" +
354+
" </conditional>" +
355+
" " +
356+
" </tasks>" +
357+
" </conditional>";
358+
}
359+
360+
173361
[ReflectorType("testInstance")]
174362
public class TestClass
175363
{

project/core/core.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
<Reference Include="System.Xml.Linq">
168168
<RequiredTargetFramework>3.5</RequiredTargetFramework>
169169
</Reference>
170+
<ProjectReference Include="..\objection\objection.csproj">
171+
<Project>{1c0b8046-fe79-4845-84b9-369a76f817a3}</Project>
172+
<Name>objection</Name>
173+
</ProjectReference>
170174
<ProjectReference Include="..\Remote\Remote.csproj">
171175
<Name>Remote</Name>
172176
<Project>{E820CF3B-8C5A-4002-BC16-B7818D3D54A8}</Project>

0 commit comments

Comments
 (0)