Beispiel #1
0
        public static void VerifyIndividualReports(ErrorWriter writer, IDirectoryInfo baselineResultInfo, IDirectoryInfo generatedResultInfo, string failedResultsFolder)
        {
            IFileInfo[] baseFiles = new IFileInfo[0];
            if (baselineResultInfo.Exists)
            {
                baseFiles = baselineResultInfo.GetFiles("R*.xml");
                Array.Sort(baseFiles, natcasecmp);
            }

            IFileInfo[] genFiles = new IFileInfo[0];
            if (generatedResultInfo.Exists)
            {
                genFiles = generatedResultInfo.GetFiles("R*.xml");
                Array.Sort(genFiles, natcasecmp);
            }

            if (baseFiles.Length < genFiles.Length)
            {
                writer.StartError("The new rendering generated too MANY files:");
                for (int i = 0; i < genFiles.Length; i++)
                {
                    bool found = Array.Exists(baseFiles, bFile => string.Equals(bFile.Name, genFiles[i].Name));
                    if (!found)
                    {
                        writer.WriteError("\tAdded:  " + genFiles[i].Name);
                    }
                }
                writer.EndError();
            }
            else if (baseFiles.Length > genFiles.Length)
            {
                writer.StartError("The new rendering generated too FEW files.");
                for (int i = 0; i < baseFiles.Length; i++)
                {
                    bool found = Array.Exists(genFiles, gFile => string.Equals(gFile.Name, baseFiles[i].Name));
                    if (!found)
                    {
                        writer.WriteError("\tAdded:  " + baseFiles[i].Name);
                    }
                }
                writer.EndError();
            }

            Dictionary <string, int> allFiles = new Dictionary <string, int>();

            foreach (IFileInfo bFile in baseFiles)
            {
                allFiles[bFile.Name] = 1;
            }

            foreach (IFileInfo gFile in genFiles)
            {
                allFiles[gFile.Name] = 1;
            }

            Dictionary <string, InstanceReport> tryVerifyEmbedded = new Dictionary <string, InstanceReport>();

            foreach (string file in allFiles.Keys)
            {
                if (!R_FILE_REGEX.IsMatch(file))
                {
                    continue;
                }

                InstanceReport baseReport = null;
                InstanceReport genReport  = null;

                try
                {
                    if (baselineResultInfo.FileExists(file))
                    {
                        using (Stream fileStream = baselineResultInfo.OpenStream(file))
                        {
                            baseReport = InstanceReport.LoadXmlStream(fileStream);
                        }
                    }

                    if (generatedResultInfo.FileExists(file))
                    {
                        using (Stream fileStream = generatedResultInfo.OpenStream(file))
                        {
                            genReport = InstanceReport.LoadXmlStream(fileStream);
                        }
                    }

                    if (baseReport == null)
                    {
                        throw new Exception("Base report is missing.");
                    }
                    else
                    {
                        foreach (InstanceReportRow row in baseReport.Rows)
                        {
                            foreach (Cell cell in row.Cells)
                            {
                                cell.FlagID = 0;
                            }
                        }
                    }

                    if (genReport == null)
                    {
                        throw new Exception("Generated report is missing.");
                    }
                    else
                    {
                        foreach (InstanceReportRow row in baseReport.Rows)
                        {
                            foreach (Cell cell in row.Cells)
                            {
                                cell.FlagID = 0;
                            }
                        }
                    }

                    writer.StartReport(file, baseReport, genReport, failedResultsFolder);
                    writer.WriteLine(PathCombine(baselineResultInfo.FullName, file));
                    writer.WriteLine(PathCombine(generatedResultInfo.FullName, file));

                    VerifyReports(writer, baseReport, genReport);
                }
                catch (Exception ex)
                {
                    writer.StartReport(file, baseReport, genReport, failedResultsFolder);
                    writer.WriteError(ex.Message);
                }
                finally
                {
                    writer.EndReport(file);
                }
            }
        }