public void ConvertXmlToObjectConvertsCorrectly()
        {
            string xml = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
                                       "timestamp=\"{1:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" result=\"{0}\" />",
                                       ResponseResult.Success,
                                       DateTime.Today);
            object result = XmlConversionUtil.ConvertXmlToObject(typeof(Response), xml);

            Assert.IsInstanceOfType(typeof(Response), result);
            Assert.AreEqual(xml, result.ToString());
        }
        public void ConvertXmlToObjectConvertsCorrectly()
        {
            string xml = string.Format(System.Globalization.CultureInfo.CurrentCulture, "<response xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
                                       "timestamp=\"{1:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" result=\"{0}\" />",
                                       ResponseResult.Success,
                                       DateTime.Today);

            object result = XmlConversionUtil.ConvertXmlToObject(typeof(Response), xml);

            using (new AssertionScope())
            {
                result.Should().BeOfType <Response>();
                XDocument.Parse(result.ToString()).Should().BeEquivalentTo(XDocument.Parse(xml));
            }
        }
Exemplo n.º 3
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);
        }