Testing XML Schema.
Step 1:Create Schema.Xsd
Step 2:
Create Instance of Schema.Xsd
<ns0:Employee xmlns:ns0="http://Company.Demo.Schemas.Employee">
<FirstName>Kumar</FirstName>
<LastName>Janssen</LastName>
<SocialSecurityNumber>330409710</SocialSecurityNumber>
<Type>Full</Type>
<Function>Manager</Function>
<Salary>50000</Salary>
<Bonus>1000</Bonus>
<Pension>1000000</Pension>
</ns0:Employee>
Step 3:
Bizunit
Method for testing Instance.xml
[TestMethod]
public void
TestEmployeeSchema()
{
var employeeTest = new
TestCase { Name = "Test
Schema.Xsd Schema" };
//Create the file validate step
var validatingFileReadStep = new
FileReadMultipleStep
{
DirectoryPath = @"..\..\..\Company.Demo\Company.Demo.Sample.Schemas",
SearchPattern = "Instance.xml",
ExpectedNumberOfFiles = 1,
Timeout = 3000,
DeleteFiles = false
};
//Create an XML Validation step
//This will
check the result against the XSD for the Employee document
var validation = new XmlValidationStep();
var employeeSchema = new
SchemaDefinition
{
XmlSchemaPath =
@"..\..\..\Company.Demo\Company.Demo.Schemas\Sample.xsd",
XmlSchemaNameSpace = "http://Company.Demo.Schemas.Employee"
};
validation.XmlSchemas.Add(employeeSchema);
validatingFileReadStep.SubSteps.Add(validation);
employeeTest.ExecutionSteps.Add(validatingFileReadStep);
//Execute Tests
var bizUnit = new
BizUnit.BizUnit(employeeContractTest);
bizUnit.RunTest();
}
