BizTalk Unit Testing Issue while validating instances against the Flat File Schemas

Consider the following scenario:
You are validating an instance against a Flat File Schema using the Validate Instance Option.

You are able to validate the schema successfully and get the validate Instance output as true.

Now if you are using BizTalk Unit Testing to validate the instance against the schema the following statement:

Assert.IsTrue(target.ValidateInstance(instanceFilePath, OutputInstanceType.Native));
might return False

This scenario will happen in case if you are using Imports while creating the Flat File Schema. 


This is a known issue with BizTalk Server 2010, that in case if we are trying to validate an instance against a Flat File Schema, which contains other imported schema then it would return False, even though the instance is valid. 
Here is a workaround that can be used for BizTalk Unit testing to validate such schema instances. 
You need to write the following code:

    public class UnitTest
        private TestContext testContextInstance;       

        ///Gets or sets the test context which provides 
        ///information about and functionality for the current test run. 

        public TestContext TestContext
            {               return testContextInstance;

                            testContextInstance = value;


// Make sure that the schemas that are imported while creating a flat file schema are deployed first.

public void TestMethod1()
var target = new SchemaMethod();
string instanceFilePath = @”C:\Instance.txt”;  

//Make sure to manually copy the schemas with full name space.      
File.Copy(@”C:\Import1.xsd” , testContextInstance.DeploymentDirectory + \\Import1);
File.Copy(@”C:\Import2.xsd” , testContextInstance.DeploymentDirectory + \\Import2);
File.Copy(@”C:\Import3.xsd”, testContextInstance.DeploymentDirectory + \\Import3);           

bool check = target.ValidateInstance(instanceFilePath, OutputInstanceType.Native);
Assert.IsTrue(target.ValidateInstance(instanceFilePath, OutputInstanceType.Native));

You would now be able to validate the instances for Flat File Schemas having Imported Schemas.

Written by
Rasika Chaudhary

Reviewed by
Jainath V R 

Microsoft India GTSC





Comments (1)

  1. David Robinson says:

    Hi there,

    I'm using BizTalk 2013 and have the same problem with imported types for flat file schemas. However, using the sample above I cannot still get it to work. Any other ideas?