public void CreateProcess_WhenAttachAndExePropertiesProvided_ReturnsExistingProcess() { processFinder.Processes = new[] { MockRepository.GenerateStub <IProcess>() }; var options = new TestIsolationOptions(); options.AddProperty("AcadAttachToExisting", "true"); options.AddProperty("AcadExePath", @"c:\path\to\acad.exe"); var process = factory.CreateProcess(options); Assert.IsInstanceOfType <ExistingAcadProcess>(process); }
public void CreateProcess_WhenExePropertyRefersToMissingFile_ThrowsFileNotFoundException() { var options = new TestIsolationOptions(); options.AddProperty("AcadExePath", @"c:\path\to\missing\acad.exe"); Assert.Throws <FileNotFoundException>(() => factory.CreateProcess(options)); }
public void CreateProcess_WhenExePropertyIsInvalid_ThrowsArgumentException() { var options = new TestIsolationOptions(); options.AddProperty("AcadExePath", new string(Path.GetInvalidPathChars())); Assert.Throws <ArgumentException>(() => factory.CreateProcess(options)); }
public void CreateProcess_WhenExePropertyProvided_SetsProcessFileName() { var options = new TestIsolationOptions(); options.AddProperty("AcadExePath", @"c:\path\to\acad.exe"); var process = factory.CreateProcess(options); Assert.IsInstanceOfType <CreatedAcadProcess>(process); Assert.AreEqual(@"c:\path\to\acad.exe", ((CreatedAcadProcess)process).FileName); }
public void CreateProcess_WhenAttachPropertyProvided_OverridesPreferenceManager() { processFinder.Processes = new[] { MockRepository.GenerateStub <IProcess>() }; preferenceManager.StartupAction = StartupAction.StartMostRecentlyUsed; var options = new TestIsolationOptions(); options.AddProperty("AcadAttachToExisting", @"true"); var process = factory.CreateProcess(options); Assert.IsInstanceOfType <ExistingAcadProcess>(process); }
public void CreateProcess_WhenExePropertyProvided_OverridesPreferenceManager() { preferenceManager.StartupAction = StartupAction.AttachToExisting; var options = new TestIsolationOptions(); options.AddProperty("AcadExePath", @"c:\path\to\acad.exe"); var process = factory.CreateProcess(options); Assert.IsInstanceOfType <CreatedAcadProcess>(process); Assert.AreEqual(@"c:\path\to\acad.exe", ((CreatedAcadProcess)process).FileName); }
public void CreateProcess_WhenMoreThanOneExistingProcess_AttachExisting_ThrowsNotSupportedException() { processFinder.Processes = new[] { MockRepository.GenerateStub <IProcess>(), MockRepository.GenerateStub <IProcess>() }; var options = new TestIsolationOptions(); options.AddProperty("AcadAttachToExisting", @"true"); Assert.Throws <NotSupportedException>(() => factory.CreateProcess(options)); }
/// <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)); } }