/// <summary> /// Constructs a flat file disassembler for the given flat file schema. /// </summary> /// <param name="schema">The flat file schema to be used for disassembling flat files.</param> public FlatFileDasm(TestableSchemaBase schema) { // Save the schema and create a temporary file for it. // Use Unicode as expected by the flat file disassembler. _schema = schema; _schemaFile = new TempFile(_schema.XmlContent, "xsd", Encoding.Unicode); }
public static ValidationResult ValidateSchema(TestableSchemaBase schemaObject, string xmlInstancePath) { XmlReaderSettings settings = new XmlReaderSettings(); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schemaObject.Schema); settings.Schemas = schemaSet; settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += new ValidationEventHandler(SchemaReaderSettingsValidationEventHandler); using (XmlReader reader = XmlReader.Create(xmlInstancePath, settings)) { _IsValid = true; while (reader.Read()) { if (!_IsValid) { break; } } } return(new ValidationResult() { IsValid = _IsValid, ValidationMessage = validationMessage }); }
/// <summary> /// Constructs an xml validation result for the given instance of an XML Instance Stream against the given schema. /// </summary> /// <param name="schemaObject">The object of the schema based class.</param> /// <param name="xmlInstanceStream">The stream representation of the XML Instance.</param> public XmlValidationResult(TestableSchemaBase schemaObject, Stream xmlInstanceStream) { XmlReaderSettings settings = new XmlReaderSettings(); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schemaObject.Schema); settings.Schemas = schemaSet; settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += new ValidationEventHandler(SchemaReaderSettingsValidationEventHandler); using (XmlReader reader = XmlReader.Create(xmlInstanceStream, settings)) { while (reader.Read()) { if (!isValid) { break; } } } }
/// <summary> /// Constructs an xml validation result for the given XmlDocument against the given schema. /// </summary> /// <param name="schemaObject">The object of the schema based class.</param> /// <param name="document">The XmlDocument instance.</param> public XmlValidationResult(TestableSchemaBase schemaObject, XmlDocument document) { XmlReaderSettings settings = new XmlReaderSettings(); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schemaObject.Schema); settings.Schemas = schemaSet; settings.ValidationType = ValidationType.Schema; settings.ValidationEventHandler += new ValidationEventHandler(SchemaReaderSettingsValidationEventHandler); StringReader stringReader = new StringReader(document.InnerXml); using (XmlReader reader = XmlReader.Create(stringReader, settings)) { while (reader.Read()) { if (!isValid) { break; } } } }
/// <summary> /// ExecuteMapTest /// </summary> /// <typeparam name="Map"></typeparam> /// <param name="inputMessage"></param> /// <param name="expectedResultReference"></param> /// <param name="targetSchema"></param> /// <param name="validateXmlOutput"></param> /// <param name="extObjects"></param> /// <param name="testContext"></param> /// <returns></returns> public string ExecuteMapTest <Map>(Assembly assembly, string inputMessage, string expectedResultReference, TestableSchemaBase targetSchema = null, bool validateXmlOutput = true, string extObjects = null, TestContext testContext = null, object[] expectedResultArguments = null, string[] ignoredLines = null) where Map : TestableMapBase, new() { var mapTestHelper = new MapTestHelper(); TestableMapBase map = new Map(); // Execute the map and load the output. string result = mapTestHelper.ExecuteMap(map, inputMessage, extObjects); XmlDocument output = new XmlDocument(); output.LoadXml(result); if (testContext != null) { testContext.WriteLine("{0}", output.OuterXml); } if (validateXmlOutput) { // Perform XML Schema validation on the output. XmlValidationResult xmlValidationResult = new XmlValidationResult(targetSchema, output); Assert.IsTrue(xmlValidationResult.IsValid, map.ToString() + " test failed. The output file was not valid. " + xmlValidationResult.Message); } Assert.IsFalse(mapTestHelper.IsXmlDifferent(assembly, output, expectedResultReference, arguments: expectedResultArguments, ignoredLines: ignoredLines), "Differences exist."); return(result); }