public void PassesIndividualSourceDataAndCombinesSingleSourceControl()
        {
            IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
            IntegrationResult to   = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

            string scValue            = null;
            List <NameValuePair> list = new List <NameValuePair>();

            list.Add(new NameValuePair("name0", "first"));
            scValue = XmlConversionUtil.ConvertObjectToXml(list);
            from.SourceControlData.Add(new NameValuePair("sc0", scValue));
            list.Clear();

            List <ISourceControl> sourceControls = new List <ISourceControl>();

            sourceControls.Add(new MockSourceControl());

            MultiSourceControl multiSourceControl = new MultiSourceControl();

            multiSourceControl.SourceControls = sourceControls.ToArray();

            //// EXECUTE
            ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

            //// VERIFY
            Assert.AreEqual(from.SourceControlData.Count, to.SourceControlData.Count, "SourceControlData.Count");

            list.Add(new NameValuePair("name0", "first"));
            Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value");
            list.Clear();
            Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name");
        }
        public void MigratesSourceControlDataToNewFormatSameSourceControlCount()
        {
            IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
            IntegrationResult to   = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

            ArrayList scList = new ArrayList();

            scList.Add(new MockSourceControl());
            scList.Add(new MockSourceControl());

            from.SourceControlData.Add(new NameValuePair("test", "first"));
            from.SourceControlData.Add(new NameValuePair("commit", "first"));

            MultiSourceControl multiSourceControl = new MultiSourceControl();

            multiSourceControl.SourceControls = (ISourceControl[])scList.ToArray(typeof(ISourceControl));

            //// EXECUTE
            ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

            //// VERIFY
            Assert.AreEqual(2, to.SourceControlData.Count, "SourceControlData.Count");

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

            list.Add(new NameValuePair("test", "first"));
            Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[0].Value, "SourceControlData[0].Value");
            list.Clear();
            Assert.AreEqual("sc0", to.SourceControlData[0].Name, "SourceControlData[0].Name");

            list.Add(new NameValuePair("commit", "first"));
            Assert.AreEqual(XmlConversionUtil.ConvertObjectToXml(list), to.SourceControlData[1].Value, "SourceControlData[1].Value");
            list.Clear();
            Assert.AreEqual("sc1", to.SourceControlData[1].Name, "SourceControlData[1].Name");
        }
        public void GetModificationsRepeatedlyShouldReturnSameResult()
        {
            IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
            IntegrationResult to   = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

            string scValue            = null;
            List <NameValuePair> list = new List <NameValuePair>();

            list.Add(new NameValuePair("name0", "first"));
            scValue = XmlConversionUtil.ConvertObjectToXml(list);
            from.SourceControlData.Add(new NameValuePair("sc0", scValue));
            list.Clear();

            list.Add(new NameValuePair("name1", "first"));
            list.Add(new NameValuePair("name2", "first"));
            scValue = XmlConversionUtil.ConvertObjectToXml(list);
            from.SourceControlData.Add(new NameValuePair("sc1", scValue));
            list.Clear();

            List <ISourceControl> sourceControls = new List <ISourceControl>();

            sourceControls.Add(new MockSourceControl());
            sourceControls.Add(new MockSourceControl());

            MultiSourceControl multiSourceControl = new MultiSourceControl();

            multiSourceControl.SourceControls = sourceControls.ToArray();

            //// EXECUTE
            try
            {
                ArrayList firstReturnedMods  = new ArrayList(multiSourceControl.GetModifications(from, to));
                ArrayList secondReturnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));
                ArrayList thirdReturnedMods  = new ArrayList(multiSourceControl.GetModifications(from, to));

                Assert.AreEqual(secondReturnedMods.Count, thirdReturnedMods.Count);
            } catch (Exception e)
            {
                Assert.Fail("GetModifications threw Exception:" + e.Message);
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            List <NameValuePair> originalSourceControlData = new List <NameValuePair>();
            List <NameValuePair> finalSourceControlData    = new List <NameValuePair>();

            var sourceControlDataType = from.SourceControlData.GetType();

            // check that the source control data given to us is in the list of list format
            // if not, then convert it now
            var fromSourceControlDataCount = from.SourceControlData.Count;

            if (fromSourceControlDataCount > 0 &&
                (fromSourceControlDataCount != SourceControls.Length ||
                 !XmlConversionUtil.CanConvertXmlToObject(sourceControlDataType, from.SourceControlData[0].Value)
                )
                )
            {
                var conversionList = new List <NameValuePair>();

                for (int i = 0; i < SourceControls.Length; i++)
                {
                    originalSourceControlData.Add(new NameValuePair(string.Format("sc{0:d}", i), ""));
                }

                int scdIndex = fromSourceControlDataCount - 1;
                for (int i = originalSourceControlData.Count - 1; i >= 0; i--)
                {
                    conversionList.Clear();

                    if (scdIndex >= 0)
                    {
                        if (!XmlConversionUtil.CanConvertXmlToObject(sourceControlDataType, from.SourceControlData[scdIndex].Value))
                        {
                            conversionList.Add(from.SourceControlData[scdIndex]);
                        }
                    }

                    originalSourceControlData[i].Value = XmlConversionUtil.ConvertObjectToXml(conversionList);

                    scdIndex--;
                }
            }
            else
            {
                originalSourceControlData.AddRange(from.SourceControlData);
            }

            var originalSourceControlDataCount = originalSourceControlData.Count;
            var modificationSet    = new Dictionary <Modification, bool>();
            int sourceControlIndex = 0;

            foreach (ISourceControl sourceControl in SourceControls)
            {
                from.SourceControlData.Clear();
                if (sourceControlIndex < originalSourceControlDataCount)
                {
                    from.SourceControlData.AddRange((List <NameValuePair>)(XmlConversionUtil.ConvertXmlToObject(sourceControlDataType, originalSourceControlData[sourceControlIndex].Value)));
                }

                to.SourceControlData.Clear();

                Modification[] mods = sourceControl.GetModifications(from, to);

                finalSourceControlData.Add(new NameValuePair(string.Format("sc{0:d}", sourceControlIndex), XmlConversionUtil.ConvertObjectToXml(to.SourceControlData)));

                if (mods != null && mods.Length > 0)
                {
                    foreach (var mod in mods)
                    {
                        modificationSet[mod] = true;
                    }
                }
                else if (RequireChangesFromAll)
                {
                    modificationSet.Clear();
                    break;
                }

                sourceControlIndex++;
            }

            to.SourceControlData.Clear();
            to.SourceControlData.AddRange(finalSourceControlData);

            var modArray = new Modification[modificationSet.Count];

            modificationSet.Keys.CopyTo(modArray, 0);
            return(modArray);
        }