Ejemplo n.º 1
0
        public void WhenTheValidatorIsCalledWithValidXmlTheErrorEventIsNotFired()
        {
            var customerSchema = xsdFilePaths.FirstOrDefault(w => w.ToLower().Contains("customersorders.xsd"));
            var customerXml    = xmlFilePaths.FirstOrDefault(w => w.ToLower().Contains("customersorders.xml"));

            if (customerSchema == null)
            {
                Assert.Fail("CustomersOrders.xsd File Missing");
            }

            if (customerXml == null)
            {
                Assert.Fail("CustomersOrders.xml File Missing");
            }

            xmlSchemaReader = new XmlSchemaReader(fileSystem, memoryStreamFactory);
            var schema    = xmlSchemaReader.ReadFromPath(customerSchema);
            var schemaSet = new XmlSchemaSet
            {
                XmlResolver = new XmlUrlResolver()
            };

            schemaSet.Add(schema);

            if (schema == null)
            {
                Assert.Fail("Schema could not be loaded");
            }

            var validator = new XmlValidator(memoryStreamFactory, fileSystem, null, null, null, null, null);

            var methodHasNotBeenCalled = true;
            var count = 0;

            validator.ErrorOccurred += async(s, e, c) =>
            {
                await Task.Run(() => { methodHasNotBeenCalled = false; });
            };

            var res = validator.ValidateXmlFileAgainstSchemaAsync(customerXml, schemaSet, true).Result;

            while (count < 10)
            {
                Thread.Sleep(1000);
                if (methodHasNotBeenCalled)
                {
                    break;
                }

                count++;
            }

            Assert.IsTrue(methodHasNotBeenCalled);
        }
Ejemplo n.º 2
0
        public void WhenTheValidatorIsCalledWithMifidValidXmlTheErrorCountIsZero()
        {
            var mifidFile = xmlFilePaths.FirstOrDefault(f => f.Contains("XX_DATTRA_ZZ_000002-0-000001_19.xml"));

            var schemaFiles = new string[]
            {
                xsdFilePaths.FirstOrDefault(f => f.Contains("head.003.001.01.xsd")),
                xsdFilePaths.FirstOrDefault(f => f.Contains("head.001.001.01_ESMAUG_1.0.0.xsd")),
                xsdFilePaths.FirstOrDefault(f => f.Contains("DRAFT15auth.016.001.01_ESMAUG_DATTRA_1.0.3.xsd")),
            };

            if (schemaFiles.Any(a => string.IsNullOrEmpty(a)))
            {
                Assert.Fail("There's a XSD file missing.");
            }

            xmlSchemaReader = new XmlSchemaReader(fileSystem, memoryStreamFactory);

            var schemaSet = new XmlSchemaSet
            {
                XmlResolver = new XmlUrlResolver()
            };

            foreach (var item in schemaFiles)
            {
                schemaSet.Add(xmlSchemaReader.ReadFromPath(item));
            }

            var validator = new XmlValidator(memoryStreamFactory, fileSystem, null, null, null, null, null);

            ValidationFinishedEventArgs validationFinishedEventArgs = null;

            validator.ValidationFinished += async(s, e, c) =>
            {
                await Task.Run(() => { validationFinishedEventArgs = e; });
            };

            var res = validator.ValidateXmlFileAgainstSchemaAsync(mifidFile, schemaSet, true).Result;

            var count = 0;

            while (validationFinishedEventArgs == null && count <= 10)
            {
                count++;
                Thread.Sleep(1000);
            }

            Assert.IsNotNull(validationFinishedEventArgs);
            Assert.AreEqual(0, validationFinishedEventArgs.ErrorCount);
        }
Ejemplo n.º 3
0
        public void WhenTheValidatorIsCalledWithGleifValidXmlTheErrorCountIsZero()
        {
            var mifidFile = xmlFilePaths.FirstOrDefault(f => f.Contains("20190402-0800-gleif-goldencopy-lei2-intra-day.xml"));

            var schemaFiles = new string[]
            {
                //xsdFilePaths.FirstOrDefault(f => f.Contains("xml.xsd")),
                xsdFilePaths.FirstOrDefault(f => f.Contains("2017-03-21_lei-cdf-v2-1.xsd")),
            };

            if (schemaFiles.Any(a => string.IsNullOrEmpty(a)))
            {
                Assert.Fail("There's a XSD file missing.");
            }

            xmlSchemaReader = new XmlSchemaReader(fileSystem, memoryStreamFactory);

            var schemaSet = new XmlSchemaSet
            {
                XmlResolver = new XmlUrlResolver()
            };

            foreach (var item in schemaFiles)
            {
                schemaSet.Add(xmlSchemaReader.ReadFromPath(item));
            }

            var validator = new XmlValidator(memoryStreamFactory, fileSystem);

            ValidationFinishedEventArgs validationFinishedEventArgs = null;

            validator.ValidationFinished += async(s, e, c) =>
            {
                await Task.Run(() => { validationFinishedEventArgs = e; });
            };

            var res = validator.ValidateXmlFileAgainstSchemaAsync(mifidFile, schemaSet, true).Result;

            var count = 0;

            while (validationFinishedEventArgs == null && count <= 10)
            {
                count++;
                Thread.Sleep(1000);
            }

            Assert.IsNotNull(validationFinishedEventArgs);
            Assert.AreEqual(6, validationFinishedEventArgs.ErrorCount);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            fs     = new FileSystem();
            msf    = new MemoryStreamFactory();
            reader = new XmlSchemaReader(fs, msf);

            draftNationalFeedbackSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            finalNationalFeedbackSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            draftInternationalFeedbackSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            finalInternationalFeedbackSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            draftInternationalReportingSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            finalInternationalReportingSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            draftNationalReportingSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            finalNationalReportingSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            gleifSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };
            customerSchemaSet = new XmlSchemaSet {
                XmlResolver = new XmlUrlResolver()
            };

            executingPath = fs.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            xmlSchemasPath = fs.Path.Combine(executingPath, "Files", "Xsd");

            xmlFilesPath = fs.Path.Combine(executingPath, "Files", "Xml");

            xmlSchemaFiles = fs.Directory.GetFiles(xmlSchemasPath).ToArray();

            draftNationalReportingFiles = xmlSchemaFiles
                                          .Where(w =>
                                                 w.Contains("head.001.001.01") ||
                                                 w.Contains("head.003.001.01") ||
                                                 w.Contains("DRAFT15auth.016.001.01_ESMAUG_Reporting_1.0.3"))
                                          .ToArray();

            gleifFiles = xmlSchemaFiles
                         .Where(w =>
                                w.Contains("2017-03-21_lei-cdf-v2-1"))
                         .ToArray();

            customerFiles = xmlSchemaFiles
                            .Where(w =>
                                   w.Contains("CustomersOrders"))
                            .ToArray();

            foreach (var item in customerFiles)
            {
                var schema = reader.ReadFromPath(item);
                customerSchemaSet.Add(schema);
            }

            foreach (var item in gleifFiles)
            {
                var schema = reader.ReadFromPath(item);
                gleifSchemaSet.Add(schema);
            }

            foreach (var item in draftNationalReportingFiles)
            {
                var schema = reader.ReadFromPath(item);
                draftNationalReportingSchemaSet.Add(schema);
            }

            draftInternationalReportingFiles = xmlSchemaFiles
                                               .Where(w =>
                                                      w.Contains("head.001.001.01") ||
                                                      w.Contains("head.003.001.01") ||
                                                      w.Contains("DRAFT15auth.016.001.01_ESMAUG_DATTRA_1.0.3"))
                                               .ToArray();

            foreach (var item in draftInternationalReportingFiles)
            {
                var schema = reader.ReadFromPath(item);
                draftInternationalReportingSchemaSet.Add(schema);
            }

            finalNationalReportingFiles = xmlSchemaFiles
                                          .Where(w =>
                                                 w.Contains("head.001.001.01") ||
                                                 w.Contains("head.003.001.01") ||
                                                 w.Contains("auth.016.001.01_ESMAUG_Reporting_1.1.0"))
                                          .ToArray();

            foreach (var item in finalNationalReportingFiles)
            {
                var schema = reader.ReadFromPath(item);
                finalNationalReportingSchemaSet.Add(schema);
            }

            finalInternationalReportingFiles = xmlSchemaFiles
                                               .Where(w =>
                                                      w.Contains("head.001.001.01") ||
                                                      w.Contains("head.003.001.01") ||
                                                      w.Contains("auth.016.001.01_ESMAUG_DATTRA_1.1.0"))
                                               .ToArray();

            foreach (var item in finalInternationalReportingFiles)
            {
                var schema = reader.ReadFromPath(item);
                finalInternationalReportingSchemaSet.Add(schema);
            }

            draftNationalFeedbackFiles = xmlSchemaFiles
                                         .Where(w =>
                                                w.Contains("head.001.001.01") ||
                                                w.Contains("head.003.001.01") ||
                                                w.Contains("DRAFT5auth.031.001.01_ESMAUG_Reporting_1.0.2"))
                                         .ToArray();

            foreach (var item in draftNationalFeedbackFiles)
            {
                var schema = reader.ReadFromPath(item);
                draftNationalFeedbackSchemaSet.Add(schema);
            }

            draftInternationalFeedbackFiles = xmlSchemaFiles
                                              .Where(w =>
                                                     w.Contains("head.001.001.01") ||
                                                     w.Contains("head.003.001.01") ||
                                                     w.Contains("DRAFT4auth.031.001.01_ESMAUG_FDBTRA_1.0.1"))
                                              .ToArray();

            foreach (var item in draftInternationalFeedbackFiles)
            {
                var schema = reader.ReadFromPath(item);
                draftInternationalFeedbackSchemaSet.Add(schema);
            }

            finalNationalFeedbackFiles = xmlSchemaFiles
                                         .Where(w =>
                                                w.Contains("head.001.001.01") ||
                                                w.Contains("head.003.001.01") ||
                                                w.Contains("auth.031.001.01_ESMAUG_Reporting_1.1.0"))
                                         .ToArray();

            foreach (var item in finalNationalFeedbackFiles)
            {
                var schema = reader.ReadFromPath(item);
                finalNationalFeedbackSchemaSet.Add(schema);
            }

            finalInternationalFeedbackFiles = xmlSchemaFiles
                                              .Where(w =>
                                                     w.Contains("head.001.001.01") ||
                                                     w.Contains("head.003.001.01") ||
                                                     w.Contains("auth.031.001.01_ESMAUG_FDBTRA_1.1.0"))
                                              .ToArray();

            foreach (var item in finalInternationalFeedbackFiles)
            {
                var schema = reader.ReadFromPath(item);
                finalInternationalFeedbackSchemaSet.Add(schema);
            }
        }