Пример #1
0
        public static int Main(string[] args)
        {
            //args = new string[2] { "/trx:Threewaycall.trx,Twowaycallonauto.aa.trx", "/output:res.trx" };


            if (args.Length == 0 ||
                args.Contains("/h") ||
                args.Contains("/help"))
            {
                DispalyHelp();
                return(1);
            }

            if (args.Where(a => a.StartsWith("/trx")).FirstOrDefault() == null)
            {
                Console.WriteLine("/trx parameter is required");
                return(1);
            }

            string trxArg   = args.Where(a => a.StartsWith("/trx")).FirstOrDefault();
            var    trxFiles = ResolveTrxFilePaths(trxArg, args.Contains("/r"));

            if (trxFiles.Count == 0)
            {
                Console.WriteLine("No trx files found!");
                return(1);
            }

            if (trxFiles.Count == 1)
            {
                if (trxFiles[0].StartsWith("Error: "))
                {
                    Console.WriteLine(trxFiles[0]);
                    return(1);
                }

                if (args.Where(a => a.StartsWith("/report")).FirstOrDefault() == null)
                {
                    Console.WriteLine("Error: Only one trx file has been passed and there is no /report parameter. When having only one trx in /trx argument, /report parameter is required.");
                    return(1);
                }

                if (args.Where(a => a.StartsWith("/output")).FirstOrDefault() != null)
                {
                    Console.WriteLine("Error: /output parameter is not allowed when having only one trx in /trx argument!.");
                    return(1);
                }

                string reportOutput = ResolveReportLocation(args.Where(a => a.StartsWith("/report")).FirstOrDefault());
                if (reportOutput.StartsWith("Error: "))
                {
                    Console.WriteLine(trxFiles[0]);
                    return(1);
                }

                string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());
                try
                {
                    TrxReportGenerator.GenerateReport(trxFiles[0], reportOutput, screenshotLocation);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("Error: " + ex.Message);
                    return(1);
                }
            }
            else
            {
                if (args.Where(a => a.StartsWith("/output")).FirstOrDefault() == null)
                {
                    Console.WriteLine("/output parameter is required, when there are multiple trx files in /trx argument");
                    return(1);
                }

                string outputParam = ResolveOutputFileName(args.Where(a => a.StartsWith("/output")).FirstOrDefault());
                if (outputParam.StartsWith("Error: "))
                {
                    Console.WriteLine(outputParam);
                    return(1);
                }

                if (trxFiles.Contains(outputParam))
                {
                    trxFiles.Remove(outputParam);
                }

                try
                {
                    var combinedTestRun = TestRunMerger.MergeTRXsAndSave(trxFiles, outputParam);
                    if (args.Where(a => a.StartsWith("/report")) == null)
                    {
                        Console.WriteLine("Report path not specified :(");
                        return(0);
                    }
                    string reportOutput = ResolveReportLocation(args.Where(a => a.StartsWith("/report")).FirstOrDefault());
                    if (reportOutput == null)
                    {
                        return(0);
                    }

                    if (reportOutput.StartsWith("Error: "))
                    {
                        Console.WriteLine(trxFiles[0]);
                        return(1);
                    }

                    string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());

                    TrxReportGenerator.GenerateReport(combinedTestRun, reportOutput, screenshotLocation);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("Error: " + ex.Message);
                    return(1);
                }
            }

            return(0);
        }
Пример #2
0
        public static int Main(string[] args)
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                Console.WriteLine("Switching to secound AppDomain, for RazorEngine...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                var exitCode = domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location, null, args);
                // RazorEngine will cleanup.
                AppDomain.Unload(domain);
                return(exitCode);
            }



            if (args.Length == 0 ||
                args.Contains("/h") ||
                args.Contains("/help"))
            {
                DispalyHelp();
                return(1);
            }

            if (args.Where(a => a.StartsWith("/trx")).FirstOrDefault() == null)
            {
                Console.WriteLine("/trx parameter is required");
                return(1);
            }

            string trxArg   = args.Where(a => a.StartsWith("/trx")).FirstOrDefault();
            var    trxFiles = ResolveTrxFilePaths(trxArg, args.Contains("/r"));

            if (trxFiles.Count == 0)
            {
                Console.WriteLine("No trx files found!");
                return(1);
            }

            if (trxFiles.Count == 1)
            {
                if (trxFiles[0].StartsWith("Error: "))
                {
                    Console.WriteLine(trxFiles[0]);
                    return(1);
                }

                if (args.Where(a => a.StartsWith("/report")).FirstOrDefault() == null)
                {
                    Console.WriteLine("Error: Only one trx file has been passed and there is no /report parameter. When having only one trx in /trx argument, /report parameter is required.");
                    return(1);
                }

                if (args.Where(a => a.StartsWith("/output")).FirstOrDefault() != null)
                {
                    Console.WriteLine("Error: /output parameter is not allowed when having only one trx in /trx argument!.");
                    return(1);
                }

                string reportOutput = ResolveReportLocation(args.Where(a => a.StartsWith("/report")).FirstOrDefault());
                if (reportOutput.StartsWith("Error: "))
                {
                    Console.WriteLine(trxFiles[0]);
                    return(1);
                }

                string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());
                string reportTitle        = ResolveReportTitle(args.Where(a => a.StartsWith("/reportTitle")).FirstOrDefault());
                try
                {
                    TrxReportGenerator.GenerateReport(trxFiles[0], reportOutput, screenshotLocation, reportTitle);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("Error: " + ex.Message);
                    return(1);
                }
            }
            else
            {
                if (args.Where(a => a.StartsWith("/output")).FirstOrDefault() == null)
                {
                    Console.WriteLine("/output parameter is required, when there are multiple trx files in /trx argument");
                    return(1);
                }

                string outputParam = ResolveOutputFileName(args.Where(a => a.StartsWith("/output")).FirstOrDefault());
                if (outputParam.StartsWith("Error: "))
                {
                    Console.WriteLine(outputParam);
                    return(1);
                }

                if (trxFiles.Contains(outputParam))
                {
                    trxFiles.Remove(outputParam);
                }

                try
                {
                    var combinedTestRun = TestRunMerger.MergeTRXsAndSave(trxFiles, outputParam);

                    string reportOutput = ResolveReportLocation(args.Where(a => a.StartsWith("/report")).FirstOrDefault());
                    if (reportOutput == null)
                    {
                        return(0);
                    }

                    if (reportOutput.StartsWith("Error: "))
                    {
                        Console.WriteLine(trxFiles[0]);
                        return(1);
                    }

                    string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());
                    string reportTitle        = ResolveReportTitle(args.Where(a => a.StartsWith("/reportTitle", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault());

                    TrxReportGenerator.GenerateReport(combinedTestRun, reportOutput, screenshotLocation, reportTitle);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("Error: " + ex.Message);
                    return(1);
                }
            }

            return(0);
        }