TestModel PopulateTestTree(Assembly assembly)
    {
      TestModel testModel = new TestModel();

      var testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>();
      var logger = new MarkupStreamLogger(TestLog.Default);

      var testFrameworkSelector = new TestFrameworkSelector()
      {
        Filter = testFrameworkHandle => testFrameworkHandle.Id == TestFrameworkHandle.Id,
        FallbackMode = TestFrameworkFallbackMode.Strict
      };

      ITestDriver testDriver = testFrameworkManager.GetTestDriver(testFrameworkSelector, logger);

      var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
      var testIsolationOptions = new TestIsolationOptions();
      using (ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, logger))
      {
        var testPackage = new TestPackage();
        testPackage.AddFile(new FileInfo(AssemblyUtils.GetFriendlyAssemblyCodeBase(assembly)));
        var testExplorationOptions = new TestExplorationOptions();

        var messageSink = TestModelSerializer.CreateMessageSinkToPopulateTestModel(testModel);

        new LogProgressMonitorProvider(logger).Run(progressMonitor =>
        {
          testDriver.Explore(testIsolationContext, testPackage, testExplorationOptions,
            messageSink, progressMonitor);
        });
      }

      return testModel;
    }
        public void CreateHostDelegatesToCreateHostImplWithACanonicalizedHostSetup()
        {
            StubHostFactory factory = new StubHostFactory();

            HostSetup originalHostSetup = new HostSetup();
            originalHostSetup.WorkingDirectory = "";
            ILogger logger = new MarkupStreamLogger(TestLog.Default);
            Assert.IsNotNull(factory.CreateHost(originalHostSetup, logger));

            Assert.AreNotSame(originalHostSetup, factory.HostSetup);
            Assert.AreEqual(Environment.CurrentDirectory, factory.HostSetup.WorkingDirectory);
            Assert.AreSame(logger, factory.Logger);
        }
        public void GetVisualStudio_WhenVisualStudioIsNotRunning_ReturnsNull()
        {
            var manager = VisualStudioManager.Instance;
            var logger = new MarkupStreamLogger(TestLog.Default);

            var versions = new[] {
                VisualStudioVersion.VS2010,
                VisualStudioVersion.VS2012,
                VisualStudioVersion.VS2013
            };

            foreach (VisualStudioVersion version in versions)
            {
                if (manager.GetVisualStudio(version, false, logger) == null)
                    return;
            }

            Assert.Inconclusive("Expected to find at least one version of Visual Studio not already running but they all seem to be.");
        }
        public void LaunchAndGetVisualStudio()
        {
            var manager = VisualStudioManager.Instance;
            var logger = new MarkupStreamLogger(TestLog.Default);

            IVisualStudio visualStudio = manager.LaunchVisualStudio(VisualStudioVersion.Any, logger);
            Assert.IsNotNull(visualStudio, "Should have started an instance.");

            try
            {
                Assert.IsTrue(visualStudio.WasLaunched, "New instance launched so WasLaunched should be true.");

                AssertVisualStudioCanBeUsed(visualStudio);
                AssertExistingInstanceOfVisualStudioCanBeLocated(manager, logger, visualStudio.Version);
            }
            finally
            {
                visualStudio.Quit();
            }
        }
        public void GetVisualStudio_WhenLaunchFlagIsTrue_ProvidesAnInstanceOrStartsOne()
        {
            var manager = VisualStudioManager.Instance;
            var logger = new MarkupStreamLogger(TestLog.Default);

            IVisualStudio visualStudio = manager.GetVisualStudio(VisualStudioVersion.Any, true, logger);
            Assert.IsNotNull(visualStudio, "Should have found or started an instance.");

            try
            {
                AssertVisualStudioCanBeUsed(visualStudio);
                AssertExistingInstanceOfVisualStudioCanBeLocated(manager, logger, visualStudio.Version);
            }
            finally
            {
                if (visualStudio.WasLaunched)
                    visualStudio.Quit();
            }
        }
        public void CanAttachToProcessWithDebugger()
        {
            var debuggerSetup = new DebuggerSetup();
            var logger = new MarkupStreamLogger(TestLog.Default);
            var debugger = new VisualStudioDebugger(debuggerSetup, logger, null);

            ProcessStartInfo processStartInfo = CreateProcessStartInfoForDummyProcess();

            Process process = Process.Start(processStartInfo);
            try
            {
                Assert.IsFalse(debugger.IsAttachedToProcess(process), "Initially the debugger is not attached.");

                Assert.AreEqual(AttachDebuggerResult.Attached, debugger.AttachToProcess(process),
                    "Should attach to process.");
                Assert.IsTrue(debugger.IsAttachedToProcess(process), "Should report that it has attached to process.");
                Assert.AreEqual(AttachDebuggerResult.AlreadyAttached, debugger.AttachToProcess(process),
                    "Should report that it was already attached to process.");

                /* This fails because Visual Studio returns "The requested operation is not supported."
                 * It seems to be related to having the Native debugger engine attached.
                Assert.AreEqual(DetachDebuggerResult.Detached, debugger.DetachFromProcess(process), "Should detach from process.");
                Assert.IsFalse(debugger.IsAttachedToProcess(process), "Finally the debugger is not attached.");
                Assert.AreEqual(DetachDebuggerResult.AlreadyDetached, debugger.DetachFromProcess(process), "Should report that it was already detached from process.");
                 */
            }
            finally
            {
                process.Kill();
            }
        }