views:

350

answers:

1

I'm trying to get into unit tests for a BizTalk application I'm working on, following the example in Michael Stephensons blog post and seemed to be getting somewhere

Then I got an error down the line, which I tracked back to a "invalid" XML test file I was using, but this was passing my validation against schema unit test ...
- reason being incorrect namespace

My puzzlement is why does the XmlReader think the XML is valid vs. the schema, but if I use the BizTalk IDE "Validate Instance" option I get the errors ...
... error BEC2004: Validate Instance failed for schema FromFrontOffice.xsd, file: ...

XmlSchema schema = XmlSchema.Read(schemaStream, null);
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.Schemas.Add(schema);
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.ValidationEventHandler += ValidationEventHandler;
XmlReader xmlReader = XmlReader.Create(xmlStream, xmlReaderSettings);
while (xmlReader.Read())

private void ValidationEventHandler(object sender, ValidationEventArgs args)
{
  if (args.Exception == null) return;
  _IsValid = false;
}
+2  A: 

Think I've sorted it ... trick seems to be using ValidationFlags

xmlReaderSettings.ValidationFlags =
    XmlSchemaValidationFlags.ReportValidationWarnings |
    XmlSchemaValidationFlags.ProcessIdentityConstraints |
    XmlSchemaValidationFlags.ProcessInlineSchema |
    XmlSchemaValidationFlags.ProcessSchemaLocation;
SteveC