예제 #1
0
        public void XmlValidationStepTest_SchemaValidationFail()
        {
            var validation          = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
            {
                XmlSchemaPath =
                    @"..\..\TestData\PurchaseOrder.xsd",
                XmlSchemaNameSpace =
                    "http://SendMail.PurchaseOrder"
            };

            validation.XmlSchemas.Add(schemaPurchaseOrder);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "PONumber";
            xpathProductId.XPath       = "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']";
            xpathProductId.Value       = "12323";
            validation.XPathValidations.Add(xpathProductId);

            var ctx  = new Context();
            var data = StreamHelper.LoadFileToStream(@"..\..\TestData\PurchaseOrder003_SchemaValidationFail.xml");

            try
            {
                Assert.Throws <ValidationStepExecutionException>(() => validation.Execute(data, ctx));
            }
            catch (ValidationStepExecutionException vsee)
            {
                Assert.AreEqual("Failed to validate document instance", vsee.Message);
                Assert.AreEqual(
                    @"The 'http://SendMail.PurchaseOrder:PurchaseOrderBAD' element is not declared.",
                    vsee.InnerException.Message);
            }
        }
예제 #2
0
        public void XmlValidationStepTest_InvalidXPath()
        {
            var validation          = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
            {
                XmlSchemaPath =
                    @"..\..\TestData\PurchaseOrder.xsd",
                XmlSchemaNameSpace =
                    "http://SendMail.PurchaseOrder"
            };

            validation.XmlSchemas.Add(schemaPurchaseOrder);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "PONumber";
            xpathProductId.XPath       = "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']";
            xpathProductId.Value       = "12323";
            validation.XPathValidations.Add(xpathProductId);

            var ctx  = new Context();
            var data = StreamHelper.LoadFileToStream(@"..\..\TestData\PurchaseOrder002_BadXPath.xml");

            try
            {
                Assert.Throws <ApplicationException>(() => validation.Execute(data, ctx));
            }
            catch (ApplicationException aex)
            {
                Assert.AreEqual(
                    @"XmlValidationStep failed, compare 12323 != BADBAD, xpath query used: /*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']",
                    aex.Message);
            }
        }
예제 #3
0
        public void XmlValidationStepTest()
        {
            var validation          = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
            {
                XmlSchemaPath =
                    @"..\..\TestData\PurchaseOrder.xsd",
                XmlSchemaNameSpace =
                    "http://SendMail.PurchaseOrder"
            };

            validation.XmlSchemas.Add(schemaPurchaseOrder);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "PONumber";
            xpathProductId.XPath       = "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']";
            xpathProductId.Value       = "12323";
            validation.XPathValidations.Add(xpathProductId);

            var ctx  = new Context();
            var data = StreamHelper.LoadFileToStream(@"..\..\TestData\PurchaseOrder001.xml");

            validation.Execute(data, ctx);
        }
예제 #4
0
        public void XmlValidationStepTest_SchemaValidationFailMissingElem()
        {
            var validation          = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
            {
                XmlSchemaPath      = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder.xsd"),
                XmlSchemaNameSpace = "http://SendMail.PurchaseOrder"
            };

            validation.XmlSchemas.Add(schemaPurchaseOrder);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "PONumber";
            xpathProductId.XPath       = "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']";
            xpathProductId.Value       = "12323";
            validation.XPathValidations.Add(xpathProductId);

            var ctx  = new Context();
            var data = StreamHelper.LoadFileToStream(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PurchaseOrder004_SchemaValidationFailMissingElem.xml"));

            try
            {
                Assert.Throws <ValidationStepExecutionException>(() => validation.Execute(data, ctx));
            }
            catch (ValidationStepExecutionException vsee)
            {
                Assert.AreEqual("Failed to validate document instance", vsee.Message);
                Assert.AreEqual(
                    @"The element 'PurchaseOrder' in namespace 'http://SendMail.PurchaseOrder' has invalid child element 'Description'. List of possible elements expected: 'CustomerInfo'.",
                    vsee.InnerException.Message);
            }
        }
        public void PickListTest_ValidatePickListQuantity()
        {
            var validation     = new XmlValidationStep();
            var schemaPickList = new SchemaDefinition
            {
                XmlSchemaPath      = @"C:\Users\amigupta7\Desktop\Amit\Project\POC\Timewave.BizUnit.Sample\Timewave.BizUnit.Sample\Timewave.BizUnit.Sample\Schemas\PickListSchema.xsd",
                XmlSchemaNameSpace = "http://Timewave.BizTalkUnit.Sample.PickListSchema"
            };

            validation.XmlSchemas.Add(schemaPickList);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "Quantity";
            xpathProductId.XPath       = "/*[local-name()='PickList' and namespace-uri()='http://Timewave.BizTalkUnit.Sample.PickListSchema']/*[local-name()='Items' and namespace-uri()='']/*[local-name()='Quantity' and namespace-uri()='']";;
            xpathProductId.Value       = "3";
            validation.XPathValidations.Add(xpathProductId);

            var ctx = new Context();

            string[] filePaths = Directory.GetFiles(@"C:\Users\amigupta7\Desktop\Amit\Project\POC\Timewave.BizUnit.Sample\Testing\Picklist", "*.xml");
            var      data      = StreamHelper.LoadFileToStream(filePaths[0]);

            validation.Execute(data, ctx);
        }
예제 #6
0
        public void PickListTest_QuantityMisMatch()
        {
            var validation          = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
            {
                XmlSchemaPath      = @"C:\Users\amigupta7\Desktop\Amit\Project\POC\Timewave.BizUnit.Sample\Timewave.BizUnit.Sample\Timewave.BizUnit.Sample\Schemas\PickListSchema.xsd",
                XmlSchemaNameSpace = "http://Timewave.BizTalkUnit.Sample.PickListSchema"
            };

            validation.XmlSchemas.Add(schemaPurchaseOrder);

            var xpathProductId = new XPathDefinition();

            xpathProductId.Description = "Quantity";
            xpathProductId.XPath       = "/*[local-name()='PickList' and namespace-uri()='http://Timewave.BizTalkUnit.Sample.PickListSchema']/*[local-name()='Items' and namespace-uri()='']/*[local-name()='Quantity' and namespace-uri()='']";;
            xpathProductId.Value       = "8";
            validation.XPathValidations.Add(xpathProductId);

            var ctx = new Context();

            string[] filePaths = Directory.GetFiles(@"C:\Users\amigupta7\Desktop\Amit\Project\POC\Timewave.BizUnit.Sample\Testing\Picklist", "*.xml");
            var      data      = StreamHelper.LoadFileToStream(filePaths[0]);

            try
            {
                Assert.Throws <ValidationStepExecutionException>(() => validation.Execute(data, ctx));
            }
            catch (ValidationStepExecutionException vsee)
            {
                Assert.AreEqual("Failed to validate document instance", vsee.Message);
                Assert.AreEqual("The expected value for qauntity is 3", vsee.InnerException.Message);
            }
        }