public void ForceBuildCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.Project = "test"; Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer)); var projectConstraint = new ProjectRequestConstraint { ProjectName = "test" }; mockCruiseServer.ExpectAndReturn("ForceBuild", new Response { Result = ResponseResult.Success }, projectConstraint); mockCruiseServer.ExpectAndReturn("Stop", new Response { Result = ResponseResult.Success }, projectConstraint); mockCruiseServer.Expect("WaitForExit", projectConstraint); Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, consoleArgs.UseRemoting, consoleArgs.ConfigFile); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run(); mockCruiseServer.Verify(); }
/// <summary> /// Start the application. /// </summary> /// <param name="args"></param> /// <returns></returns> public int Run(string[] args, bool usesShadowCopying) { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); List <string> extra = new List <string>(); OptionSet opts = new OptionSet(); opts.Add("h|?|help", "display this help screen", delegate(string v) { consoleArgs.ShowHelp = v != null; }) .Add("c|config=", "the configuration file to use (defaults to ccnet.conf)", delegate(string v) { consoleArgs.ConfigFile = v; }) .Add("r|remoting=", "turn remoting on/off (defaults to on)", delegate(string v) { consoleArgs.UseRemoting = v == "on"; }) .Add("p|project=", "the project to integrate (???)", delegate(string v) { consoleArgs.Project = v; }) .Add("v|validate", "validate the configuration file and exit", delegate(string v) { consoleArgs.ValidateConfigOnly = v != null; }) .Add("l|logging=", "turn logging on/off (defaults to on)", delegate(string v) { consoleArgs.Logging = v == "on"; }) .Add("e|errorpause=", "turn pause on error on/off (defaults to on)", delegate(string v) { consoleArgs.PauseOnError = v == "on"; }); try { extra = opts.Parse(args); } catch (OptionException e) { System.Console.WriteLine(e.Message); System.Console.WriteLine(e.StackTrace); return(1); } if (consoleArgs.ShowHelp) { DisplayHelp(opts); return(0); } try { runner = new ConsoleRunner(consoleArgs, new CruiseServerFactory()); if (!usesShadowCopying) { Log.Warning("Shadow-copying has been turned off - hot-swapping will not work!"); } runner.Run(); return(0); } catch (Exception ex) { Log.Error(ex); if (consoleArgs.PauseOnError) { System.Console.WriteLine("An unexpected error has caused the console to crash, please press any key to continue..."); System.Console.ReadKey(); } return(1); } finally { runner = null; } }
private void StartConsoleRunner(bool usesShadowCopying, ConsoleRunnerArguments consoleArgs) { runner = new ConsoleRunner(consoleArgs, new CruiseServerFactory()); if (!usesShadowCopying) { Log.Warning("Shadow-copying has been turned off - hot-swapping will not work!"); } runner.Run(); }
/// <summary> /// Start the application. /// </summary> /// <param name="args"></param> /// <returns></returns> public int Run(string[] args, bool usesShadowCopying) { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); if (consoleArgs.ShowHelp) { DisplayHelp(GetPopulatedOptionSet(consoleArgs)); return(0); } return(SetUpConsoleRunner(usesShadowCopying, consoleArgs)); }
public void TestDefaultArguments() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); Assert.AreEqual(true, consoleArgs.UseRemoting); Assert.IsNull(consoleArgs.Project); Assert.AreEqual(ConsoleRunnerArguments.DEFAULT_CONFIG_PATH, consoleArgs.ConfigFile); Assert.AreEqual(false, consoleArgs.ValidateConfigOnly); Assert.AreEqual(true, consoleArgs.Logging); Assert.AreEqual(true, consoleArgs.PauseOnError); Assert.AreEqual(false, consoleArgs.ShowHelp); }
private OptionSet GetPopulatedOptionSet(ConsoleRunnerArguments consoleArgs) { OptionSet opts = new OptionSet(); opts.Add("h|?|help", "display this help screen", delegate(string v) { consoleArgs.ShowHelp = v != null; }) .Add("c|config=", "the configuration file to use (defaults to ccnet.conf)", delegate(string v) { consoleArgs.ConfigFile = v; }) .Add("r|remoting=", "turn remoting on/off (defaults to on)", delegate(string v) { consoleArgs.UseRemoting = v == "on"; }) .Add("p|project=", "the project to integrate (???)", delegate(string v) { consoleArgs.Project = v; }) .Add("v|validate", "validate the configuration file and exit", delegate(string v) { consoleArgs.ValidateConfigOnly = v != null; }) .Add("l|logging=", "turn logging on/off (defaults to on)", delegate(string v) { consoleArgs.Logging = v == "on"; }) .Add("e|errorpause=", "turn pause on error on/off (defaults to on)", delegate(string v) { consoleArgs.PauseOnError = v == "on"; }); return(opts); }
public void ValidateConfigFileShouldNotStartServer() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.ValidateConfigOnly = true; var mockCruiseServer = new Mock <ICruiseServer>(); var mockCruiseServerFactory = new Mock <ICruiseServerFactory>(); mockCruiseServerFactory.Setup(factory => factory.Create(false, consoleArgs.ConfigFile)).Returns(mockCruiseServer.Object).Verifiable(); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.Object).Run(); mockCruiseServer.Verify(); }
public void StartCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); var mockCruiseServer = new Mock <ICruiseServer>(); mockCruiseServer.Setup(server => server.Start()).Verifiable(); mockCruiseServer.Setup(server => server.WaitForExit()).Verifiable(); var mockCruiseServerFactory = new Mock <ICruiseServerFactory>(); mockCruiseServerFactory.Setup(factory => factory.Create(consoleArgs.UseRemoting, consoleArgs.ConfigFile)).Returns(mockCruiseServer.Object).Verifiable(); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.Object).Run(); mockCruiseServer.Verify(); }
public void StartCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer)); mockCruiseServer.Expect("Start"); mockCruiseServer.Expect("WaitForExit"); Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, consoleArgs.UseRemoting, consoleArgs.ConfigFile); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run(); mockCruiseServer.Verify(); }
public void ValidateConfigFileShouldNotStartServer() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.ValidateConfigOnly = true; Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer)); Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, false, consoleArgs.ConfigFile); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run(); mockCruiseServer.Verify(); }
private int SetUpConsoleRunner(bool usesShadowCopying, ConsoleRunnerArguments consoleArgs) { try { StartConsoleRunner(usesShadowCopying, consoleArgs); return(0); } catch (Exception ex) { HandleAppRunnerException(consoleArgs.PauseOnError, ex); return(1); } finally { runner = null; } }
public void ShowHelp() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.UseRemoting = true; consoleArgs.ShowHelp = true; var mockCruiseServerFactory = new Mock <ICruiseServerFactory>(); ConsoleRunner runner = new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.Object); runner.Run(); // FIXME: should we care for the usage text and the logging implementation? // If yes read it from the embedded resource //Assert.AreEqual(1, listener.Traces.Count); //Assert.IsTrue(listener.Traces[0].ToString().IndexOf(ConsoleRunnerArguments.Usage) > 0, "Wrong message was logged."); mockCruiseServerFactory.Verify(); mockCruiseServerFactory.VerifyNoOtherCalls(); }
public void ShowHelp() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.UseRemoting = true; consoleArgs.ShowHelp = true; Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory)); mockCruiseServerFactory.ExpectNoCall("Create", typeof(bool), typeof(string)); ConsoleRunner runner = new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance); runner.Run(); // FIXME: should we care for the usage text and the logging implementation? // If yes read it from the embedded resource //Assert.AreEqual(1, listener.Traces.Count); //Assert.IsTrue(listener.Traces[0].ToString().IndexOf(ConsoleRunnerArguments.Usage) > 0, "Wrong message was logged."); mockCruiseServerFactory.Verify(); }
public void ForceBuildCruiseServerProject() { ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments(); consoleArgs.Project = "test"; var mockCruiseServer = new Mock <ICruiseServer>(); mockCruiseServer.Setup(server => server.ForceBuild(It.Is <ProjectRequest>(_request => _request.ProjectName == "test"))).Returns(new Response { Result = ResponseResult.Success }).Verifiable(); mockCruiseServer.Setup(server => server.Stop(It.Is <ProjectRequest>(_request => _request.ProjectName == "test"))).Returns(new Response { Result = ResponseResult.Success }).Verifiable(); mockCruiseServer.Setup(server => server.WaitForExit(It.Is <ProjectRequest>(_request => _request.ProjectName == "test"))).Verifiable(); var mockCruiseServerFactory = new Mock <ICruiseServerFactory>(); mockCruiseServerFactory.Setup(factory => factory.Create(consoleArgs.UseRemoting, consoleArgs.ConfigFile)).Returns(mockCruiseServer.Object).Verifiable(); new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.Object).Run(); mockCruiseServer.Verify(); }
/// <summary> /// Starts the actual application. /// </summary> /// <param name="args">The arguments for the application.</param> /// <param name="usesShadowCopying">A flag indicating whether shadow copying should be used.</param> /// <returns> /// The return code for the application. /// </returns> public int Run(string[] args, bool usesShadowCopying) { // Parse the command line arguments var webOptions = new WebApiOptions(); var consoleArgs = new ConsoleRunnerArguments(); var opts = new OptionSet(); opts.Add("h|?|help", "display this help screen", v => consoleArgs.ShowHelp = v != null) .Add("c|config=", "the configuration file to use (defaults to ccnet.conf)", v => consoleArgs.ConfigFile = v) .Add("r|remoting=", "turn remoting on/off (defaults to on)", v => consoleArgs.UseRemoting = v == "on") .Add("p|project=", "the project to integrate (???)", v => consoleArgs.Project = v) .Add("v|validate", "validate the configuration file and exit", v => consoleArgs.ValidateConfigOnly = v != null) .Add("l|logging=", "turn logging on/off (defaults to on)", v => consoleArgs.Logging = v == "on") .Add("sc|shadowCopy=", "turn shadow copying on/off (defaults to on)", v => usesShadowCopying = v == "on") .Add("e|errorpause=", "turn pause on error on/off (defaults to on)", v => consoleArgs.PauseOnError = v == "on") .Add("we|webEndPoint=", "the base endpoint for the web API (default none)", v => webOptions.BaseEndpoint = v); try { opts.Parse(args); } catch (OptionException e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return(1); } // Display the help if (consoleArgs.ShowHelp) { DisplayHelp(opts); return(0); } ICruiseServerFactory factory = null; try { // Start the actual console runner if (webOptions.IsConfigured) { var apiFactory = new WebApiServerFactory(); apiFactory.StartWebApi(apiFactory, webOptions); factory = apiFactory; } else { factory = new CruiseServerFactory(); } runner = new ConsoleRunner(consoleArgs, factory); if (!usesShadowCopying) { Log.Warning("Shadow-copying has been turned off - hot-swapping will not work!"); } runner.Run(); return(0); } catch (Exception ex) { Log.Error(ex); if (consoleArgs.PauseOnError) { Console.WriteLine("An unexpected error has caused the console to crash"); Console.ReadKey(); } return(2); } finally { // Clean up runner = null; var disposable = factory as IDisposable; if (disposable != null) { disposable.Dispose(); } } }