Exemplo n.º 1
0
        /// <summary>
        /// GetXmlFromTemplate
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="filename"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public string GetXmlFromTemplate(Assembly assembly, string filename, string[] args = null)
        {
            string result = string.Empty;

            try
            {
                XmlTemplate xmltemplate = new XmlTemplate();
                xmltemplate.LoadFromResource(assembly, filename);
                xmltemplate.Execute(args);

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xmltemplate.InstanceAsXmlString());
                if (xmlDocument.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
                {
                    xmlDocument.RemoveChild(xmlDocument.FirstChild);
                }

                result = xmlDocument.OuterXml;
            }
            catch (SystemException contextualException)
            {
                Console.WriteLine("Unable to obtain {0}", filename);
                if (!contextualException.Message.Contains("Error loading XML template from resource"))
                {
                    throw contextualException;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Detemines if the output of the map is equal to the expected XML file.
        /// Outputs using Side by Side
        /// </summary>
        /// <param name="assembly">The Test assembly</param>
        /// <param name="newXmlDocument">output generated by the map</param>
        /// <param name="expectedXmlFilePath">location of the referenced XML file ie: TestFiles.ProcessWorkCompletion.ToHost.Electric.MeterRemove.FormSubmittedMessage_To_WorkCanonical_ExpectedResult.xml</param>
        /// <param name="arguments">values passed into the XmlTemplate.Execute() method if the expected XML file is a template</param>
        /// <returns>true or false</returns>
        public bool IsXmlDifferent(Assembly assembly, XmlDocument newXmlDocument, string expectedXmlFilePath, object[] arguments = null, string[] ignoredLines = null)
        {
            XmlTemplate xmltemplate = new XmlTemplate();

            xmltemplate.LoadFromResource(assembly, expectedXmlFilePath);
            xmltemplate.Execute(arguments);

            XmlDocument expectedXmlDocument = xmltemplate.InstanceAsXmlDocument();

            string originalText = XElement.Parse(expectedXmlDocument.OuterXml).ToString();
            string newText      = XElement.Parse(newXmlDocument.OuterXml).ToString();

            // Were there differences
            return(SideBySideCompare(originalText, newText, ignoredLines: ignoredLines));
        }