Пример #1
0
            public Listener(TestRunnerEventDispatcher eventDispatcher, TappedLogger tappedLogger, LockBox <Report> reportBox)
            {
                this.eventDispatcher = eventDispatcher;
                this.tappedLogger    = tappedLogger;
                this.reportBox       = reportBox;

                states = new Dictionary <string, TestStepState>();

                rootTestStepIds       = new List <string>();
                rootTestStepStopwatch = Stopwatch.StartNew();
                rootTestStepResult    = new TestResult()
                {
                    Outcome = TestOutcome.Passed
                };

                consumer = new MessageConsumer()
                           .Handle <TestDiscoveredMessage>(HandleTestDiscoveredMessage)
                           .Handle <AnnotationDiscoveredMessage>(HandleAnnotationDiscoveredMessage)
                           .Handle <TestStepStartedMessage>(HandleTestStepStartedMessage)
                           .Handle <TestStepLifecyclePhaseChangedMessage>(HandleTestStepLifecyclePhaseChangedMessage)
                           .Handle <TestStepMetadataAddedMessage>(HandleTestStepMetadataAddedMessage)
                           .Handle <TestStepFinishedMessage>(HandleTestStepFinishedMessage)
                           .Handle <TestStepLogAttachMessage>(HandleTestStepLogAttachMessage)
                           .Handle <TestStepLogStreamWriteMessage>(HandleTestStepLogStreamWriteMessage)
                           .Handle <TestStepLogStreamEmbedMessage>(HandleTestStepLogStreamEmbedMessage)
                           .Handle <TestStepLogStreamBeginSectionBlockMessage>(HandleTestStepLogStreamBeginSectionBlockMessage)
                           .Handle <TestStepLogStreamBeginMarkerBlockMessage>(HandleTestStepLogStreamBeginMarkerBlockMessage)
                           .Handle <TestStepLogStreamEndBlockMessage>(HandleTestStepLogStreamEndBlockMessage)
                           .Handle <LogEntrySubmittedMessage>(HandleLogEntrySubmittedMessage);

                tappedLogger.SetListener(this);
            }
Пример #2
0
            public Listener(TestRunnerEventDispatcher eventDispatcher, TappedLogger tappedLogger, LockBox<Report> reportBox)
            {
                this.eventDispatcher = eventDispatcher;
                this.tappedLogger = tappedLogger;
                this.reportBox = reportBox;

                states = new Dictionary<string, TestStepState>();

                rootTestStepIds = new List<string>();
                rootTestStepStopwatch = Stopwatch.StartNew();
                rootTestStepResult = new TestResult()
                {
                    Outcome = TestOutcome.Passed
                };

                consumer = new MessageConsumer()
                    .Handle<TestDiscoveredMessage>(HandleTestDiscoveredMessage)
                    .Handle<AnnotationDiscoveredMessage>(HandleAnnotationDiscoveredMessage)
                    .Handle<TestStepStartedMessage>(HandleTestStepStartedMessage)
                    .Handle<TestStepLifecyclePhaseChangedMessage>(HandleTestStepLifecyclePhaseChangedMessage)
                    .Handle<TestStepMetadataAddedMessage>(HandleTestStepMetadataAddedMessage)
                    .Handle<TestStepFinishedMessage>(HandleTestStepFinishedMessage)
                    .Handle<TestStepLogAttachMessage>(HandleTestStepLogAttachMessage)
                    .Handle<TestStepLogStreamWriteMessage>(HandleTestStepLogStreamWriteMessage)
                    .Handle<TestStepLogStreamEmbedMessage>(HandleTestStepLogStreamEmbedMessage)
                    .Handle<TestStepLogStreamBeginSectionBlockMessage>(HandleTestStepLogStreamBeginSectionBlockMessage)
                    .Handle<TestStepLogStreamBeginMarkerBlockMessage>(HandleTestStepLogStreamBeginMarkerBlockMessage)
                    .Handle<TestStepLogStreamEndBlockMessage>(HandleTestStepLogStreamEndBlockMessage)
                    .Handle<LogEntrySubmittedMessage>(HandleLogEntrySubmittedMessage);

                tappedLogger.SetListener(this);
            }
Пример #3
0
        /// <inheritdoc />
        public void Initialize(TestRunnerOptions testRunnerOptions, ILogger logger, IProgressMonitor progressMonitor)
        {
            if (testRunnerOptions == null)
                throw new ArgumentNullException("testRunnerOptions");
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");

            ThrowIfDisposed();
            if (state != State.Created)
                throw new InvalidOperationException("The test runner has already been initialized.");

            testRunnerOptions = testRunnerOptions.Copy();

            this.testRunnerOptions = testRunnerOptions;
            tappedLogger = new TappedLogger(this, logger);

            int extensionCount = extensions.Count;
            using (progressMonitor.BeginTask("Initializing the test runner.", 1 + extensionCount))
            {
                foreach (ITestRunnerExtension extension in extensions)
                {
                    string extensionName = extension.GetType().Name; // TODO: improve me

                    progressMonitor.SetStatus(String.Format("Installing extension '{0}'.", extensionName));
                    try
                    {
                        // Note: We don't pass the tapped logger to the extensions because the
                        //       extensions frequently write to the console a bunch of information we
                        //       already have represented in the report.  We are more interested in what
                        //       the test driver has to tell us.
                        extension.Install(eventDispatcher, logger);
                        progressMonitor.Worked(1);
                    }
                    catch (Exception ex)
                    {
                        throw new RunnerException(String.Format("Failed to install extension '{0}'.", extensionName), ex);
                    }
                    progressMonitor.SetStatus("");
                }

                try
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += OnUnhandledException;

                    eventDispatcher.NotifyInitializeStarted(new InitializeStartedEventArgs(testRunnerOptions));

                    progressMonitor.SetStatus("Initializing the test isolation context.");

                    TestIsolationOptions testIsolationOptions = new TestIsolationOptions();
                    GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testIsolationOptions.AddProperty(x.Key, x.Value));
                    testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, tappedLogger);

                    progressMonitor.Worked(1);
                }
                catch (Exception ex)
                {
                    eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(false));

                    UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;

                    throw new RunnerException("A fatal exception occurred while initializing the test isolation context.", ex);
                }

                state = State.Initialized;
                eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(true));
            }
        }
Пример #4
0
        /// <inheritdoc />
        public void Initialize(TestRunnerOptions testRunnerOptions, ILogger logger, IProgressMonitor progressMonitor)
        {
            if (testRunnerOptions == null)
            {
                throw new ArgumentNullException("testRunnerOptions");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            ThrowIfDisposed();
            if (state != State.Created)
            {
                throw new InvalidOperationException("The test runner has already been initialized.");
            }

            testRunnerOptions = testRunnerOptions.Copy();

            this.testRunnerOptions = testRunnerOptions;
            tappedLogger           = new TappedLogger(this, logger);

            int extensionCount = extensions.Count;

            using (progressMonitor.BeginTask("Initializing the test runner.", 1 + extensionCount))
            {
                foreach (ITestRunnerExtension extension in extensions)
                {
                    string extensionName = extension.GetType().Name; // TODO: improve me

                    progressMonitor.SetStatus(String.Format("Installing extension '{0}'.", extensionName));
                    try
                    {
                        // Note: We don't pass the tapped logger to the extensions because the
                        //       extensions frequently write to the console a bunch of information we
                        //       already have represented in the report.  We are more interested in what
                        //       the test driver has to tell us.
                        extension.Install(eventDispatcher, logger);
                        progressMonitor.Worked(1);
                    }
                    catch (Exception ex)
                    {
                        throw new RunnerException(String.Format("Failed to install extension '{0}'.", extensionName), ex);
                    }
                    progressMonitor.SetStatus("");
                }

                try
                {
                    UnhandledExceptionPolicy.ReportUnhandledException += OnUnhandledException;

                    eventDispatcher.NotifyInitializeStarted(new InitializeStartedEventArgs(testRunnerOptions));

                    progressMonitor.SetStatus("Initializing the test isolation context.");

                    TestIsolationOptions testIsolationOptions = new TestIsolationOptions();
                    GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testIsolationOptions.AddProperty(x.Key, x.Value));
                    testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, tappedLogger);

                    progressMonitor.Worked(1);
                }
                catch (Exception ex)
                {
                    eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(false));

                    UnhandledExceptionPolicy.ReportUnhandledException -= OnUnhandledException;

                    throw new RunnerException("A fatal exception occurred while initializing the test isolation context.", ex);
                }

                state = State.Initialized;
                eventDispatcher.NotifyInitializeFinished(new InitializeFinishedEventArgs(true));
            }
        }