Tuesday, 29 January 2013

Unit Testing Biztalk 2010 Artifacts using BizUnit 4.0


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();
        }

10 comments:

  1. could you please provide similar similar code for flat file validation as well? i tried a lot with multiple options but not getting any where

    ReplyDelete
  2. Enable unit testing of Biztalk Project , then try code

    TestableSchemaBase _Schema = new SchemaName();
    bool result = _Schema.ValidateInstance(@"FilePath", OutputInstanceType.XML);
    Assert.IsTrue(result, "Validation Failed");

    TestableSchemaBase _Schema = new SchemaName_FF();
    bool result = _Schema.ValidateInstance(@"TextFilePath", OutputInstanceType.Native);
    Assert.IsTrue(result, "Validation Failed");

    ReplyDelete
  3. Biztalk server online training - 21st Century Software Solutions
    http://www.21cssindia.com/courses/biztalk-server-online-training-213.html
    ఈ పేజీని అనువదించు
    biztalk server online training, biztalk server training, biztalk server online training visakhapatnam, biztalk 2010 online training, microsoft biztalk online training, ...
    Biztalk admin online training - 21st Century Software Solutions
    http://www.21cssindia.com/courses/biztalk-admin-online-training-220.html
    ఈ పేజీని అనువదించు
    biztalk admin online training, biztalk admin training, biztalk server online training, biztalk server training, biztalk admin course contents, biztalk admin enquiry, .Courses at 21st Century Software Solutions
    Talend Online Training -Hyperion Online Training - IBM Unica Online Training -
    Siteminder Online Training - SharePoint Online Training - Informatica Online Training
    SalesForce Online Training - Many more… | Call Us +917386622889
    Visit: http://www.21cssindia.com/courses.html

    ReplyDelete
  4. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai

    ReplyDelete
  5. Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!

    python Training in chennai

    python Course in chennai


    ReplyDelete