示例#1
0
        static void Execute(ArgumentInfo arginfo)
        {
            string disp_se      = ResultStatus.SyntaxError.DisplayName();
            string disp_fa      = ResultStatus.Assert.DisplayName();
            string disp_sr      = ResultStatus.Report.DisplayName();
            string reportheader = $"{disp_se} | {disp_fa} | {disp_sr}";
            string reportborder = new string('-', reportheader.Length);

            Console.ForegroundColor = ConsoleColor.Gray;

            SchemaDocument doc = null;

            try
            {
                doc = new SchemaDocument();

                doc.Open(arginfo.SchFile.FullName);
                doc.Compile(arginfo.Phase);

                ResultCollection results = new ResultCollection();
                foreach (FileInfo xmlfile in arginfo.XmlFiles)
                {
                    Console.WriteLine("");
                    Console.WriteLine($"> Validation Start of '{xmlfile.Name}' by '{doc.SchemaTmp.Name}'");

                    ResultCollection file_results = doc.Validation(xmlfile.FullName);

                    string se = String.Format("{0, " + disp_se.Length + "}", file_results.TotalSyntaxError);
                    string fa = String.Format("{0, " + disp_fa.Length + "}", file_results.TotalAssert);
                    string sr = String.Format("{0, " + disp_sr.Length + "}", file_results.TotalReport);
                    Console.WriteLine("  " + reportborder);
                    Console.WriteLine("  " + reportheader);
                    Console.WriteLine($"  {se} | {fa} | {sr}");
                    Console.WriteLine("  " + reportborder);

                    Console.WriteLine("> End of Validation");

                    results.AddRange(file_results);
                }
                if (results.Count > 0 && arginfo.OutFile != null)
                {
                    Reporter report = new Reporter();
                    report.Results = results;
                    IReportStrategy strategy = EmbeddReportStrategies.Find(arginfo.OutFormat);
                    if (strategy == null)
                    {
                        strategy = new ReportDefaultStrategy();
                    }

                    report.Write(arginfo.OutFile.FullName, strategy);
                }
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("");
                Console.WriteLine("COMPLETE!");
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("");
                Console.WriteLine("ERROR!");
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc?.Dispose();
            }
        }
示例#2
0
        public void SchemaDocumentTest()
        {
            string        dir   = @"../../../../../testdata/";
            List <string> tests = new List <string>()
            {
                "mimetype",
                "cultures",
                "calendar-2017"
            };

            SchemaDocument        doc      = null;
            Reporter              report   = new Reporter();
            Func <string, string> replacer = new Func <string, string>((str) =>
            {
                return(Regex.Replace(str, "<div class=\"dateinfo\">(.+?)</div>", ""));
            });

            try
            {
                Stopwatch sw = Stopwatch.StartNew();

                PrintWorkingSet($"start of processing: ({DateTime.Now.ToShortTimeString()})");

                foreach (string test in tests)
                {
                    PrintWorkingSet($"pre processing of {test}");

                    string testsch = Path.Combine(dir, $"{test}.sch");
                    string testxml = Path.Combine(dir, $"{test}.xml");
                    string dstfile = Path.Combine(dir, $"{test}-result.json");
                    if (!File.Exists(testsch))
                    {
                        throw new FileNotFoundException();
                    }
                    if (!File.Exists(testxml))
                    {
                        throw new FileNotFoundException();
                    }

                    doc = new SchemaDocument();

                    doc.Open(testsch);
                    doc.Compile(Phase.ALL);

                    report.Results = doc.Validation(testxml);

#if true
                    report.Write(dstfile, new ReportJsonStrategy());
#else
                    // test result
                    string result = report.ToString(ExportFormats.Html);
                    // trusted result
                    string expected = File.ReadAllText(dstfile, Encoding.UTF8);

                    result   = replacer(result);
                    expected = replacer(expected);

                    Assert.AreEqual(result, expected, $"{test} not equals.");
#endif

                    doc?.Dispose();

                    PrintWorkingSet($"post processing of {test}");
                }

                sw.Stop();
                PrintWorkingSet($"end of processing: ({DateTime.Now.ToShortTimeString()}, {sw.ElapsedMilliseconds} ms)");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
            }
        }