Exemplo n.º 1
0
        static int Main(string[] args)
        {
            string testCaseFile = string.Empty;
            string packageFile  = string.Empty;
            string outputFile   = string.Empty;
            string report       = string.Empty;
            var    parameters   = new Dictionary <string, string>();

            if (args.Length == 0 || args[0].Contains("?"))
            {
                Console.WriteLine("Usage: ssisUnitTestRunner /TESTCASE test-case-file [/OUTPUT output-file] [/REPORT <ALL:PASSED:FAILED>]");
                Console.WriteLine("/TESTCASE\tFilename for test case");
                Console.WriteLine("[/OUTPUT]\tFilename for results");
                Console.WriteLine("[/REPORT]\tALL - Reports all results (inlcuding setup and teardown)");
                Console.WriteLine("         \tPASSED - Reports only results for successful tests");
                Console.WriteLine("         \tFAILED - Reports only results for failed tests");
                Console.WriteLine("[/PARAM] \tName|Value for a parameter value specified in the test");
                return(0);
            }

            for (int i = 0; i < args.Length - 1; i++)
            {
                if (args[i].ToUpper() == ARG_TEST_CASE)
                {
                    testCaseFile = args[i + 1];
                }

                if (args[i].ToUpper() == ARG_OUTPUT_FILE)
                {
                    outputFile = args[i + 1];
                }

                if (args[i].ToUpper() == ARG_REPORT_LEVEL)
                {
                    report = args[i + 1];
                }

                if (args[i].ToUpper() == ARG_PARAM)
                {
                    var paramValue = args[i + 1].Split('|');

                    if (paramValue.Length == 2)
                    {
                        parameters.Add(paramValue[0], paramValue[1]);
                    }
                    else
                    {
                        Console.WriteLine("Parameter value {0} was ignored, as it wasn't in a valid format.", args[i + 1]);
                    }
                }
            }

            var run = new TestRun();

            try
            {
                return(run.RunTest(testCaseFile, outputFile, report, parameters));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occurred: " + ex.Message);
                return(2);
            }
        }