Exemplo n.º 1
0
        public int Execute(ConsoleOptions options)
        {
            XmlTextReader transformReader = GetTransformReader(options);

            if (transformReader == null)
            {
                return(3);
            }

            ConsoleWriter outStream = options.isOut
                                ? new ConsoleWriter(new StreamWriter(options.output))
                                : new ConsoleWriter(Console.Out);

            ConsoleWriter errorStream = options.isErr
                                ? new ConsoleWriter(new StreamWriter(options.err))
                                : new ConsoleWriter(Console.Error);

            TestDomain testDomain = new TestDomain(outStream, errorStream);

            if (options.noshadow)
            {
                testDomain.ShadowCopyFiles = false;
            }

            Test test = MakeTestFromCommandLine(testDomain, options);

            if (test == null)
            {
                Console.Error.WriteLine("Unable to locate fixture {0}", options.fixture);
                return(2);
            }

            Directory.SetCurrentDirectory(new FileInfo((string)options.Parameters[0]).DirectoryName);

            EventListener collector = new EventCollector(options, outStream);

            string savedDirectory = Environment.CurrentDirectory;

            if (options.HasInclude)
            {
                Console.WriteLine("Included categories: " + options.include);
                testDomain.SetFilter(new CategoryFilter(options.IncludedCategories));
            }
            else if (options.HasExclude)
            {
                Console.WriteLine("Excluded categories: " + options.exclude);
                testDomain.SetFilter(new CategoryFilter(options.ExcludedCategories, true));
            }

            TestResult result = null;

            if (options.thread)
            {
                testDomain.RunTest(collector);
                testDomain.Wait();
                result = testDomain.Result;
            }
            else
            {
                result = testDomain.Run(collector);
            }

            Directory.SetCurrentDirectory(savedDirectory);

            Console.WriteLine();

            string xmlOutput = CreateXmlOutput(result);

            if (options.xmlConsole)
            {
                Console.WriteLine(xmlOutput);
            }
            else
            {
                CreateSummaryDocument(xmlOutput, transformReader);
            }

            // Write xml output here
            string xmlResultFile = options.IsXml ? options.xml : "TestResult.xml";

            using (StreamWriter writer = new StreamWriter(xmlResultFile))
            {
                writer.Write(xmlOutput);
            }

            if (testDomain != null)
            {
                testDomain.Unload();
            }

            return(result.IsFailure ? 1 : 0);
        }