/// <summary> /// Creates a copy of the host setup information. /// </summary> /// <returns>The copy.</returns> public HostSetup Copy() { HostSetup copy = new HostSetup(); copy.applicationBaseDirectory = applicationBaseDirectory; copy.workingDirectory = workingDirectory; copy.hintDirectories.AddRange(hintDirectories); copy.shadowCopy = shadowCopy; if (debuggerSetup != null) { copy.debuggerSetup = debuggerSetup.Copy(); } copy.processorArchitecture = processorArchitecture; copy.runtimeVersion = runtimeVersion; copy.elevated = elevated; copy.configurationFileLocation = configurationFileLocation; copy.properties.AddAll(properties); if (configuration != null) { copy.configuration = configuration.Copy(); } return(copy); }
protected override void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata) { base.ConfigureHostSetup(hostSetup, testPackage, assemblyPath, assemblyMetadata); // csUnit always creates its own AppDomain with shadow copy enabled so we do not need this. hostSetup.ShadowCopy = false; }
/// <inheritdoc /> protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { IsolatedAppDomainHost host = new IsolatedAppDomainHost(hostSetup, logger, debuggerManager); host.Connect(); return(host); }
public void WriteTemporaryConfigurationFile_ReturnsNullWhenNone() { HostSetup setup = new HostSetup(); setup.ConfigurationFileLocation = ConfigurationFileLocation.None; Assert.IsNull(setup.WriteTemporaryConfigurationFile()); }
public void WriteTemporaryConfigurationFile_ThrowsIfApplicationBaseDirectoryMissingButRequested() { HostSetup setup = new HostSetup(); setup.ConfigurationFileLocation = ConfigurationFileLocation.AppBase; Assert.Throws<InvalidOperationException>(() => setup.WriteTemporaryConfigurationFile()); }
/// <inheritdoc /> protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { IsolatedProcessHost host = new IsolatedProcessHost(hostSetup, logger, runtimePath); host.Connect(); return(host); }
/// <inheritdoc /> protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { var host = new LocalHost(hostSetup, logger, debuggerManager); host.Connect(); return(host); }
/// <summary> /// Sets the part cover coverage file. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="partCoverCoverageFile">The part cover coverage file.</param> internal static void SetPartCoverCoverageFile(HostSetup hostSetup, string partCoverCoverageFile) { if (hostSetup == null) throw new ArgumentNullException("hostSetup"); hostSetup.RemoveProperty("PartCoverCoverageFile"); hostSetup.AddProperty("PartCoverCoverageFile", partCoverCoverageFile); }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="debuggerManager">The debugger manager.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/> /// or <paramref name="debuggerManager"/> is null.</exception> public IsolatedAppDomainHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager) : base(hostSetup, logger, null) { if (debuggerManager == null) throw new ArgumentNullException("debuggerManager"); this.debuggerManager = debuggerManager; }
/// <inheritdoc /> protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { if (! Service.IsInstalled) throw new IntegrationNotInstalledException("TypeMock does not appear to be installed."); TypeMockHost host = new TypeMockHost(hostSetup, logger, RuntimePath); host.Connect(); return host; }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="debuggerManager">The debugger manager.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/> /// or <paramref name="debuggerManager"/> is null.</exception> public IsolatedAppDomainHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager) : base(hostSetup, logger, null) { if (debuggerManager == null) { throw new ArgumentNullException("debuggerManager"); } this.debuggerManager = debuggerManager; }
private static HostSetup ForceProcessorArchitectureAndRuntimeVersionIfRequired(HostSetup hostSetup, NCoverVersion version) { hostSetup = hostSetup.Copy(); NCoverTool tool = NCoverTool.GetInstance(version, hostSetup.ProcessorArchitecture); hostSetup.ProcessorArchitecture = tool.NegotiateProcessorArchitecture(hostSetup.ProcessorArchitecture); hostSetup.RuntimeVersion = tool.NegotiateRuntimeVersion(hostSetup.RuntimeVersion); return hostSetup; }
/// <summary> /// Creates a host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// or <paramref name="logger"/> is null.</exception> protected BaseHost(HostSetup hostSetup, ILogger logger) { if (hostSetup == null) throw new ArgumentNullException("hostSetup"); if (logger == null) throw new ArgumentNullException("logger"); this.hostSetup = hostSetup; this.logger = logger; }
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)); } }
protected override void ConfigureHostSetup(HostSetup hostSetup, TestPackage testPackage, string assemblyPath, AssemblyMetadata assemblyMetadata) { base.ConfigureHostSetup(hostSetup, testPackage, assemblyPath, assemblyMetadata); if (hostSetup.ProcessorArchitecture == ProcessorArchitecture.Amd64 || hostSetup.ProcessorArchitecture == ProcessorArchitecture.IA64) throw new ModelException("Cannot run MSTest tests compiled for 64bit because MSTest.exe throws exceptions when run without isolation as a 64bit process."); hostSetup.ProcessorArchitecture = ProcessorArchitecture.X86; }
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)); } }
/// <inheritdoc /> public IHost CreateHost(HostSetup hostSetup, ILogger logger) { if (hostSetup == null) throw new ArgumentNullException("hostSetup"); if (logger == null) throw new ArgumentNullException("logger"); HostSetup canonicalHostSetup = hostSetup.Copy(); canonicalHostSetup.Canonicalize(null); return CreateHostImpl(canonicalHostSetup, logger); }
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"); } }
internal static void GetNCoverProperties(HostSetup hostSetup, out string ncoverArguments, out string ncoverCoverageFile) { ncoverArguments = hostSetup.Properties.GetValue("NCoverArguments"); ncoverCoverageFile = hostSetup.Properties.GetValue("NCoverCoverageFile"); if (ncoverArguments == null) ncoverArguments = string.Empty; if (string.IsNullOrEmpty(ncoverCoverageFile)) ncoverCoverageFile = "Coverage.xml"; ncoverCoverageFile = Path.GetFullPath(ncoverCoverageFile); }
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); }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="runtimePath">The runtime path where the hosting executable will be found.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// <paramref name="logger"/>, or <paramref name="runtimePath"/> is null.</exception> public IsolatedProcessHost(HostSetup hostSetup, ILogger logger, string runtimePath) : base(hostSetup, logger, PingInterval) { if (runtimePath == null) { throw new ArgumentNullException("runtimePath"); } this.runtimePath = runtimePath; uniqueId = Hash64.CreateUniqueHash().ToString(); logConsoleOutputBufferTimer = new Timer(LogConsoleOutputBufferTimeoutExpired); }
private void CreateTemporaryConfigurationFile() { try { HostSetup patchedSetup = HostSetup.Copy(); patchedSetup.Configuration.AddAssemblyBinding(new AssemblyBinding(typeof(IsolatedProcessHost).Assembly)); temporaryConfigurationFilePath = patchedSetup.WriteTemporaryConfigurationFile(); } catch (Exception ex) { throw new HostException("Could not write the temporary configuration file.", ex); } }
/// <summary> /// Creates a host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// or <paramref name="logger"/> is null.</exception> protected BaseHost(HostSetup hostSetup, ILogger logger) { if (hostSetup == null) { throw new ArgumentNullException("hostSetup"); } if (logger == null) { throw new ArgumentNullException("logger"); } this.hostSetup = hostSetup; this.logger = logger; }
public void WriteTemporaryConfigurationFile_UsesTempFolderByDefault() { HostSetup setup = new HostSetup(); setup.ConfigurationFileLocation = ConfigurationFileLocation.Temp; string path = setup.WriteTemporaryConfigurationFile(); try { Assert.AreEqual(SpecialPathPolicy.For("Hosting").GetTempDirectory().FullName, Path.GetDirectoryName(path)); Assert.Contains(File.ReadAllText(path), "<configuration>"); } finally { File.Delete(path); } }
/// <inheritdoc /> public IHost CreateHost(HostSetup hostSetup, ILogger logger) { if (hostSetup == null) { throw new ArgumentNullException("hostSetup"); } if (logger == null) { throw new ArgumentNullException("logger"); } HostSetup canonicalHostSetup = hostSetup.Copy(); canonicalHostSetup.Canonicalize(null); return(CreateHostImpl(canonicalHostSetup, logger)); }
/// <summary> /// Creates a local host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="debuggerManager">The debugger manager.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/> /// or <paramref name="debuggerManager"/> is null.</exception> public LocalHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager) : base(hostSetup, logger) { if (debuggerManager == null) throw new ArgumentNullException("debuggerManager"); this.debuggerManager = debuggerManager; if (! string.IsNullOrEmpty(hostSetup.WorkingDirectory)) currentDirectorySwitcher = new CurrentDirectorySwitcher(hostSetup.WorkingDirectory); if (hostSetup.HintDirectories.Count != 0) { assemblyLoader = new DefaultAssemblyLoader(); GenericCollectionUtils.ForEach(hostSetup.HintDirectories, assemblyLoader.AddHintDirectory); } }
public void WriteTemporaryConfigurationFile_UsesApplicationBaseDirectoryWhenRequested() { HostSetup setup = new HostSetup(); setup.ApplicationBaseDirectory = AppDomain.CurrentDomain.BaseDirectory; setup.ConfigurationFileLocation = ConfigurationFileLocation.AppBase; string path = setup.WriteTemporaryConfigurationFile(); try { Assert.AreEqual(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory), Path.GetDirectoryName(path)); Assert.EndsWith(path, ".tmp.config"); Assert.Contains(File.ReadAllText(path), "<configuration>"); } finally { File.Delete(path); } }
/// <summary> /// Gets the part cover properties. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="partcoverIncludes">The partcover includes.</param> /// <param name="partcoverExcludes">The partcover excludes.</param> /// <param name="partcoverCoverageFile">The partcover coverage file.</param> internal static void GetPartCoverProperties(HostSetup hostSetup, out string partcoverIncludes, out string partcoverExcludes, out string partcoverCoverageFile) { if (hostSetup == null) throw new ArgumentNullException("hostSetup"); partcoverIncludes = hostSetup.Properties.GetValue("PartCoverIncludes"); partcoverExcludes = hostSetup.Properties.GetValue("PartCoverExcludes"); partcoverCoverageFile = hostSetup.Properties.GetValue("PartCoverCoverageFile"); if (partcoverIncludes == null) partcoverIncludes = "[*]*"; if (partcoverExcludes == null) partcoverExcludes = "[Gallio*]*;[MbUnit*]*;[Microsoft*]*"; if (string.IsNullOrEmpty(partcoverCoverageFile)) partcoverCoverageFile = "Coverage.xml"; partcoverCoverageFile = Path.GetFullPath(partcoverCoverageFile); }
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(); } } }
/// <summary> /// Creates a local host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="debuggerManager">The debugger manager.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/>, <paramref name="logger"/> /// or <paramref name="debuggerManager"/> is null.</exception> public LocalHost(HostSetup hostSetup, ILogger logger, IDebuggerManager debuggerManager) : base(hostSetup, logger) { if (debuggerManager == null) { throw new ArgumentNullException("debuggerManager"); } this.debuggerManager = debuggerManager; if (!string.IsNullOrEmpty(hostSetup.WorkingDirectory)) { currentDirectorySwitcher = new CurrentDirectorySwitcher(hostSetup.WorkingDirectory); } if (hostSetup.HintDirectories.Count != 0) { assemblyLoader = new DefaultAssemblyLoader(); GenericCollectionUtils.ForEach(hostSetup.HintDirectories, assemblyLoader.AddHintDirectory); } }
/// <summary> /// Creates the host. /// </summary> /// <param name="hostSetup">The canonicalized host setup, non-null.</param> /// <param name="logger">The logger, non-null.</param> /// <returns>The host.</returns> protected abstract IHost CreateHostImpl(HostSetup hostSetup, ILogger logger);
/// <inheritdoc /> protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { PartCoverHost host = new PartCoverHost(hostSetup, logger, RuntimePath); host.Connect(); return host; }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="pingInterval">The automatic ping interval, or null if none.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// or <paramref name="logger"/> is null.</exception> protected RemoteHost(HostSetup hostSetup, ILogger logger, TimeSpan?pingInterval) : base(hostSetup, logger) { this.pingInterval = pingInterval; }
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."); }
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); }
protected override IHost CreateHostImpl(HostSetup hostSetup, ILogger logger) { HostSetup = hostSetup; Logger = logger; return new MockRepository().Stub<IHost>(); }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="installationPath">The runtime installation path where the hosting executable will be found.</param> /// <param name="version">The NCover version.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// <paramref name="logger"/>, <paramref name="installationPath"/> is null.</exception> public NCoverHost(HostSetup hostSetup, ILogger logger, string installationPath, NCoverVersion version) : base(ForceProcessorArchitectureAndRuntimeVersionIfRequired(hostSetup, version), logger, installationPath) { this.version = version; }
/// <summary> /// Creates a host setup based on the package properties. /// </summary> /// <returns>The host setup.</returns> public HostSetup CreateHostSetup() { var hostSetup = new HostSetup { DebuggerSetup = DebuggerSetup, ShadowCopy = ShadowCopy, ApplicationBaseDirectory = ApplicationBaseDirectory != null ? ApplicationBaseDirectory.FullName : null, WorkingDirectory = WorkingDirectory != null ? WorkingDirectory.FullName : null, RuntimeVersion = RuntimeVersion }; GenericCollectionUtils.ForEach(Properties, x => hostSetup.AddProperty(x.Key, x.Value)); GenericCollectionUtils.ForEach(HintDirectories, x => hostSetup.AddHintDirectory(x.FullName)); return hostSetup; }
internal static void SetNCoverCoverageFile(HostSetup hostSetup, string ncoverCoverageFile) { hostSetup.RemoveProperty("NCoverCoverageFile"); hostSetup.AddProperty("NCoverCoverageFile", ncoverCoverageFile); }
/// <summary> /// Creates an uninitialized host. /// </summary> /// <param name="hostSetup">The host setup.</param> /// <param name="logger">The logger for host message output.</param> /// <param name="runtimePath">The runtime path where the hosting executable will be found.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="hostSetup"/> /// <paramref name="logger"/>, or <paramref name="runtimePath"/> is null.</exception> public IsolatedProcessHost(HostSetup hostSetup, ILogger logger, string runtimePath) : base(hostSetup, logger, PingInterval) { if (runtimePath == null) throw new ArgumentNullException("runtimePath"); this.runtimePath = runtimePath; uniqueId = Hash64.CreateUniqueHash().ToString(); logConsoleOutputBufferTimer = new Timer(LogConsoleOutputBufferTimeoutExpired); }
/// <summary> /// Creates a copy of the host setup information. /// </summary> /// <returns>The copy.</returns> public HostSetup Copy() { HostSetup copy = new HostSetup(); copy.applicationBaseDirectory = applicationBaseDirectory; copy.workingDirectory = workingDirectory; copy.hintDirectories.AddRange(hintDirectories); copy.shadowCopy = shadowCopy; if (debuggerSetup != null) copy.debuggerSetup = debuggerSetup.Copy(); copy.processorArchitecture = processorArchitecture; copy.runtimeVersion = runtimeVersion; copy.elevated = elevated; copy.configurationFileLocation = configurationFileLocation; copy.properties.AddAll(properties); if (configuration != null) copy.configuration = configuration.Copy(); return copy; }