Exemple #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);
        }
Exemple #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));
        }
Exemple #3
0
 /// <summary>
 /// Constructs a temporary file in the current directory for the current instance of an XmlTemplate.
 /// The file will have UTF-8 encoding and the extension "xml".
 /// </summary>
 /// <param name="xmlTemplate">An XmlTemplate containing the XML content to be used for the temporary file.</param>
 public TempFile(XmlTemplate xmlTemplate)
 {
     try
     {
         _directory = Directory.GetCurrentDirectory();
         _name      = Guid.NewGuid().ToString();
         _extension = "xml";
         _filePath  = Path.Combine(_directory, _name + "." + _extension);
         _encoding  = Encoding.UTF8;
         WriteContent(xmlTemplate.InstanceAsXmlString());
     }
     catch (Exception exception)
     {
         //ContextualException contextualException = new ContextualException( "Error creating temporary file " + _filePath + ".", exception );
         //contextualException.EventType = EventLogEntryType.Error;
         //contextualException.EventId = 405;
         //ExceptionManager.HandleException( contextualException, PolicyName.SystemException );
         throw exception;
     }
 }