Exemplo n.º 1
0
        /// <summary>
        /// Handler for external UI messages.
        /// </summary>
        /// <param name="messageType">The type of message.</param>
        /// <param name="messageRecord">The message details.</param>
        /// <param name="buttons">Buttons to show (unused).</param>
        /// <param name="icon">The icon to show (unused).</param>
        /// <param name="defaultButton">The default button (unused).</param>
        /// <returns>How the message was handled.</returns>
        public MessageResult UIRecordHandler(
            InstallMessage messageType,
            Record messageRecord,
            MessageButtons buttons,
            MessageIcon icon,
            MessageDefaultButton defaultButton)
        {
#if False
            Console.WriteLine("Message type {0}: {1}", messageType.ToString(), this.session.FormatRecord(messageRecord));
#endif

            if (!this.session.IsClosed && 1 <= messageRecord.FieldCount)
            {
                switch (messageType)
                {
                case InstallMessage.ActionStart:
                    // only try to interpret the messages if they're coming from WixRunImmediateUnitTests
                    string action = messageRecord.GetString(1);
                    this.runningTests = Constants.LuxCustomActionName == action;
                    return(MessageResult.OK);

                case InstallMessage.User:
                    if (this.runningTests)
                    {
                        string message = messageRecord.ToString();
                        int    id      = messageRecord.GetInteger(1);

                        if (Constants.TestIdMinimumSuccess <= id && Constants.TestIdMaximumSuccess >= id)
                        {
                            this.OnMessage(NitVerboses.TestPassed(message));
                            ++this.passes;
                        }
                        else if (Constants.TestIdMinimumFailure <= id && Constants.TestIdMaximumFailure >= id)
                        {
                            this.OnMessage(NitErrors.TestFailed(message));
                            ++this.failures;
                        }
                    }

                    return(MessageResult.OK);

                case InstallMessage.Error:
                case InstallMessage.FatalExit:
                    this.OnMessage(NitErrors.PackageFailed(this.session.FormatRecord(messageRecord)));
                    return(MessageResult.Error);
                }
            }

            return(MessageResult.OK);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up an external UI handler and runs the package.
        /// </summary>
        /// <param name="passes">Number of passing tests.</param>
        /// <param name="failures">Number of failing tests.</param>
        public void RunTests(out int passes, out int failures)
        {
            InstallUIOptions        previousUILevel   = Installer.SetInternalUI(InstallUIOptions.Silent);
            ExternalUIRecordHandler previousUIHandler = Installer.SetExternalUI(this.UIRecordHandler, InstallLogModes.FatalExit | InstallLogModes.Error | /*InstallLogModes.Info | */ InstallLogModes.User | InstallLogModes.ActionStart);

            try
            {
                foreach (string package in this.InputFiles)
                {
                    using (this.session = Installer.OpenPackage(package, false))
                    {
                        IList <string> mutations = this.session.Database.ExecuteStringQuery("SELECT DISTINCT `Mutation` FROM `WixUnitTest`");
                        foreach (string mutation in mutations)
                        {
                            if (!String.IsNullOrEmpty(mutation))
                            {
                                this.OnMessage(NitVerboses.RunningMutation(mutation));
                                this.session[Constants.LuxMutationRunningProperty] = mutation;
                            }

                            try
                            {
                                this.session.DoAction("INSTALL");
                            }
                            catch (InstallCanceledException)
                            {
                                ; // expected
                            }
                            catch (InstallerException ex)
                            {
                                this.OnMessage(NitErrors.PackageFailed(ex.Message));
                                ++this.failures;
                            }
                        }
                    }
                }
            }
            finally
            {
                Installer.SetExternalUI(previousUIHandler, InstallLogModes.None);
                Installer.SetInternalUI(previousUILevel);
            }

            passes   = this.passes;
            failures = this.failures;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            try
            {
                // parse the command line
                this.ParseCommandLine(args);
                this.messageHandler.ShowVerboseMessages = true; // always verbose, to show passed tests

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.EncounteredError)
                {
                    return(this.messageHandler.LastErrorNumber);
                }

                if (this.showLogo)
                {
                    AppCommon.DisplayToolHeader();
                }

                if (this.showHelp)
                {
                    Console.WriteLine(NitStrings.HelpMessage);
                    AppCommon.DisplayToolFooter();
                    return(this.messageHandler.LastErrorNumber);
                }

                foreach (string parameter in this.invalidArgs)
                {
                    this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter));
                }

                this.invalidArgs = null;

                // gotta have something to do
                if (0 == this.inputFiles.Count)
                {
                    Console.WriteLine(NitStrings.HelpMessage);
                    this.messageHandler.Display(this, NitErrors.MalfunctionNeedInput());
                    return(this.messageHandler.LastErrorNumber);
                }

                // run tests and report results
                TestRunner runner = new TestRunner();
                runner.InputFiles = this.inputFiles;
                runner.Message   += this.messageHandler.Display;

                int failures = 0;
                int passes   = 0;
                runner.RunTests(out passes, out failures);

                if (0 < failures)
                {
                    this.messageHandler.Display(this, NitErrors.TotalTestFailures(failures, passes));
                    return(this.messageHandler.LastErrorNumber);
                }
                else
                {
                    this.messageHandler.Display(this, NitVerboses.OneHundredPercent(passes));
                }
            }
            catch (WixException we)
            {
                this.messageHandler.Display(this, we.Error);
            }
            catch (Exception e)
            {
                this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }

            return(this.messageHandler.LastErrorNumber);
        }