Example #1
0
        protected FilingSummary BuildAndVerifyRecursive(string folder, string instanceName, string taxonomyName)
        {
            Console.WriteLine("=================================================");
            Console.WriteLine("  BUILD AND VERIFY " + folder + "...");
            Console.WriteLine("=================================================");

            string baselineResultFolder = PathCombine(this.baseDir, folder, "Results");

            this.resultsPath = baselineResultFolder;

            if (!BuildAndVerifyWithoutResults && !Directory.Exists(this.resultsPath))
            {
                throw new Exception("There are no results to verify againsts.");
            }

            string generatedResultFolder = PathCombine(this.baseDir, folder, "Reports");

            this.reportsPath = generatedResultFolder;

            string failedResultsFolder = Path.GetDirectoryName(generatedResultFolder);

            failedResultsFolder = Path.Combine(failedResultsFolder, "Failures");
            CleanAndPrepareFolder(failedResultsFolder);

            FilingSummary fs = BuildFiling(folder, instanceName, taxonomyName);

            using (ErrorWriter writer = new ErrorWriter())
            {
                ExtendedDirectoryInfo baselineResultInfo  = new ExtendedDirectoryInfo(baselineResultFolder);
                ExtendedDirectoryInfo generatedResultInfo = new ExtendedDirectoryInfo(generatedResultFolder);
                VerifyIndividualReports(writer, baselineResultInfo, generatedResultInfo, failedResultsFolder);
                VerifyCharts(writer, baselineResultInfo, generatedResultInfo);

                if (writer.HasErrors)
                {
                    writer.Flush();
                    writer.SaveResults(failedResultsFolder);

                    Console.Write(writer.GetStringBuilder().ToString().Trim());
                    throw new Exception(writer.GetStringBuilder().ToString().Trim());
                }
            }

            return(fs);
        }
Example #2
0
        public void EndReport( string file )
        {
            this.WriteLine( "*************************Comparison ENDED " + file + "*************************" );
            this.WriteLine();

            ErrorWriter report = this._reports.Pop();
            if( report.HasErrors )
            {
                report.Flush();

                if( this.currentReport == null )
                {
                    this.Errors += report.Errors;
                    report.SaveFailedFiles();
                }
                else
                {
                    this.currentReport.Errors += report.Errors;
                }

                this.Write( report.GetStringBuilder().ToString().Trim() );
            }
        }
Example #3
0
        /// <summary>
        /// Runs a test on the given base (could be either a folder or zip file containing R Files).  The method can
        /// accept either a zip or a folder of R files.  The name of the folder/zip of the new files must match that
        /// of the base path.
        /// </summary>
        /// <param name="testSummary"></param>
        /// <param name="testErrors"></param>
        /// <param name="baseZipOrDir"></param>
        public static void RunTest( FilingResult testSummaryItem, StringBuilder testErrors, string baseZipOrDir )
        {
            // The name of the filing is used to build all paths
            testSummaryItem.Name = Path.GetFileNameWithoutExtension( baseZipOrDir );
            string filingLogFolder = Test_Abstract.PathCombine( AutoTester.logPath, testSummaryItem.Name );

            // Preparing (clean/create) folders for output
            Test_Abstract.CleanAndPrepareFolder(filingLogFolder);

            int errorCount = 0;

            IDirectoryInfo baseDirInfo = null;
            IDirectoryInfo newDirInfo = null;

            try
            {
                // The base can be a directory, and if it is, then it needs to be handled differently.
                if (Directory.Exists(baseZipOrDir))
                {
                    baseDirInfo = new ExtendedDirectoryInfo( baseZipOrDir );
                }
                else if (File.Exists(baseZipOrDir))
                {
                    baseDirInfo = new ZipDirectoryInfo( baseZipOrDir );
                }
                else
                {
                    // This shouldn't occur if the method was called from a file listing, but handle anyway
                    string message = "The the zip or folder for the Base filing was missing.  Tried to process the following as a directory and zip file: \r\n\t";
                    message += baseZipOrDir;

                    string resultPath = Test_Abstract.PathCombine(filingLogFolder, "Base Filing Zip or Folder Missing.txt");
                    File.WriteAllText(resultPath, message);

                    testSummaryItem.Success = false;
                    testSummaryItem.Reason = "The base file name given to the processor could not be found.";
                    return;
                }

                // When picking the new files, prefer directory over zip
                if( Directory.Exists( Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name) ) )
                {
                    string dirPath = Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name );
                    newDirInfo = new ExtendedDirectoryInfo( dirPath );
                }
                else if( File.Exists( Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" ) ) )
                {
                    string zipPath = Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" );
                    newDirInfo = new ZipDirectoryInfo( zipPath );
                }
                else
                {
                    string message = "The the zip or folder for the New filing was missing.  Tried the directory: \r\n\t";
                    message += Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name );
                    message += "\r\nAnd the file: \r\n\t";
                    message += Test_Abstract.PathCombine( AutoTester.newFilingsPath, testSummaryItem.Name + ".zip" );

                    string resultPath = Test_Abstract.PathCombine(filingLogFolder, "New Filing Zip or Folder Missing.txt");
                    File.WriteAllText(resultPath, message);

                    testSummaryItem.Success = false;
                    testSummaryItem.Reason = "The new file corresponding to the base file could not be found.";
                    return;
                }

                //
                using (ErrorWriter writer = new ErrorWriter())
                {
                    Test_Abstract.VerifyIndividualReports(writer, baseDirInfo, newDirInfo, filingLogFolder);
                    Test_Abstract.VerifyCharts( writer, baseDirInfo, newDirInfo );

                    if (writer.HasErrors)
                    {
                        writer.Flush();
                        writer.SaveResults(filingLogFolder);

                        testSummaryItem.Errors = writer.Errors;
                        testSummaryItem.Success = true;
                        testSummaryItem.Reason = "See error log.";

                        testErrors.AppendFormat( "Error in: {0}\r\n{1}\r\n\r\n\r\n", testSummaryItem.Name, writer.GetStringBuilder().ToString().Trim() );
                    }
                    else
                    {
                        testSummaryItem.Success = true;
                    }

                    errorCount = writer.Errors;
                }
            }
            catch (Exception e)
            {
                testSummaryItem.Success = false;
                testSummaryItem.Reason = "Exception) "+ e.Message;
            }
            finally
            {
                if( errorCount == 0 )
                {
                    try
                    {
                        Directory.Delete( filingLogFolder, true );
                    }
                    catch { }
                }
            }
        }