Esempio n. 1
0
 static void ProcessInputZipFile(string filename, ITestResultProcessor processor)
 {
     Console.WriteLine("Processing: " + filename);
     using (ZipArchive zip = ZipFile.Open(filename, ZipArchiveMode.Read))
     {
         foreach (ZipArchiveEntry entry in zip.Entries)
         {
             // Must not be folder (empty name) and must have .xml extension
             if (!string.IsNullOrEmpty(entry.Name) && Path.GetExtension(entry.Name).Equals(".xml", StringComparison.OrdinalIgnoreCase))
             {
                 Console.WriteLine("   Processing: " + entry.FullName);
                 using (Stream stream = entry.Open())
                 {
                     try
                     {
                         processor.ProcessResult(stream);
                     }
                     catch (Exception err)
                     {
                         Console.Error.WriteLine("Error processing input file '{0}/{1}\r\n{2}\r\n", filename, entry.FullName, err.Message);
                         ++s_ErrorCount;
                     }
                 }
             }
         }
     }
     Console.WriteLine();
 }
Esempio n. 2
0
        static void ProcessInputFilename(string filenamePattern, ITestResultProcessor processor)
        {
            int    count     = 0;
            string directory = Path.GetDirectoryName(filenamePattern);

            if (string.IsNullOrEmpty(directory))
            {
                directory = Environment.CurrentDirectory;
            }
            string pattern = Path.GetFileName(filenamePattern);

            foreach (string filename in Directory.GetFiles(directory, pattern))
            {
                switch (Path.GetExtension(filename).ToLower())
                {
                case ".xml":
                    ProcessInputTrtFile(filename, processor);
                    break;

                case ".zip":
                    ProcessInputZipFile(filename, processor);
                    break;

                default:
                    throw new ArgumentException(string.Format("Input file '{0}' is of unsupported time. Only .xml and .zip are supported.", filename));
                }
                ++count;
            }
            if (count == 0)
            {
                throw new ArgumentException(string.Format("Input file '{0}' not found!", filenamePattern));
            }
        }
 public ConventionContext(string dataDescription, IList <IReportDataFormatter> formatters,
                          IEnumerable <IResultsProcessor> processors, ITestResultProcessor testResultProcessor)
 {
     this.formatters          = formatters;
     this.processors          = processors;
     this.testResultProcessor = testResultProcessor;
     this.dataDescription     = dataDescription;
 }
        public static void Is <TDataSource>(IConvention <TDataSource> convention, TDataSource data,
                                            ITestResultProcessor resultProcessor = null)
            where TDataSource : IConventionData
        {
            if (defaultProcessors == null)
            {
                Init(Assembly.GetCallingAssembly());
            }

            Execute(convention, data, defaultProcessors.Concat(new[] { new ThrowOnFailureResultsProcessor() }), resultProcessor ?? new ConventionReportTextRenderer());
        }
Esempio n. 5
0
        public static void Is <TDataSource>(IConvention <TDataSource> convention, TDataSource data,
                                            ITestResultProcessor resultProcessor = null)
            where TDataSource : IConventionData
        {
            if (defaultProcessors == null)
            {
                var reporters = GetCustomReporters <TDataSource>();
                Init(reporters.ToList());
            }

            Execute(convention, data, defaultProcessors.Concat(new[] { new ThrowOnFailureResultsProcessor() }), resultProcessor ?? new ConventionReportTextRenderer());
        }
        /// <summary>
        /// Verifies a convention, returning the failures as a string instead of throwing an exception
        ///
        /// Allows you to approve or assert against the failures yourself
        /// </summary>
        /// <example>Convention.GetFailures(new SomeConvention(), Types.InAssemblyOf&lt;SomeTypeOfMine&gt;())</example>
        public static string GetFailures <TDataSource>(IConvention <TDataSource> convention, TDataSource data,
                                                       ITestResultProcessor resultProcessor = null)
            where TDataSource : IConventionData
        {
            if (defaultProcessors == null)
            {
                Init(Assembly.GetCallingAssembly());
            }
            var captureFailuresProcessor = new CaptureFailuresProcessor();

            Execute(convention, data, defaultProcessors.Concat(new [] { captureFailuresProcessor }), resultProcessor ?? new ConventionReportTextRenderer());
            return(captureFailuresProcessor.Failures);
        }
Esempio n. 7
0
 static void ProcessInputTrtFile(string filename, ITestResultProcessor processor)
 {
     Console.WriteLine("Processing: " + filename);
     using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         try
         {
             processor.ProcessResult(stream);
         }
         catch (Exception err)
         {
             Console.Error.WriteLine("Error processing input file '{0}\r\n{1}\r\n", filename, err.Message);
             ++s_ErrorCount;
         }
     }
     Console.WriteLine();
 }
 static void ProcessInputZipFile(string filename, ITestResultProcessor processor)
 {
     Console.WriteLine("Processing: " + filename);
     using (ZipArchive zip = ZipFile.Open(filename, ZipArchiveMode.Read))
     {
         foreach(ZipArchiveEntry entry in zip.Entries)
         {
             // Must not be folder (empty name) and must have .xml extension
             if (!string.IsNullOrEmpty(entry.Name) && Path.GetExtension(entry.Name).Equals(".xml", StringComparison.OrdinalIgnoreCase))
             {
                 Console.WriteLine("   Processing: " + entry.FullName);
                 using (Stream stream = entry.Open())
                 {
                     try
                     {
                         processor.ProcessResult(stream);
                     }
                     catch (Exception err)
                     {
                         Console.Error.WriteLine("Error processing input file '{0}/{1}\r\n{2}\r\n", filename, entry.FullName, err.Message);
                         ++s_ErrorCount;
                     }
                 }
             }
         }
     }
     Console.WriteLine();
 }
        static void ProcessInputTrtFile(string filename, ITestResultProcessor processor)
        {
            Console.WriteLine("Processing: " + filename);
            using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    processor.ProcessResult(stream);
                }
                catch (Exception err)
                {
                    Console.Error.WriteLine("Error processing input file '{0}\r\n{1}\r\n", filename, err.Message);
                    ++s_ErrorCount;
                }

            }
            Console.WriteLine();
        }
        static void ProcessInputFilename(string filenamePattern, ITestResultProcessor processor)
        {
            int count = 0;
            string directory = Path.GetDirectoryName(filenamePattern);
            if (string.IsNullOrEmpty(directory)) directory = Environment.CurrentDirectory;
            string pattern = Path.GetFileName(filenamePattern);
            foreach (string filename in Directory.GetFiles(directory, pattern))
            {
                switch (Path.GetExtension(filename).ToLower())
                {
                    case ".xml":
                        ProcessInputTrtFile(filename, processor);
                        break;

                    case ".zip":
                        ProcessInputZipFile(filename, processor);
                        break;

                    default:
                        throw new ArgumentException(string.Format("Input file '{0}' is of unsupported time. Only .xml and .zip are supported.", filename));
                }
                ++count;
            }
            if (count == 0) throw new ArgumentException(string.Format("Input file '{0}' not found!", filenamePattern));
        }
 static void ProcessInputXmlFile(string filename, ITestResultProcessor processor)
 {
     Console.WriteLine("Processing: " + filename);
     using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         processor.ProcessResult(stream);
     }
     Console.WriteLine();
 }
Esempio n. 12
0
        static void Execute <TDataSource>(IConvention <TDataSource> convention, TDataSource data,
                                          IEnumerable <IResultsProcessor> processors, ITestResultProcessor resultProcessor)
            where TDataSource : IConventionData
        {
            var dataDescription = $"{data.GetType().GetSentenceCaseName()} in {data.Description}";
            var context         = new ConventionContext(dataDescription, Formatters, processors, resultProcessor);

            context.Execute(convention, data);
        }