コード例 #1
0
        public void LaunchesMSILHostByDefault()
        {
            HostSetup hostSetup = new HostSetup();

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                string processName = host.GetHostService().Do <object, string>(GetHostProcessName, null);

                Assert.Contains(processName, "Gallio.Host.exe");
            }
        }
コード例 #2
0
        public void TypeMockHostRunsWithTypeMockAttached()
        {
            TypeMockHostFactory factory = new TypeMockHostFactory(RuntimeAccessor.Instance);

            using (IHost host = factory.CreateHost(new HostSetup(), new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);

                bool isTypeMockRunning = host.GetHostService().Do <object, bool>(IsTypeMockRunning, null);
                Assert.IsTrue(isTypeMockRunning, "TypeMock should be attached to the host process.");
            }
        }
コード例 #3
0
        public void HostRunsWithSpecifiedApplicationBaseDirectory()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.ApplicationBaseDirectory = Path.GetTempPath();

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                AssertArePathsEqualIgnoringFinalBackslash(Path.GetTempPath(), host.GetHostService().Do <object, string>(GetApplicationBaseDirectory, null));
            }
        }
コード例 #4
0
        public void HostRunsWithShadowCopyingEnabledOnRequest()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.ShadowCopy = true;

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                Assert.IsTrue(host.GetHostService().Do <object, bool>(IsShadowCopyFilesEnabled, null));
            }
        }
コード例 #5
0
        public void LaunchesX86HostWhenDemandedByProcessorArchitecture()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.ProcessorArchitecture = ProcessorArchitecture.X86;

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                string processName = host.GetHostService().Do <object, string>(GetHostProcessName, null);

                Assert.Contains(processName, "Gallio.Host.x86.exe");
            }
        }
コード例 #6
0
        public void PolicyPerformsCorrelationThenReporting()
        {
            CorrelatedExceptionEventArgs finalArgs;

            using (IHost host = new IsolatedProcessHostFactory(RuntimeAccessor.Instance).CreateHost(new HostSetup(), new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                finalArgs = (CorrelatedExceptionEventArgs)host.GetHostService().Do <object, object>(PolicyPerformsCorrelationThenReportingCallback, null);
            }

            Assert.IsNotNull(finalArgs);
            Assert.AreEqual("foo\nbar", finalArgs.Message);
            Assert.IsInstanceOfType <Exception>(finalArgs.Exception);
            Assert.IsFalse(finalArgs.IsRecursive);
        }
コード例 #7
0
        public void DoCallbackHasRemoteSideEffects()
        {
            using (IHost host = Factory.CreateHost(new HostSetup(), new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);

                Assert.AreEqual(0, callbackCounter);

                Assert.AreEqual(1, host.GetHostService().Do <int, int>(DoCallbackHasRemoteSideEffectsCallback, 1));
                Assert.Throws <Exception>(delegate { host.GetHostService().Do <int, int>(DoCallbackHasRemoteSideEffectsCallback, 1); });
                Assert.AreEqual(5, host.GetHostService().Do <int, int>(DoCallbackHasRemoteSideEffectsCallback, 3));

                Assert.AreEqual(0, callbackCounter);
            }
        }
コード例 #8
0
        public void ToleratesAppDomainUnload()
        {
            StringWriter logWriter = new StringWriter();
            var          logger    = new SeverityPrefixLogger(new TextLogger(logWriter));

            var hostFactory = (IsolatedAppDomainHostFactory)RuntimeAccessor.ServiceLocator.ResolveByComponentId(IsolatedAppDomainHostFactory.ComponentId);

            using (IHost host = hostFactory.CreateHost(new HostSetup(), logger))
            {
                HostAssemblyResolverHook.InstallCallback(host);

                host.GetHostService().Do <object, object>(RemoteCallback, null);
            }

            Assert.AreEqual("", logWriter.ToString(),
                            "A dangling Db4o client may have caused the AppDomain.Unload to fail.  Check the DomainUnload event handling policy for the client.");
        }
コード例 #9
0
        public void HostRunsInRequestedWorkingDirectory()
        {
            string oldWorkingDirectory = Environment.CurrentDirectory;

            HostSetup hostSetup = new HostSetup();

            hostSetup.WorkingDirectory = Path.GetTempPath();

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                string remoteWorkingDirectory = host.GetHostService().Do <object, string>(GetWorkingDirectory, null);
                AssertArePathsEqualIgnoringFinalBackslash(Path.GetTempPath(), remoteWorkingDirectory);
            }

            Assert.AreEqual(oldWorkingDirectory, Environment.CurrentDirectory,
                            "Current working directory of the calling process should be unchanged or at least restored once the host is disposed.");
        }
コード例 #10
0
        public void PolicyHandlesUnhandledExceptionsAndRecursion()
        {
            List <CorrelatedExceptionEventArgs> args;

            using (IHost host = new IsolatedProcessHostFactory(RuntimeAccessor.Instance).CreateHost(new HostSetup(), new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                args = (List <CorrelatedExceptionEventArgs>)host.GetHostService().Do <object, object>(PolicyHandlesUnhandledExceptionsAndRecursionCallback, null);
            }

            Assert.Count(3, args);
            Assert.AreEqual("Error.", args[0].Exception.Message);
            Assert.IsFalse(args[0].IsRecursive);
            Assert.AreEqual("Correlation error.", args[1].Exception.Message);
            Assert.IsTrue(args[1].IsRecursive);
            Assert.AreEqual("Reporting error.", args[2].Exception.Message);
            Assert.IsTrue(args[2].IsRecursive);
        }
コード例 #11
0
        public void RegisteredServiceCanBeAccessedWithGetService()
        {
            var hostFactory = (IsolatedAppDomainHostFactory)RuntimeAccessor.ServiceLocator.ResolveByComponentId(IsolatedAppDomainHostFactory.ComponentId);

            using (IHost host = hostFactory.CreateHost(new HostSetup(), new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);

                host.GetHostService().Do <object, object>(RemoteCallback, null);

                using (BinaryIpcClientChannel clientChannel = new BinaryIpcClientChannel(PortName))
                {
                    TestService serviceProxy =
                        (TestService)clientChannel.GetService(typeof(TestService), ServiceName);
                    Assert.AreEqual(42, serviceProxy.Add(23, 19));
                }
            }
        }
コード例 #12
0
        public void HostRunsWithSpecifiedConfigurationXml()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.Configuration.ConfigurationXml =
                "<configuration>"
                + "  <appSettings>"
                + "    <add key=\"TestSetting\" value=\"TestValue\" />"
                + "  </appSettings>"
                + "</configuration>";

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                string setting = host.GetHostService().Do <object, string>(GetTestSetting, null);
                Assert.AreEqual("TestValue", setting);
            }
        }
コード例 #13
0
        public void HostRunsWithSpecifiedAssertUiFlag()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.Configuration.AssertUiEnabled = true;

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                Assert.IsTrue(host.GetHostService().Do <object, bool>(GetAssertUiEnabledFlag, null));
            }

            hostSetup.Configuration.AssertUiEnabled = false;

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                Assert.IsFalse(host.GetHostService().Do <object, bool>(GetAssertUiEnabledFlag, null));
            }
        }
コード例 #14
0
        public void HostDoesNotTerminateAbruptlyIfUnhandledExceptionThrowsWithTheLegacyUnhandledExceptionPolicyEnabled()
        {
            HostSetup hostSetup = new HostSetup();

            hostSetup.Configuration.LegacyUnhandledExceptionPolicyEnabled = true;

            using (IHost host = Factory.CreateHost(hostSetup, new MarkupStreamLogger(TestLog.Default)))
            {
                HostAssemblyResolverHook.InstallCallback(host);
                host.GetHostService().Do <object, object>(ThrowUnhandledExceptionCallback, null);

                // Ping the host a few times to ensure that the process does not terminate abruptly.
                // In practice it may continue to service requests for a little while after the
                // unhandled exception occurs.
                for (int i = 0; i < 3; i++)
                {
                    Thread.Sleep(1000);
                    host.GetHostService().Ping();
                }
            }
        }
コード例 #15
0
            private TestResult RunTests(string assemblyPath)
            {
                AssemblyMetadata assemblyMetadata = AssemblyUtils.GetAssemblyMetadata(assemblyPath, AssemblyMetadataFields.Default);

                if (assemblyMetadata == null)
                {
                    ITestContext testContext = listOfTestCommands[0].StartPrimaryChildStep(topTestStep);
                    testContext.LifecyclePhase = LifecyclePhases.Execute;
                    testContext.LogWriter.Failures.WriteLine("Test assembly does not exist or is not a valid .Net assembly. [{0}]", assemblyPath ?? String.Empty);
                    return(testContext.FinishStep(TestOutcome.Error, null));
                }

                // Remark: We cannot use the RemoteLoader directly from this AppDomain.
                //   csUnit v2.5 contains a bug in its detection of the NUnitAdapter.  It tries
                //   to enumerate ALL types in ALL assemblies that are loaded in the AppDomain.
                //   Bad news for us because some of these types derived from other types in
                //   assemblies that cannot be loaded (eg. VisualStudio APIs).
                //   So csUnit promptly blows up.  The workaround is to create our own AppDomain.
                //   We cannot use the csUnit Loader because it does things like report
                //   events asynchronously and possibly out of order or even in parallel. -- Jeff.
                // See also: http://sourceforge.net/tracker/index.php?func=detail&aid=2111390&group_id=23919&atid=380010
                HostSetup hostSetup = new HostSetup();

                hostSetup.ApplicationBaseDirectory = Path.GetDirectoryName(assemblyPath);
                hostSetup.WorkingDirectory         = hostSetup.ApplicationBaseDirectory;
                hostSetup.ShadowCopy = true;
                hostSetup.ConfigurationFileLocation = ConfigurationFileLocation.AppBase;
                hostSetup.ProcessorArchitecture     = assemblyMetadata.ProcessorArchitecture;

                string configFile = assemblyPath + ".config";

                if (File.Exists(configFile))
                {
                    hostSetup.Configuration.ConfigurationXml = File.ReadAllText(configFile);
                }

                var hostFactory = (IHostFactory)RuntimeAccessor.ServiceLocator.ResolveByComponentId(IsolatedAppDomainHostFactory.ComponentId);

                using (IHost host = hostFactory.CreateHost(hostSetup, RuntimeAccessor.Logger))
                {
                    HostAssemblyResolverHook.InstallCallback(host);

                    Type loaderType = typeof(RemoteLoader);

                    using (RemoteLoader loader = (RemoteLoader)host.GetHostService().CreateInstance(
                               loaderType.Assembly.FullName,
                               loaderType.FullName).Unwrap())
                    {
                        // Attach ourself to get feedback
                        loader.Listener = this;

                        // Load the test assembly
                        loader.LoadAssembly(assemblyPath);

                        // Run the tests of that assembly
                        TextWriter consoleOutputWriter = new ContextualLogTextWriter(MarkupStreamNames.ConsoleOutput);
                        var        spec = new CallbackTestSpec(this);
                        loader.RunTests(spec, consoleOutputWriter);
                    }
                }

                return(topResult ?? new TestResult(TestOutcome.Error));
            }