Microsoft.Protocols.TestSuites.Common.SchemaValidation.GenerateValidationResult C# (CSharp) Method

GenerateValidationResult() public static method

This method is used to generate xml validation result information by using the record errors and warnings.
public static GenerateValidationResult ( ) : string
return string
        public static string GenerateValidationResult()
        {
            StringBuilder sb = new StringBuilder();

            if (XmlValidationWarnings.Count != 0)
            {
                sb.Append("The xml validation warnings:");
                sb.Append(Environment.NewLine);
                foreach (ValidationEventArgs warning in XmlValidationWarnings)
                {
                    sb.Append(warning.Message);
                    sb.Append(Environment.NewLine);
                }
            }

            if (XmlValidationErrors.Count != 0)
            {
                sb.Append("The xml validation errors:");
                foreach (ValidationEventArgs error in XmlValidationErrors)
                {
                    sb.Append(error.Message);
                    sb.Append(Environment.NewLine);
                }
            }

            return sb.ToString();
        }

Usage Example

Example #1
0
        /// <summary>
        /// Validate the response xml.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An CustomerEventArgs that contains event data.</param>
        public void ValidateSchema(object sender, CustomerEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.RawRequestXml))
            {
                this.site.Log.Add(LogEntryKind.Debug, "The raw xml request message is:\r\n{0}", e.RawRequestXml);
                XmlDocument requestXml = new XmlDocument();
                requestXml.LoadXml(e.RawRequestXml);
                SchemaValidation.LastRawRequestXml = requestXml.DocumentElement;
            }
            else
            {
                SchemaValidation.LastRawRequestXml = null;
            }

            if (!string.IsNullOrEmpty(e.RawResponseXml))
            {
                this.site.Log.Add(LogEntryKind.Debug, "The raw xml response message is:\r\n{0}", e.RawResponseXml);

                MemoryStream ms        = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(e.RawResponseXml));
                XmlReader    xmlReader = XmlReader.Create(ms);
                e.ValidationXmlReaderOut = xmlReader;

                XmlDocument responseDoc = new XmlDocument();
                responseDoc.LoadXml(e.RawResponseXml);
                SchemaValidation.LastRawResponseXml = responseDoc.DocumentElement;

                if (this.performSchemaValidation)
                {
                    SchemaValidation.ValidateXml(this.site, this.ignoreSoapFaultSchemaValidationForSoap12);

                    if (this.throwException &&
                        ((ValidationResult.Error == SchemaValidation.ValidationResult) ||
                         (ValidationResult.Warning == SchemaValidation.ValidationResult)))
                    {
                        throw new XmlSchemaValidationException(SchemaValidation.GenerateValidationResult());
                    }
                }
            }
            else
            {
                SchemaValidation.LastRawResponseXml = null;
            }
        }