public void SetUp()
 {
     assemblyOptions = new CommandOptionsArxNet(new string[]
         { firstAssembly, secondAssembly });
     fixtureOptions = new CommandOptionsArxNet(new string[]
         { "-fixture:"+fixture, firstAssembly, secondAssembly });
 }
        public EventCollectorArxNet( CommandOptionsArxNet options, TextWriter outWriter, TextWriter errorWriter)
            : base(options, outWriter, errorWriter)
        {
            level = 0;
            this.options = options;
            this.outWriter = outWriter;
            this.errorWriter = errorWriter;
            this.currentTestName = string.Empty;
            this.progress = !options.xmlConsole && !options.labels && !options.nodots;

            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(OnUnhandledException);
        }
        public void BooleanOptionAreRecognized( string fieldName, string option )
        {
            FieldInfo field = typeof(CommandOptionsArxNet).GetField( fieldName );
            Assert.IsNotNull( field, "Field '{0}' not found", fieldName );
            Assert.AreEqual( typeof(bool), field.FieldType, "Field '{0}' is wrong type", fieldName );

            CommandOptionsArxNet options = new CommandOptionsArxNet( "-" + option );
            Assert.AreEqual( true, (bool)field.GetValue( options ), "Didn't recognize -" + option );
            options = new CommandOptionsArxNet( "--" + option );
            Assert.AreEqual( true, (bool)field.GetValue( options ), "Didn't recognize --" + option );
            options = new CommandOptionsArxNet( false, "/" + option );
            Assert.AreEqual( false, (bool)field.GetValue( options ), "Incorrectly recognized /" + option );
            options = new CommandOptionsArxNet( true, "/" + option );
            Assert.AreEqual( true, (bool)field.GetValue( options ), "Didn't recognize /" + option );
        }
        public void DomainOptionIsNone(string optionValue)
        {
            FieldInfo field = typeof(CommandOptionsArxNet).GetField("domain");

            CommandOptionsArxNet options = new CommandOptionsArxNet("-domain=" + optionValue);
            Assert.AreEqual(DomainUsage.None, (DomainUsage)field.GetValue(options), "Field 'domain' is not 'None'");
            options = new CommandOptionsArxNet("--domain=" + optionValue);
            Assert.AreEqual(DomainUsage.None, (DomainUsage)field.GetValue(options), "Field 'domain' is not 'None'");
            options = new CommandOptionsArxNet(false, "/domain=" + optionValue);
            Assert.AreEqual(DomainUsage.None, (DomainUsage)field.GetValue(options), "Field 'domain' is not 'None'");
            options = new CommandOptionsArxNet(true, "/domain=" + optionValue);
            Assert.AreEqual(DomainUsage.None, (DomainUsage)field.GetValue(options), "Field 'domain' is not 'None'");
            options = new CommandOptionsArxNet();
            Assert.AreEqual(DomainUsage.None, (DomainUsage)field.GetValue(options), "Field 'domain' is not 'None'");
        }
 public void AssemblyName()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "nunit.tests.dll" );
     Assert.AreEqual( "nunit.tests.dll", options.Parameters[0] );
 }
 public void AssemblyAloneIsValid()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "nunit.tests.dll" );
     Assert.IsTrue(options.Validate(), "command line should be valid");
 }
        public void ProcessOptionIsSingle(string optionValue)
        {
            FieldInfo field = typeof(CommandOptionsArxNet).GetField("process");

            CommandOptionsArxNet options = new CommandOptionsArxNet("-process=" + optionValue);
            Assert.AreEqual(ProcessModel.Single, (ProcessModel)field.GetValue(options), "Field 'process' is not 'None'");
            options = new CommandOptionsArxNet("--process=" + optionValue);
            Assert.AreEqual(ProcessModel.Single, (ProcessModel)field.GetValue(options), "Field 'process' is not 'None'");
            options = new CommandOptionsArxNet(false, "/process=" + optionValue);
            Assert.AreEqual(ProcessModel.Single, (ProcessModel)field.GetValue(options), "Field 'domain' is not 'None'");
            options = new CommandOptionsArxNet(true, "/process=" + optionValue);
            Assert.AreEqual(ProcessModel.Single, (ProcessModel)field.GetValue(options), "Field 'process' is not 'None'");
            options = new CommandOptionsArxNet();
            Assert.AreEqual(ProcessModel.Single, (ProcessModel)field.GetValue(options), "Field 'process' is not 'None'");
        }
        public void HelpTextUsesCorrectDelimiterForPlatform()
        {
            string helpText = new CommandOptionsArxNet().GetHelpText();
            char delim = System.IO.Path.DirectorySeparatorChar == '/' ? '-' : '/';

            string expected = string.Format( "{0}output=", delim );
            StringAssert.Contains( expected, helpText );

            expected = string.Format( "{0}out=", delim );
            StringAssert.Contains( expected, helpText );
        }
        public static new int Main(string[] args)
        {
            CommandOptionsArxNet options = new CommandOptionsArxNet(args);

            // Create SettingsService early so we know the trace level right at the start
            SettingsService settingsService = new SettingsService();
            InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default);
            if (options.trace != InternalTraceLevel.Default)
                level = options.trace;

            InternalTrace.Initialize("nunit-command-arxnet_%p.log", level);

            log.Info("NUnit-command-arxnet.dll starting");

            if (!options.nologo)
                WriteCopyright();

            if (options.help)
            {
                options.Help();
                return CommandUiArxNet.OK;
            }

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            if (options.cleanup)
            {
                log.Info("Performing cleanup of shadow copy cache");
                DomainManager.DeleteShadowCopyPath();
                ed.WriteMessage("\nShadow copy cache emptied");
                return CommandUiArxNet.OK;
            }

            if (options.NoArgs)
            {
                ed.WriteMessage("\nfatal error: no inputs specified");
                options.Help();
                return CommandUiArxNet.OK;
            }

            if (!options.Validate())
            {
                foreach (string arg in options.InvalidArguments)
                    ed.WriteMessage("\nfatal error: invalid argument: {0}", arg);
                options.Help();
                return CommandUiArxNet.INVALID_ARG;
            }

            // Add Standard Services to ServiceManager
            ServiceManager.Services.AddService(new SettingsService());
            ServiceManager.Services.AddService(new DomainManager());
            //ServiceManager.Services.AddService( new RecentFilesService() );
            ServiceManager.Services.AddService(new ProjectService());
            //ServiceManager.Services.AddService( new TestLoader() );
            ServiceManager.Services.AddService(new AddinRegistry());
            ServiceManager.Services.AddService(new AddinManager());
            // Hack: Resolves conflict with gui testagency when running
            // console tests under the gui.
            if (!AppDomain.CurrentDomain.FriendlyName.StartsWith("test-domain-"))
                ServiceManager.Services.AddService(new TestAgency());

            // Initialize Services
            ServiceManager.Services.InitializeServices();

            foreach (string parm in options.Parameters)
            {
                if (!Services.ProjectService.CanLoadProject(parm) && !PathUtils.IsAssemblyFileType(parm))
                {
                    ed.WriteMessage("\nFile type not known: {0}", parm);
                    return CommandUiArxNet.INVALID_ARG;
                }
            }

            try
            {
                CommandUiArxNet commandUiArxNet = new CommandUiArxNet();
                return commandUiArxNet.Execute(options);
            }
            catch (FileNotFoundException ex)
            {
                ed.WriteMessage("\n" + ex.Message);
                return CommandUiArxNet.FILE_NOT_FOUND;
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\nAutoCAD Exception:\n{0}", ex.ToString());
                return CommandUiArxNet.UNEXPECTED_ERROR;
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("\nUnhandled Exception:\n{0}", ex.ToString());
                return CommandUiArxNet.UNEXPECTED_ERROR;
            }
            finally
            {
                if (options.wait)
                {
                    ed.GetString(new PromptStringOptions("\n\nHit <enter> key to continue"));
                }

                log.Info("NUnit-command-arxnet.dll terminating");
            }
        }
 public void XmlParameter()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "tests.dll", "-xml:results.xml" );
     Assert.IsTrue(options.ParameterCount == 1, "assembly should be set");
     Assert.AreEqual("tests.dll", options.Parameters[0]);
     Assert.AreEqual("results.xml", options.result);
 }
        public void StringOptionsAreRecognized( string fieldName, string option )
        {
            FieldInfo field = typeof(CommandOptionsArxNet).GetField( fieldName );
            Assert.IsNotNull( field, "Field {0} not found", fieldName );
            Assert.AreEqual( typeof(string), field.FieldType );

            CommandOptionsArxNet options = new CommandOptionsArxNet( "-" + option + ":text" );
            Assert.AreEqual( "text", (string)field.GetValue( options ), "Didn't recognize -" + option );
            options = new CommandOptionsArxNet( "--" + option + ":text" );
            Assert.AreEqual( "text", (string)field.GetValue( options ), "Didn't recognize --" + option );
            options = new CommandOptionsArxNet( false, "/" + option + ":text" );
            Assert.AreEqual( null, (string)field.GetValue( options ), "Incorrectly recognized /" + option );
            options = new CommandOptionsArxNet( true, "/" + option + ":text" );
            Assert.AreEqual( "text", (string)field.GetValue( options ), "Didn't recognize /" + option );
        }
        public void NothreadOptionIsTrue()
        {
            FieldInfo field = typeof(CommandOptionsArxNet).GetField("nothread");
            Assert.IsNotNull(field, "Field 'nothread' not found");
            Assert.AreEqual(typeof(bool), field.FieldType, "Field 'nothread' is wrong type");

            CommandOptionsArxNet options = new CommandOptionsArxNet("-nothread");
            Assert.AreEqual(true, (bool)field.GetValue(options), "Field 'nothread' is not true");
            options = new CommandOptionsArxNet("--nothread");
            Assert.AreEqual(true, (bool)field.GetValue(options), "Field 'nothread' is not true");
            options = new CommandOptionsArxNet(false, "/nothread");
            Assert.AreEqual(true, (bool)field.GetValue(options), "Field 'nothread' is not true");
            options = new CommandOptionsArxNet(true, "/nothread");
            Assert.AreEqual(true, (bool)field.GetValue(options), "Field 'nothread' is not true");
            options = new CommandOptionsArxNet();
            Assert.AreEqual(true, (bool)field.GetValue(options), "Field 'nothread' is not true");
        }
 public void NoParametersCount()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet();
     Assert.IsTrue(options.NoArgs);
 }
 public void NoFixtureNameProvided()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "-fixture:", "nunit.tests.dll" );
     Assert.IsFalse(options.Validate());
 }
 public void InvalidOption()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "-asembly:nunit.tests.dll" );
     Assert.IsFalse(options.Validate());
 }
 public void InvalidCommandLineParms()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "-garbage:TestFixture", "-assembly:Tests.dll" );
     Assert.IsFalse(options.Validate());
 }
 public void FileNameWithoutXmlParameterLooksLikeParameter()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "tests.dll", "result.xml" );
     Assert.IsTrue(options.Validate());
     Assert.AreEqual(2, options.Parameters.Count);
 }
 public void XmlParameterWithFullPathUsingEqualSign()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "tests.dll", "-xml=C:/nunit/tests/bin/Debug/console-test.xml" );
     Assert.IsTrue(options.ParameterCount == 1, "assembly should be set");
     Assert.AreEqual("tests.dll", options.Parameters[0]);
     Assert.AreEqual("C:/nunit/tests/bin/Debug/console-test.xml", options.result);
 }
 public void XmlParameterWithoutFileNameIsInvalid()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "tests.dll", "-xml:" );
     Assert.IsFalse(options.Validate());
 }
 public void AllowForwardSlashDefaultsCorrectly()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet();
     Assert.AreEqual( Path.DirectorySeparatorChar != '/', options.AllowForwardSlash );
 }
        public int Execute(CommandOptionsArxNet options)
        {
            this.workDir = options.work;
            if (workDir == null || workDir == string.Empty)
                workDir = Environment.CurrentDirectory;
            else
            {
                workDir = Path.GetFullPath(workDir);
                if (!Directory.Exists(workDir))
                    Directory.CreateDirectory(workDir);
            }

            TextWriter outWriter = new StringWriter();
            bool redirectOutput = options.output != null && options.output != string.Empty;
            if (redirectOutput)
            {
                StreamWriter outStreamWriter = new StreamWriter(Path.Combine(workDir, options.output));
                outStreamWriter.AutoFlush = true;
                outWriter = outStreamWriter;
            }

            TextWriter errorWriter = new StringWriter();
            bool redirectError = options.err != null && options.err != string.Empty;
            if (redirectError)
            {
                StreamWriter errorStreamWriter = new StreamWriter(Path.Combine(workDir, options.err));
                errorStreamWriter.AutoFlush = true;
                errorWriter = errorStreamWriter;
            }

            TestPackage package = MakeTestPackage(options);

            ProcessModel processModel = package.Settings.Contains("ProcessModel")
                ? (ProcessModel)package.Settings["ProcessModel"]
                : ProcessModel.Default;

            DomainUsage domainUsage = package.Settings.Contains("DomainUsage")
                ? (DomainUsage)package.Settings["DomainUsage"]
                : DomainUsage.Default;

            RuntimeFramework framework = package.Settings.Contains("RuntimeFramework")
                ? (RuntimeFramework)package.Settings["RuntimeFramework"]
                : RuntimeFramework.CurrentFramework;

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            #if CLR_2_0 || CLR_4_0
            ed.WriteMessage("\nProcessModel: {0}    DomainUsage: {1}", processModel, domainUsage);

            ed.WriteMessage("\nExecution Runtime: {0}", framework);
            #else
            ed.WriteMessage("\nDomainUsage: {0}", domainUsage);

            if (processModel != ProcessModel.Default && processModel != ProcessModel.Single)
                ed.WriteMessage("\nWarning: Ignoring project setting 'processModel={0}'", processModel);

            if (!RuntimeFramework.CurrentFramework.Supports(framework))
                ed.WriteMessage("\nWarning: Ignoring project setting 'runtimeFramework={0}'", framework);
            #endif
            using (TestRunner testRunner = new DefaultTestRunnerFactory().MakeTestRunner(package))
            {
                testRunner.Load(package);

                if (testRunner.Test == null)
                {
                    testRunner.Unload();
                    ed.WriteMessage("\nUnable to locate fixture {0}", options.fixture);
                    return FIXTURE_NOT_FOUND;
                }

                EventCollectorArxNet collector = new EventCollectorArxNet(options, outWriter, errorWriter);

                TestFilter testFilter = TestFilter.Empty;
                SimpleNameFilter nameFilter = new SimpleNameFilter();

                if (options.run != null && options.run != string.Empty)
                {
                    ed.WriteMessage("\nSelected test(s): " + options.run);
                    foreach (string name in TestNameParser.Parse(options.run))
                        nameFilter.Add(name);
                    testFilter = nameFilter;
                }

                if (options.runlist != null && options.runlist != string.Empty)
                {
                    ed.WriteMessage("\nRun list: " + options.runlist);
                    using (StreamReader rdr = new StreamReader(options.runlist))
                    {
                        // NOTE: We can't use rdr.EndOfStream because it's
                        // not present in .NET 1.x.
                        string line = rdr.ReadLine();
                        while (line != null)
                        {
                            if (line[0] != '#')
                                nameFilter.Add(line);
                            line = rdr.ReadLine();
                        }
                    }
                    testFilter = nameFilter;
                }

                if (options.include != null && options.include != string.Empty)
                {
                    TestFilter includeFilter = new CategoryExpression(options.include).Filter;
                    ed.WriteMessage("\nIncluded categories: " + includeFilter.ToString());

                    if (testFilter.IsEmpty)
                        testFilter = includeFilter;
                    else
                        testFilter = new AndFilter(testFilter, includeFilter);
                }

                if (options.exclude != null && options.exclude != string.Empty)
                {
                    TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter);
                    ed.WriteMessage("\nExcluded categories: " + excludeFilter.ToString());

                    if (testFilter.IsEmpty)
                        testFilter = excludeFilter;
                    else if (testFilter is AndFilter)
                        ((AndFilter)testFilter).Add(excludeFilter);
                    else
                        testFilter = new AndFilter(testFilter, excludeFilter);
                }

                if (testFilter is NotFilter)
                    ((NotFilter)testFilter).TopLevel = true;

                TestResult result = null;
                string savedDirectory = Environment.CurrentDirectory;
                TextWriter savedOut = Console.Out;
                TextWriter savedError = Console.Error;

                try
                {
                    result = testRunner.Run(collector, testFilter);
                    if (!redirectOutput) ed.WriteMessage("\n" + outWriter.ToString());
                    if (!redirectError) ed.WriteMessage("\n" + errorWriter.ToString());
                }
                finally
                {
                    outWriter.Flush();
                    errorWriter.Flush();

                    if (redirectOutput)
                        outWriter.Close();
                    if (redirectError)
                        errorWriter.Close();

                    Environment.CurrentDirectory = savedDirectory;
                    Console.SetOut(savedOut);
                    Console.SetError(savedError);
                }

                ed.WriteMessage("\n");

                int returnCode = UNEXPECTED_ERROR;

                if (result != null)
                {
                    string xmlOutput = CreateXmlOutput(result);
                    ResultSummarizer summary = new ResultSummarizer(result);

                    if (options.xmlConsole)
                    {
                        ed.WriteMessage("\n" + xmlOutput);
                    }
                    else
                    {
                        WriteSummaryReport(summary);
                        if (summary.ErrorsAndFailures > 0 || result.IsError || result.IsFailure)
                            WriteErrorsAndFailuresReport(result);
                        if (summary.TestsNotRun > 0)
                            WriteNotRunReport(result);

                        if (!options.noresult)
                        {
                            // Write xml output here
                            string xmlResultFile = options.result == null || options.result == string.Empty
                                ? "TestResult.xml" : options.result;

                            using (StreamWriter writer = new StreamWriter(Path.Combine(workDir, xmlResultFile)))
                            {
                                writer.Write(xmlOutput);
                            }
                        }
                    }

                    returnCode = summary.ErrorsAndFailures;
                }

                if (collector.HasExceptions)
                {
                    collector.WriteExceptions();
                    returnCode = UNEXPECTED_ERROR;
                }

                return returnCode;
            }
        }
 public void FixtureNamePlusAssemblyIsValid()
 {
     CommandOptionsArxNet options = new CommandOptionsArxNet( "-fixture:NUnit.Tests.AllTests", "nunit.tests.dll" );
     Assert.AreEqual("nunit.tests.dll", options.Parameters[0]);
     Assert.AreEqual("NUnit.Tests.AllTests", options.fixture);
     Assert.IsTrue(options.Validate());
 }