|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
| 3 | +using System.Collections.Generic; |
3 | 4 | using Exortech.NetReflector;
|
4 | 5 | using NMock;
|
5 | 6 | using NUnit.Framework;
|
6 | 7 | using ThoughtWorks.CruiseControl.Core;
|
7 | 8 | using ThoughtWorks.CruiseControl.Core.Sourcecontrol;
|
| 9 | +using ThoughtWorks.CruiseControl.Remote; |
8 | 10 |
|
9 | 11 | namespace ThoughtWorks.CruiseControl.UnitTests.Core.Sourcecontrol
|
10 | 12 | {
|
@@ -136,8 +138,186 @@ private DynamicMock CreateModificationsSourceControlMock(Modification[] mods, In
|
136 | 138 | return mock;
|
137 | 139 | }
|
138 | 140 |
|
139 |
| - |
140 |
| - [Test] |
| 141 | + private class MockSourceControl : ISourceControl |
| 142 | + { |
| 143 | + public Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to) |
| 144 | + { |
| 145 | + Assert.AreEqual("first", from.SourceControlData[0].Value, "SourceControlData[0].Value"); |
| 146 | + |
| 147 | + to.SourceControlData.Clear(); |
| 148 | + to.SourceControlData.Add(from.SourceControlData[0]); |
| 149 | + |
| 150 | + return new Modification[] { }; |
| 151 | + } |
| 152 | + |
| 153 | + public void LabelSourceControl(IIntegrationResult result) { } |
| 154 | + public void GetSource(IIntegrationResult result) { } |
| 155 | + public void Initialize(IProject project) { } |
| 156 | + public void Purge(IProject project) { } |
| 157 | + } |
| 158 | + |
| 159 | + |
| 160 | + [Test] |
| 161 | + public void PassesIndividualSourceDataAndCombines() |
| 162 | + { |
| 163 | + IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now); |
| 164 | + IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10)); |
| 165 | + |
| 166 | + string scValue = null; |
| 167 | + List<NameValuePair> list = new List<NameValuePair>(); |
| 168 | + |
| 169 | + list.Add(new NameValuePair("name0", "first")); |
| 170 | + scValue = XmlConversionUtil.ConvertObjectToXml(list); |
| 171 | + from.SourceControlData.Add(new NameValuePair("sc0", scValue)); |
| 172 | + list.Clear(); |
| 173 | + |
| 174 | + list.Add(new NameValuePair("name1", "first")); |
| 175 | + list.Add(new NameValuePair("name2", "first")); |
| 176 | + scValue = XmlConversionUtil.ConvertObjectToXml(list); |
| 177 | + from.SourceControlData.Add(new NameValuePair("sc1", scValue)); |
| 178 | + list.Clear(); |
| 179 | + |
| 180 | + List<ISourceControl> sourceControls = new List<ISourceControl>(); |
| 181 | + sourceControls.Add(new MockSourceControl()); |
| 182 | + sourceControls.Add(new MockSourceControl()); |
| 183 | + |
| 184 | + MultiSourceControl multiSourceControl = new MultiSourceControl(); |
| 185 | + multiSourceControl.SourceControls = sourceControls.ToArray(); |
| 186 | + |
| 187 | + //// EXECUTE |
| 188 | + ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to)); |
| 189 | + |
| 190 | + //// VERIFY |
| 191 | + Assert.AreEqual(from.SourceControlData.Count, to.SourceControlData.Count, "SourceControlData.Count"); |
| 192 | + |
| 193 | + list.Add(new NameValuePair("name0", "first")); |
| 194 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value"); |
| 195 | + list.Clear(); |
| 196 | + Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name"); |
| 197 | + |
| 198 | + list.Add(new NameValuePair("name1", "first")); |
| 199 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[1].Value, "SourceControlData[1].Value"); |
| 200 | + list.Clear(); |
| 201 | + Assert.AreEqual("sc1", to.SourceControlData[1].Name, "SourceControlData[1].Name"); |
| 202 | + } |
| 203 | + |
| 204 | + [Test] |
| 205 | + public void PassesIndividualSourceDataAndCombinesSingleSourceControl() |
| 206 | + { |
| 207 | + IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now); |
| 208 | + IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10)); |
| 209 | + |
| 210 | + string scValue = null; |
| 211 | + List<NameValuePair> list = new List<NameValuePair>(); |
| 212 | + |
| 213 | + list.Add(new NameValuePair("name0", "first")); |
| 214 | + scValue = XmlConversionUtil.ConvertObjectToXml(list); |
| 215 | + from.SourceControlData.Add(new NameValuePair("sc0", scValue)); |
| 216 | + list.Clear(); |
| 217 | + |
| 218 | + List<ISourceControl> sourceControls = new List<ISourceControl>(); |
| 219 | + sourceControls.Add(new MockSourceControl()); |
| 220 | + |
| 221 | + MultiSourceControl multiSourceControl = new MultiSourceControl(); |
| 222 | + multiSourceControl.SourceControls = sourceControls.ToArray(); |
| 223 | + |
| 224 | + //// EXECUTE |
| 225 | + ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to)); |
| 226 | + |
| 227 | + //// VERIFY |
| 228 | + Assert.AreEqual(from.SourceControlData.Count, to.SourceControlData.Count, "SourceControlData.Count"); |
| 229 | + |
| 230 | + list.Add(new NameValuePair("name0", "first")); |
| 231 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value"); |
| 232 | + list.Clear(); |
| 233 | + Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name"); |
| 234 | + } |
| 235 | + |
| 236 | + [Test] |
| 237 | + public void MigratesSourceControlDataToNewFormat() |
| 238 | + { |
| 239 | + IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now); |
| 240 | + IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10)); |
| 241 | + |
| 242 | + ArrayList mocks = new ArrayList(); |
| 243 | + mocks.Add(CreateModificationsSourceControlMock(new Modification[] { }, from, to)); |
| 244 | + mocks.Add(CreateModificationsSourceControlMock(null, from, to)); |
| 245 | + |
| 246 | + ArrayList scList = new ArrayList(); |
| 247 | + foreach (DynamicMock mock in mocks) |
| 248 | + { |
| 249 | + scList.Add(mock.MockInstance); |
| 250 | + } |
| 251 | + scList.Add(new MockSourceControl()); |
| 252 | + scList.Add(new MockSourceControl()); |
| 253 | + |
| 254 | + from.SourceControlData.Add(new NameValuePair("test", "first")); |
| 255 | + from.SourceControlData.Add(new NameValuePair("commit", "first")); |
| 256 | + |
| 257 | + MultiSourceControl multiSourceControl = new MultiSourceControl(); |
| 258 | + multiSourceControl.SourceControls = (ISourceControl[])scList.ToArray(typeof(ISourceControl)); |
| 259 | + |
| 260 | + //// EXECUTE |
| 261 | + ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to)); |
| 262 | + |
| 263 | + //// VERIFY |
| 264 | + Assert.AreEqual(4, to.SourceControlData.Count, "SourceControlData.Count"); |
| 265 | + |
| 266 | + List<NameValuePair> list = new List<NameValuePair>(); |
| 267 | + |
| 268 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value"); |
| 269 | + Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name"); |
| 270 | + |
| 271 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[1].Value, "SourceControlData[1].Value"); |
| 272 | + Assert.AreEqual("sc1", to.SourceControlData[1].Name, "SourceControlData[1].Name"); |
| 273 | + |
| 274 | + list.Add(new NameValuePair("test", "first")); |
| 275 | + Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[2].Value, "SourceControlData[2].Value"); |
| 276 | + list.Clear(); |
| 277 | + 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"); |
| 283 | + } |
| 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] |
141 | 321 | public void IfRequireChangesFromAllTrueAndAllSourceControlHasModificationsThenReturnMods()
|
142 | 322 | {
|
143 | 323 | //// SETUP
|
|
0 commit comments