public IService GetService(Type serviceType) { IService theService = (IService)serviceIndex[serviceType]; if (theService == null) { foreach (IService service in services) { // TODO: Does this work on Mono? if (serviceType.IsInstanceOfType(service)) { serviceIndex[serviceType] = service; theService = service; break; } } } if (theService == null) { NTrace.Error(string.Format("Requested service {0} was not found", serviceType.FullName)); } else { NTrace.Info(string.Format("Request for service {0} satisfied by {1}", serviceType.Name, theService.GetType().Name)); } return(theService); }
public void Start() { NTrace.Info("Starting"); this.channel = ServerUtilities.GetTcpChannel(); NTrace.Debug("Acquired Tcp Channel"); try { this.agency = (TestAgency)Activator.GetObject(typeof(TestAgency), agencyUrl); NTrace.DebugFormat("Connected to TestAgency at {0}", agencyUrl); } catch (Exception ex) { NTrace.ErrorFormat("Unable to connect to test agency at {0}", agencyUrl); NTrace.Error(ex.Message); } try { this.agency.Register(this, ProcessId); NTrace.Debug("Registered with TestAgency"); } catch (Exception ex) { NTrace.Error("Failed to register with TestAgency", ex); } }
private Assembly Load(string path) { Assembly assembly = null; // Change currentDirectory in case assembly references unmanaged dlls using (new DirectorySwapper(Path.GetDirectoryName(path))) { // Throws if this isn't a managed assembly or if it was built // with a later version of the same assembly. AssemblyName.GetAssemblyName(Path.GetFileName(path)); // TODO: Figure out why we can't load using the assembly name // in all cases. Might be a problem with the tests themselves. assembly = Assembly.Load(Path.GetFileNameWithoutExtension(path)); if (assembly != null) { CoreExtensions.Host.InstallAdhocExtensions(assembly); } NTrace.Info("Loaded assembly " + assembly.FullName, "'TestAssemblyBuilder'"); return(assembly); } }
public void InitializeServices() { foreach (IService service in services) { NTrace.Info("Initializing " + service.GetType().Name); service.InitializeService(); } }
public void Stop() { NTrace.Info("Stopping"); lock ( theLock ) { if (this.channel != null) { ChannelServices.UnregisterChannel(this.channel); } Monitor.PulseAll(theLock); } }
public static int Main(string[] args) { NTrace.Info("Starting NUnit GUI"); GuiOptions guiOptions = new GuiOptions(args); GuiAttachedConsole attachedConsole = null; if (guiOptions.console) { attachedConsole = new GuiAttachedConsole(); } if (!guiOptions.Validate() || guiOptions.help) { string message = guiOptions.GetHelpText(); UserMessage.DisplayFailure(message, "Help Syntax"); return(2); } if (guiOptions.cleanup) { DomainManager.DeleteShadowCopyPath(); return(0); } if (!guiOptions.NoArgs) { if (guiOptions.lang != null) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(guiOptions.lang); } } // Add Standard Services to ServiceManager ServiceManager.Services.AddService(new SettingsService()); ServiceManager.Services.AddService(new DomainManager()); ServiceManager.Services.AddService(new RecentFilesService()); ServiceManager.Services.AddService(new TestLoader(new GuiTestEventDispatcher())); ServiceManager.Services.AddService(new AddinRegistry()); ServiceManager.Services.AddService(new AddinManager()); ServiceManager.Services.AddService(new TestAgency()); // Initialize Services ServiceManager.Services.InitializeServices(); // Create container in order to allow ambient properties // to be shared across all top-level forms. AppContainer c = new AppContainer(); AmbientProperties ambient = new AmbientProperties(); c.Services.AddService(typeof(AmbientProperties), ambient); NUnitForm form = new NUnitForm(guiOptions); c.Add(form); try { Application.Run(form); } finally { ServiceManager.Services.StopAllServices(); } if (attachedConsole != null) { Console.WriteLine("Press Enter to exit"); Console.ReadLine(); attachedConsole.Close(); } NTrace.Info("Exiting NUnit GUI"); return(0); }
public static int Main(string[] args) { NTrace.Info("NUnit-console.exe starting"); ConsoleOptions options = new ConsoleOptions(args); if (!options.nologo) { WriteCopyright(); } if (options.help) { options.Help(); return(ConsoleUi.OK); } if (options.NoArgs) { Console.Error.WriteLine("fatal error: no inputs specified"); options.Help(); return(ConsoleUi.OK); } if (!options.Validate()) { foreach (string arg in options.InvalidArguments) { Console.Error.WriteLine("fatal error: invalid argument: {0}", arg); } options.Help(); return(ConsoleUi.INVALID_ARG); } // Add Standard Services to ServiceManager ServiceManager.Services.AddService(new SettingsService()); ServiceManager.Services.AddService(new DomainManager()); //ServiceManager.Services.AddService( new RecentFilesService() ); //ServiceManager.Services.AddService( new TestLoader() ); ServiceManager.Services.AddService(new AddinRegistry()); ServiceManager.Services.AddService(new AddinManager()); // TODO: Resolve conflict with gui testagency when running // console tests under the gui. //ServiceManager.Services.AddService( new TestAgency() ); // Initialize Services ServiceManager.Services.InitializeServices(); try { ConsoleUi consoleUi = new ConsoleUi(); return(consoleUi.Execute(options)); } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); return(ConsoleUi.FILE_NOT_FOUND); } catch (Exception ex) { Console.WriteLine("Unhandled Exception:\n{0}", ex.ToString()); return(ConsoleUi.UNEXPECTED_ERROR); } finally { if (options.wait) { Console.Out.WriteLine("\nHit <enter> key to continue"); Console.ReadLine(); } NTrace.Info("NUnit-console.exe terminating"); } }