public List <string> ValidateTestInstance(string testFileName, string encryptionKey) { List <string> validationResults = new List <string>(); List <string> formatValidationResults = new List <string>(); List <string> dataValidationResults = new List <string>(); // create instance of GP2GP messaging class and use it to consume test data MessageCodec msg = new MessageCodec(); ClinicalDocument cd = new ClinicalDocument(); string templateID = string.Empty; try { // create CDA object from test data & add any message-related errors to list try { if (Path.GetFileName(testFileName).StartsWith("ENC_")) { cd = msg.ConsumeIncomingMessage(testFileName, encryptionKey); } else { cd = msg.ConsumeIncomingMessage(testFileName); } formatValidationResults.AddRange(msg.Errors); } catch (Exception exFormat) { formatValidationResults.Add("Exception : " + exFormat.Message); } // extract & validate CDA - add any errors to list try { foreach (Template tmpl in cd.templates) { templateID = tmpl.oid; if (templateID == this.documentTemplate) { break; } } if (templateID != this.documentTemplate) { formatValidationResults.Add("Invalid Document Template ID " + templateID + " : expected " + this.documentTemplate); } else { cd.ValidateSchema(Specification.GetSchemaLocation()); formatValidationResults.AddRange(cd.schemaErrors); cd.Validate(); dataValidationResults.AddRange(cd.allErrors); } } catch (Exception exData) { dataValidationResults.Add("Exception : " + exData.Message); } } catch (Exception ex) { formatValidationResults.Add("Exception : " + ex.Message); dataValidationResults.Add("Unable to validate due to formatting exception(s)"); } finally { cd = null; msg = null; } validationResults.Add("FORMAT : " + (formatValidationResults.Count < 1 ? "Pass" : "Fail")); validationResults.AddRange(formatValidationResults); validationResults.Add("DATA : " + (dataValidationResults.Count < 1 ? "Pass" : "Fail")); validationResults.AddRange(dataValidationResults); return(validationResults); }