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

Commit 3fba9fa

Browse files
committed
The conversion must be done once and for all and thus can be more precise.
1 parent 8da0905 commit 3fba9fa

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-16
lines changed

project/UnitTests/Core/SourceControl/MultiSourceControlTest.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void PassesIndividualSourceDataAndCombinesSingleSourceControl()
234234
}
235235

236236
[Test]
237-
public void MigratesSingleSourceControlDataToNewFormat()
237+
public void MigratesSourceControlDataToNewFormat()
238238
{
239239
IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
240240
IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));
@@ -249,7 +249,9 @@ public void MigratesSingleSourceControlDataToNewFormat()
249249
scList.Add(mock.MockInstance);
250250
}
251251
scList.Add(new MockSourceControl());
252+
scList.Add(new MockSourceControl());
252253

254+
from.SourceControlData.Add(new NameValuePair("test", "first"));
253255
from.SourceControlData.Add(new NameValuePair("commit", "first"));
254256

255257
MultiSourceControl multiSourceControl = new MultiSourceControl();
@@ -259,7 +261,7 @@ public void MigratesSingleSourceControlDataToNewFormat()
259261
ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));
260262

261263
//// VERIFY
262-
Assert.AreEqual(3, to.SourceControlData.Count, "SourceControlData.Count");
264+
Assert.AreEqual(4, to.SourceControlData.Count, "SourceControlData.Count");
263265

264266
List<NameValuePair> list = new List<NameValuePair>();
265267

@@ -269,13 +271,53 @@ public void MigratesSingleSourceControlDataToNewFormat()
269271
Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[1].Value, "SourceControlData[1].Value");
270272
Assert.AreEqual("sc1", to.SourceControlData[1].Name, "SourceControlData[1].Name");
271273

272-
list.Add(new NameValuePair("commit", "first"));
274+
list.Add(new NameValuePair("test", "first"));
273275
Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[2].Value, "SourceControlData[2].Value");
274276
list.Clear();
275277
Assert.AreEqual("sc2", to.SourceControlData[2].Name, "SourceControlData[2].Name");
278+
279+
list.Add(new NameValuePair("commit", "first"));
280+
Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[3].Value, "SourceControlData[3].Value");
281+
list.Clear();
282+
Assert.AreEqual("sc3", to.SourceControlData[3].Name, "SourceControlData[3].Name");
276283
}
277-
278-
[Test]
284+
285+
[Test]
286+
public void MigratesSourceControlDataToNewFormatSameSourceControlCount()
287+
{
288+
IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
289+
IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));
290+
291+
ArrayList scList = new ArrayList();
292+
scList.Add(new MockSourceControl());
293+
scList.Add(new MockSourceControl());
294+
295+
from.SourceControlData.Add(new NameValuePair("test", "first"));
296+
from.SourceControlData.Add(new NameValuePair("commit", "first"));
297+
298+
MultiSourceControl multiSourceControl = new MultiSourceControl();
299+
multiSourceControl.SourceControls = (ISourceControl[])scList.ToArray(typeof(ISourceControl));
300+
301+
//// EXECUTE
302+
ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));
303+
304+
//// VERIFY
305+
Assert.AreEqual(2, to.SourceControlData.Count, "SourceControlData.Count");
306+
307+
List<NameValuePair> list = new List<NameValuePair>();
308+
309+
list.Add(new NameValuePair("test", "first"));
310+
Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value");
311+
list.Clear();
312+
Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name");
313+
314+
list.Add(new NameValuePair("commit", "first"));
315+
Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[1].Value, "SourceControlData[1].Value");
316+
list.Clear();
317+
Assert.AreEqual("sc1", to.SourceControlData[1].Name, "SourceControlData[1].Name");
318+
}
319+
320+
[Test]
279321
public void IfRequireChangesFromAllTrueAndAllSourceControlHasModificationsThenReturnMods()
280322
{
281323
//// SETUP

project/core/sourcecontrol/MultiSourceControl.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,51 @@ public override Modification[] GetModifications(IIntegrationResult from, IIntegr
118118
{
119119
List<NameValuePair> originalSourceControlData = new List<NameValuePair>();
120120
List<NameValuePair> finalSourceControlData = new List<NameValuePair>();
121-
originalSourceControlData.AddRange(from.SourceControlData);
122-
var originalSourceControlDataCount = originalSourceControlData.Count;
123121

124122
var sourceControlDataType = from.SourceControlData.GetType();
125123

124+
// check that the source control data given to us is in the list of list format
125+
// if not, then convert it now
126+
var fromSourceControlDataCount = from.SourceControlData.Count;
127+
if (fromSourceControlDataCount > 0 &&
128+
(fromSourceControlDataCount != SourceControls.Length ||
129+
!XmlConversionUtil.CanConvertXmlToObject(sourceControlDataType, from.SourceControlData[0].Value)
130+
)
131+
)
132+
{
133+
var conversionList = new List<NameValuePair>();
134+
135+
for (int i = 0; i < SourceControls.Length; i++)
136+
originalSourceControlData.Add(new NameValuePair(string.Format("sc{0:d}", i), ""));
137+
138+
int scdIndex = fromSourceControlDataCount - 1;
139+
for (int i = originalSourceControlData.Count - 1; i >= 0; i--)
140+
{
141+
conversionList.Clear();
142+
143+
if (scdIndex >= 0)
144+
if (!XmlConversionUtil.CanConvertXmlToObject(sourceControlDataType, from.SourceControlData[scdIndex].Value))
145+
conversionList.Add(from.SourceControlData[scdIndex]);
146+
147+
originalSourceControlData[i].Value = XmlConversionUtil.ConvertObjectToXml(conversionList);
148+
149+
scdIndex--;
150+
}
151+
152+
}
153+
else
154+
{
155+
originalSourceControlData.AddRange(from.SourceControlData);
156+
}
157+
158+
var originalSourceControlDataCount = originalSourceControlData.Count;
126159
var modificationSet = new Dictionary<Modification, bool>();
127160
int sourceControlIndex = 0;
128161
foreach (ISourceControl sourceControl in SourceControls)
129162
{
130163
from.SourceControlData.Clear();
131-
132-
if (originalSourceControlDataCount > 1 ||
133-
(originalSourceControlDataCount == 1 &&
134-
sourceControlIndex == 0 &&
135-
XmlConversionUtil.CanConvertXmlToObject(sourceControlDataType, originalSourceControlData[0].Value)
136-
)
137-
)
164+
if (sourceControlIndex < originalSourceControlDataCount)
138165
from.SourceControlData.AddRange((List<NameValuePair>)(XmlConversionUtil.ConvertXmlToObject(sourceControlDataType, originalSourceControlData[sourceControlIndex].Value)));
139-
else if ((originalSourceControlDataCount == 1) && (sourceControlIndex == SourceControls.Length - 1))
140-
from.SourceControlData.Add(originalSourceControlData[0]);
141166

142167
to.SourceControlData.Clear();
143168

0 commit comments

Comments
 (0)