Using NUnit and XMLUnit.NET
I have two test which validate generated Xml document against the schema
First one testing only required elements
<Test>
Public Sub GenerateXmlDocument_WithOnlyRequiredElements_SuccesfullyValidated()
Dim factory As New TestFactory()
Dim schemaConstraint As SchemaValidConstraint = factory.GreateSchemaConstraint()
Dim invoice As factory.CreateInvoiceWithOnlyRequiredValues()
Dim service As New MyService()
Dim result As XmlDocument = service.GenerateXmlDocument(invoice)
Dim documentSource As ISource = Input.FromDocument(result).Build()
Assert.That(documentSource, schemaConstraint)
End Sub
Second testing all elements
<Test>
Public Sub GenerateXmlDocument_WithAllElements_SuccesfullyValidated()
Dim factory As New TestFactory()
Dim schemaConstraint As SchemaValidConstraint = factory.GreateSchemaConstraint()
Dim invoice As factory.CreateInvoiceWithAllValues()
Dim service As New MyService()
Dim result As XmlDocument = service.GenerateXmlDocument(invoice)
Dim documentSource As ISource = Input.FromDocument(result).Build()
Assert.That(documentSource, schemaConstraint)
End Sub
Both tests cover almost all needed cases as element's type, order and requiring.
Except situation when schema contain a element with minOccurs="0" maxOccurs="1"
and that element missing from Xml document generated in the second test(WithAllElements).
Question: Is there a assert/validate method which can handled all elements in schema as required?
I want this for situation when new element need to be added. Then adding new element, event with minOccurs="0"
will break a test.