Ejemplo n.º 1
0
        public void CreateProcess_WhenWorkingDirectoryPreferenceRefersToMissingDirectory_ThrowsDirectoryNotFoundException()
        {
            preferenceManager.WorkingDirectory = @"c:\missing\dir\";
            var options = new TestIsolationOptions();

            Assert.Throws <DirectoryNotFoundException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 2
0
        private static StartupAction GetStartupAction(TestIsolationOptions options, IAcadPreferenceManager preferenceManager)
        {
            // Startup actions from test isolation options take precedence.
            var attach = GetAttachOption(options);

            if (attach.HasValue && attach.Value)
            {
                return(StartupAction.AttachToExisting);
            }

            var executable = options.Properties.GetValue("AcadExePath");

            if (!string.IsNullOrEmpty(executable))
            {
                return(StartupAction.StartUserSpecified);
            }

            // Fall back to preference manager, ensuring that "AcadAttachToExisting=false" is honored.
            var preference = preferenceManager.StartupAction;

            if (preference == StartupAction.AttachToExisting && attach.HasValue)
            {
                return(StartupAction.StartMostRecentlyUsed);
            }

            return(preference);
        }
Ejemplo n.º 3
0
        public void CreateProcess_WhenWorkingDirectoryPreferenceIsInvalid_ThrowsArgumentException()
        {
            preferenceManager.WorkingDirectory = new string(Path.GetInvalidPathChars());
            var options = new TestIsolationOptions();

            Assert.Throws <ArgumentException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 4
0
        protected 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);
        }
Ejemplo n.º 5
0
        public void CreateProcess_WhenUserSpecifiedExecutablePreferenceIsInvalid_ThrowsArgumentException()
        {
            preferenceManager.StartupAction           = StartupAction.StartUserSpecified;
            preferenceManager.UserSpecifiedExecutable = new string(Path.GetInvalidPathChars());
            var options = new TestIsolationOptions();

            Assert.Throws <ArgumentException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 6
0
        public void CreateProcess_WhenExePropertyRefersToMissingFile_ThrowsFileNotFoundException()
        {
            var options = new TestIsolationOptions();

            options.AddProperty("AcadExePath", @"c:\path\to\missing\acad.exe");

            Assert.Throws <FileNotFoundException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 7
0
        public void CreateProcess_WhenUserSpecifiedExecutablePreferenceIsNull_ThrowsArgumentException()
        {
            preferenceManager.StartupAction           = StartupAction.StartUserSpecified;
            preferenceManager.UserSpecifiedExecutable = null;
            var options = new TestIsolationOptions();

            Assert.Throws <ArgumentException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 8
0
        public void CreateProcess_WhenExePropertyIsInvalid_ThrowsArgumentException()
        {
            var options = new TestIsolationOptions();

            options.AddProperty("AcadExePath", new string(Path.GetInvalidPathChars()));

            Assert.Throws <ArgumentException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 9
0
        public void CreateProcess_WhenUserSpecifiedExecutablePreferenceRefersToMissingFile_ThrowsFileNotFoundException()
        {
            preferenceManager.StartupAction           = StartupAction.StartUserSpecified;
            preferenceManager.UserSpecifiedExecutable = @"c:\missing\path\to\acad.exe";
            var options = new TestIsolationOptions();

            Assert.Throws <FileNotFoundException>(() => factory.CreateProcess(options));
        }
Ejemplo n.º 10
0
        public void CreateProcess_WhenStartupActionPreferenceIsAttachToExisting_ReturnsExistingProcess()
        {
            processFinder.Processes         = new[] { MockRepository.GenerateStub <IProcess>() };
            preferenceManager.StartupAction = StartupAction.AttachToExisting;
            var options = new TestIsolationOptions();

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <ExistingAcadProcess>(process);
        }
Ejemplo n.º 11
0
        public void CreateProcess_WhenCommandLineArgumentsPreferenceProvided_SetsProcessArguments()
        {
            preferenceManager.CommandLineArguments = "arguments";
            var options = new TestIsolationOptions();

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <CreatedAcadProcess>(process);
            Assert.AreEqual("arguments", ((CreatedAcadProcess)process).Arguments);
        }
Ejemplo n.º 12
0
        public void CreateProcess_WhenStartupActionPreferenceIsStartMru_SetsFileName()
        {
            preferenceManager.StartupAction = StartupAction.StartMostRecentlyUsed;
            var options = new TestIsolationOptions();

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <CreatedAcadProcess>(process);
            Assert.AreEqual(@"c:\most\recently\used\acad.exe", ((CreatedAcadProcess)process).FileName);
        }
Ejemplo n.º 13
0
        public void CreateProcess_WhenWorkingDirectoryPreferenceProvided_SetsWorkingDirectory()
        {
            preferenceManager.WorkingDirectory = @"c:\working\dir\";
            var options = new TestIsolationOptions();

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <CreatedAcadProcess>(process);
            Assert.AreEqual(@"c:\working\dir\", ((CreatedAcadProcess)process).WorkingDirectory);
        }
Ejemplo n.º 14
0
        public void CreateProcess_WhenStartupActionPreferenceIsStartUserSpecified_SetsFileName()
        {
            preferenceManager.StartupAction           = StartupAction.StartUserSpecified;
            preferenceManager.UserSpecifiedExecutable = @"c:\path\to\acad.exe";
            var options = new TestIsolationOptions();

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <CreatedAcadProcess>(process);
            Assert.AreEqual(@"c:\path\to\acad.exe", ((CreatedAcadProcess)process).FileName);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        public void CreateProcess_WhenAttachPropertyProvided_ReturnsExistingProcess()
        {
            processFinder.Processes = new[] { MockRepository.GenerateStub <IProcess>() };
            var options = new TestIsolationOptions();

            options.AddProperty("AcadAttachToExisting", "true");

            var process = factory.CreateProcess(options);

            Assert.IsInstanceOfType <ExistingAcadProcess>(process);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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));
        }
        public void CreateContext_ReturnsAnAcadTestIsolationContext()
        {
            var options        = new TestIsolationOptions();
            var process        = MockRepository.GenerateStub <IAcadProcess>();
            var processFactory = MockRepository.GenerateStub <IAcadProcessFactory>();

            processFactory.Stub(x => x.CreateProcess(Arg.Is(options))).Return(process);

            var provider = new AcadTestIsolationProvider(processFactory);

            var context = provider.CreateContext(options, logger);

            Assert.IsInstanceOfType <AcadTestIsolationContext>(context);
        }
Ejemplo n.º 21
0
        private static string GetExecutable(TestIsolationOptions options, IAcadPreferenceManager preferenceManager, IAcadLocator acadLocator)
        {
            var executable = options.Properties.GetValue("AcadExePath");

            if (!string.IsNullOrEmpty(executable))
            {
                return(executable);
            }

            if (preferenceManager.StartupAction == StartupAction.StartUserSpecified)
            {
                return(preferenceManager.UserSpecifiedExecutable);
            }

            return(acadLocator.GetMostRecentlyUsed());
        }
Ejemplo n.º 22
0
        private static bool UseRemoting(TestIsolationOptions testIsolationOptions)
        {
            if (testIsolationOptions.Properties.ContainsKey("MessageSink"))
            {
                var messageSinkToUse = testIsolationOptions.Properties["MessageSink"];

                if (messageSinkToUse == "Remoting")
                {
                    return(true);
                }

                throw new ArgumentException(string.Format("{0} is not a valid value for MessageSink", messageSinkToUse));
            }
            // HACK: this code gets executed both in and out of proc :(
            // it won't be necessary once all communication is via messaging
            return(Process.GetCurrentProcess().ProcessName == "Gallio.Host");
        }
Ejemplo n.º 23
0
        private static bool?GetAttachOption(TestIsolationOptions options)
        {
            var attachOption = options.Properties.GetValue("AcadAttachToExisting");

            if (attachOption == null)
            {
                return(null);
            }

            bool attach;

            if (!bool.TryParse(attachOption, out attach))
            {
                throw new ArgumentException(string.Format("Error parsing AcadAttachToExisting value: \"{0}\"", attachOption));
            }

            return(attach);
        }
Ejemplo n.º 24
0
        /// <inheritdoc/>
        /// <remarks>
        /// <para>
        /// <c>CreateProcess</c> creates <see cref="IAcadProcess"/> objects that use AutoCAD's
        /// OLE Automation support for the initial communication with the AutoCAD process.
        /// Unfortunately, AutoCAD does not register each process with a unique moniker so
        /// retrieving the "AutoCAD.Application" object for a specific process using
        /// <see cref="Marshal.GetActiveObject(string)"/> is not possible. To handle this the
        /// <see cref="CreateProcess"/> method throws <see cref="NotSupportedException"/>
        /// whenever it is unsure what AutoCAD process it will acquire from the ROT.
        /// </para>
        /// </remarks>
        /// <exception cref="InvalidOperationException">
        /// If attaching to an existing process and none can be found.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// If creating a new AutoCAD process and an existing one is found.
        /// If attaching to an existing process and more than one is found.
        /// </exception>
        public IAcadProcess CreateProcess(TestIsolationOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var startupAction = GetStartupAction(options, preferenceManager);

            if (startupAction == StartupAction.AttachToExisting)
            {
                var existing = GetExistingAcadProcess();
                return(AttachToProcess(existing));
            }

            var executable       = GetExecutable(options, preferenceManager, acadLocator);
            var workingDirectory = GetWorkingDirectory(preferenceManager);
            var arguments        = GetArguments(preferenceManager);

            return(CreateNewProcess(executable, workingDirectory, arguments));
        }
Ejemplo n.º 25
0
        private List <Test> getTests(string assembly)
        {
            var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
            var testIsolationOptions  = new TestIsolationOptions();
            ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, _logger);

            // Create a test package.
            // You can set a whole bunch of options here.
            var testPackage = new TestPackage();

            testPackage.AddFile(new FileInfo(assembly));
            testPackage.TestFrameworkFallbackMode = TestFrameworkFallbackMode.Strict;

            var testExplorationOptions = new TestExplorationOptions();

            // This query you can answer by exploring tests and looking at their metadata for "TestsOn".
            // You can explore tests using the Explore method of TestDriver. It sends a bunch of
            // messages to an IMessageSink just like Run.  Just scan these messages for tests that
            // match the pattern you like.

            // Alternately, you can build a TestModel once up front and traverse the resulting test tree
            // to find what you need.  The Explore method of testDriver is just like Run, except that
            // it does not run the tests.
            // TestModelSerializer is a little helper we can use to build up a TestModel from test messages on the fly.
            // The TestModel is just a tree of test metadata.  Pretty straightforward.
            TestModel    testModel   = new TestModel();
            IMessageSink messageSink = TestModelSerializer.CreateMessageSinkToPopulateTestModel(testModel);

            var logProgressMonitorProvider = new LogProgressMonitorProvider(_logger);

            logProgressMonitorProvider.Run((progressMonitor) =>
            {
                _testDriver.Explore(testIsolationContext, testPackage, testExplorationOptions, messageSink, progressMonitor);
            });

            return(testModel.AllTests.Where(x => x.IsTestCase).ToList());
        }
Ejemplo n.º 26
0
 private static int?GetPort(TestIsolationOptions testIsolationOptions)
 {
     return(null);
 }
Ejemplo n.º 27
0
 private static IMessageFormatter GetMessageFormatter(TestIsolationOptions testIsolationOptions)
 {
     return(new BinaryMessageFormatter());
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Gets the right message sink for the host, based on the test isolation options.
 /// </summary>
 /// <param name="testIsolationOptions">The test isolation options.</param>
 /// <param name="messageSink">The message sink to wrap.</param>
 /// <returns>An appropriate message sink for the runner.</returns>
 public static IMessageSink GetHostMessageSink(TestIsolationOptions testIsolationOptions, IMessageSink messageSink)
 {
     return(UseRemoting(testIsolationOptions)
                         ? messageSink
                         : new AsyncTcpServerMessageSink(GetMessageFormatter(testIsolationOptions), GetPort(testIsolationOptions)));
 }
        /// <inheritdoc />
        protected override ITestIsolationContext CreateContextImpl(TestIsolationOptions testIsolationOptions, ILogger logger)
        {
            var process = processFactory.CreateProcess(testIsolationOptions);

            return(new AcadTestIsolationContext(logger, process));
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates an NCover test isolation context.
 /// </summary>
 /// <param name="testIsolationOptions">The test isolation options.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="runtime">The runtime.</param>
 /// <param name="version">The NCover version.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="testIsolationOptions" />,
 /// <paramref name="logger"/> or <paramref name="runtime"/> is null.</exception>
 public NCoverTestIsolationContext(TestIsolationOptions testIsolationOptions, ILogger logger,
                                   IRuntime runtime, NCoverVersion version)
     : base(new NCoverHostFactory(runtime, version), testIsolationOptions, logger)
 {
     this.version = version;
 }