Beispiel #1
0
        /// <summary>
        /// common procedure that will load all settings in the given directory, and run a report and
        /// compare the result with results
        /// from previous, using the csv and the txt output
        /// </summary>
        public void TestReport(String ASettingsDirectory)
        {
            String[] fileEntries;
            string   fileName;

            if (!Directory.Exists(".." + System.IO.Path.DirectorySeparatorChar + ".." + System.IO.Path.DirectorySeparatorChar + "Reporting" +
                                  System.IO.Path.DirectorySeparatorChar + "TestData" + System.IO.Path.DirectorySeparatorChar + ASettingsDirectory))
            {
                TLogging.Log("Test for " + ASettingsDirectory + " does not exist yet!");
                return;
            }

            try
            {
                /* get all xml files in the given directory (assume we are starting it from testing\_bin\debug */
                fileEntries = Directory.GetFiles(PathToTestData + ASettingsDirectory, "*.xml");

                foreach (string s in fileEntries)
                {
                    fileName = s.Substring(0, s.IndexOf(".xml"));
                    System.Console.Write(Path.GetFileName(fileName) + ' ');
                    FCalculator.ResetParameters();
                    FCalculator.GetParameters().Load(fileName + ".xml");

                    if (FCalculator.GenerateResultRemoteClient())
                    {
                        FCalculator.GetResults().WriteBinaryFile(FCalculator.GetParameters(), "report.bin");

                        FCalculator.GetParameters().Save(
                            PathToTestData + ASettingsDirectory + System.IO.Path.DirectorySeparatorChar + "LogParametersAfterCalc.log",
                            true);
                        FCalculator.GetResults().WriteCSV(
                            FCalculator.GetParameters(), PathToTestData + ASettingsDirectory + System.IO.Path.DirectorySeparatorChar +
                            "LogResults.log",
                            "FIND_BEST_SEPARATOR", true);

                        if (!System.IO.File.Exists(fileName + ".csv"))
                        {
                            /* create a new reference file */
                            FCalculator.GetResults().WriteCSV(FCalculator.GetParameters(), fileName + ".csv");
                        }
                        else
                        {
                            FCalculator.GetResults().WriteCSV(FCalculator.GetParameters(), fileName + ".csv.new");
                        }

                        if (!System.IO.File.Exists(fileName + ".txt"))
                        {
                            /* create a new reference file */
                            PrintTxt(FCalculator.GetResults(), FCalculator.GetParameters(), fileName + ".txt");
                        }
                        else
                        {
                            PrintTxt(FCalculator.GetResults(), FCalculator.GetParameters(), fileName + ".txt.new");
                        }

                        if (System.IO.File.Exists(fileName + ".csv.new"))
                        {
                            /* compare the files */
                            Assert.AreEqual(true, TTextFile.SameContent(fileName + ".csv",
                                                                        fileName + ".csv.new"), "the csv files should be the same: " + fileName);
                            System.IO.File.Delete(fileName + ".csv.new");
                        }

                        if (System.IO.File.Exists(fileName + ".txt.new"))
                        {
                            /* compare the files */
                            /* requires compilation with directive TESTMODE being set, so that the date of the report printout is constant */
                            // TODO: ignore the date, and also ignore the version number
                            // TODO: define sections which should be compared, and which should be ignored. Overwrite with blanks?
                            Assert.AreEqual(true, TTextFile.SameContent(fileName + ".txt",
                                                                        fileName + ".txt.new"), "the txt files should be the same: " + fileName);
                            System.IO.File.Delete(fileName + ".txt.new");
                        }

                        /* todo: test if something was written to the log file (e.g. parameter not found, etc); */
                        /* make a copy of the file before running the report, and compare with the new version */
                        /* this proves difficult, because it runs against the server */
                        /* once the progress of the report is fed back, we can compare the two output files */
                        /* test if there is a detail report */
                        if (FCalculator.GetParameters().Exists("param_detail_report_0") == true)
                        {
                            TestDetailReport(PathToTestData + ASettingsDirectory + System.IO.Path.DirectorySeparatorChar, PathToSettingsData);
                        }
                    }
                    else
                    {
                        Assert.Fail("Report calculation did not finish, was cancelled on the server");
                    }
                }
            }
            catch (Exception e)
            {
                if (e.GetType() != typeof(NUnit.Framework.AssertionException))
                {
                    System.Console.WriteLine(e.Message);
                    System.Console.WriteLine(e.StackTrace);
                }

                throw;
            }
        }