public static async Task <Robot> StartBot(Options options) { if (options.Test && (options.ScriptFiles == null || !options.ScriptFiles.Any())) { Console.WriteLine("You need to specify at least one script file to test."); return(null); } var logConfig = CreateLogConfig(options); ConfigurePath(options, logConfig.GetLogger()); var builder = new RobotBuilder(logConfig).WithConfiguration(GetConfiguration(options)); if (!string.IsNullOrWhiteSpace(options.Name)) { builder.WithName(options.Name); } if (options.Test) { builder.DisableScriptDiscovery(); } if (!string.IsNullOrEmpty(options.WorkingDirectory)) { builder.UseWorkingDirectory(options.WorkingDirectory); } if (options.Watch) { builder.EnableScriptWatcher(); } Robot robot = null; try { robot = builder.Build(); if (robot == null) { return(null); } } catch (Exception e) { logConfig.GetLogger().Fatal("Could not build robot. Try installing the latest version of any mmbot packages (mmbot.jabbr, mmbot.slack etc) if there was a breaking change.", e); } await robot.Run().ContinueWith(t => { if (!t.IsFaulted) { Console.WriteLine(IntroText); Console.WriteLine((options.Test ? "The test console is ready. " : "mmbot is running. ") + "Press CTRL+C at any time to exit"); } }); return(robot); }
public void WhenUnconfiguredBuildConstructsNewRobot() { var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)); var robot = builder.Build(); Assert.IsType <Robot>(robot); }
public async Task WhenRobotIsReset_ScriptCleanupIsInvoked() { var loggerConfigurator = new LoggerConfigurator(LogLevel.All); var builder = new RobotBuilder(loggerConfigurator) .UseAdapter <StubAdapter>() .UseBrain <StubBrain>() .DisablePluginDiscovery() .DisableScriptDiscovery(); var scriptRunner = new ScriptRunner(loggerConfigurator.GetLogger()); var robot = builder .Build(c => c.Register <IScriptRunner>(scriptRunner)); scriptRunner.Initialize(robot); robot.LoadScript <StubEchoScript>(); bool isCleanedUp = false; using (scriptRunner.StartScriptProcessingSession(new ScriptSource("TestScript", string.Empty))) { robot.RegisterCleanup(() => isCleanedUp = true); } await robot.Reset(); Assert.True(isCleanedUp); }
public void WhenUnconfiguredBuildConstructsNewRobot() { var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)); var robot = builder.Build(); Assert.IsType<Robot>(robot); }
public static async Task<Robot> StartBot(Options options) { if (options.Test && (options.ScriptFiles == null || !options.ScriptFiles.Any())) { Console.WriteLine("You need to specify at least one script file to test."); return null; } var logConfig = CreateLogConfig(options); ConfigurePath(options, logConfig.GetLogger()); var builder = new RobotBuilder(logConfig).WithConfiguration(GetConfiguration(options)); if (!string.IsNullOrWhiteSpace(options.Name)) { builder.WithName(options.Name); } if (options.Test) { builder.DisableScriptDiscovery(); } if (!string.IsNullOrEmpty(options.WorkingDirectory)) { builder.UseWorkingDirectory(options.WorkingDirectory); } if (options.Watch) { builder.EnableScriptWatcher(); } Robot robot = null; try { robot = builder.Build(); } catch (Exception e) { logConfig.GetLogger().Fatal("Could not build robot. Try installing the latest version of any mmbot packages (mmbot.jabbr, mmbot.slack etc) if there was a breaking change.", e); } if (robot == null) { return null; } await robot.Run().ContinueWith(t => { if (!t.IsFaulted) { Console.WriteLine(IntroText); Console.WriteLine((options.Test ? "The test console is ready. " : "mmbot is running. ") + "Press CTRL+C at any time to exit"); } }); return robot; }
public void WhenNameNotDefinedBuildNamesNewRobotWithDefaultName() { string name = "mmbot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)); var robot = builder.Build(); Assert.IsType <Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenNameNotDefinedBuildNamesNewRobotWithDefaultName() { string name = "mmbot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)); var robot = builder.Build(); Assert.IsType<Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenWithNameCalledBuildNamesNewRobotWithName() { string name = "my-shiny-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithName(name); var robot = builder.Build(); Assert.IsType <Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenNameInConfigurationBuildNamesNewRobotFromConfiguration() { string name = "my-shiny-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithConfiguration(new Dictionary<string, string>{{"MMBOT_ROBOT_NAME", name}}); var robot = builder.Build(); Assert.IsType<Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenWithNameCalledBuildNamesNewRobotWithName() { string name = "my-shiny-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithName(name); var robot = builder.Build(); Assert.IsType<Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenNameInConfigurationBuildNamesNewRobotFromConfiguration() { string name = "my-shiny-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithConfiguration(new Dictionary <string, string> { { "MMBOT_ROBOT_NAME", name } }); var robot = builder.Build(); Assert.IsType <Robot>(robot); Assert.Equal(name, robot.Name); }
public void WhenNameInConfigurationAndWithNameCalledBuildNamesNewRobotWithName() { string withName = "my-shiny-robot"; string configuredName = "my-not-so-shint-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithName(withName) .WithConfiguration(new Dictionary<string, string> {{"MMBOT_ROBOT_NAME", configuredName}}); var robot = builder.Build(); Assert.IsType<Robot>(robot); Assert.Equal(withName, robot.Name); Assert.NotEqual(configuredName, robot.Name); }
public void WhenNameInConfigurationAndWithNameCalledBuildNamesNewRobotWithName() { string withName = "my-shiny-robot"; string configuredName = "my-not-so-shint-robot"; var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All)) .WithName(withName) .WithConfiguration(new Dictionary <string, string> { { "MMBOT_ROBOT_NAME", configuredName } }); var robot = builder.Build(); Assert.IsType <Robot>(robot); Assert.Equal(withName, robot.Name); Assert.NotEqual(configuredName, robot.Name); }
public async Task WhenRobotIsReset_ScriptCleanupIsInvoked() { var loggerConfigurator = new LoggerConfigurator(LogLevel.All); var builder = new RobotBuilder(loggerConfigurator) .UseAdapter<StubAdapter>() .UseBrain<StubBrain>() .DisablePluginDiscovery() .DisableScriptDiscovery(); var scriptRunner = new ScriptRunner(loggerConfigurator.GetLogger()); var robot = builder .Build(c => c.Register<IScriptRunner>(scriptRunner)); scriptRunner.Initialize(robot); robot.LoadScript<StubEchoScript>(); bool isCleanedUp = false; using(scriptRunner.StartScriptProcessingSession(new ScriptSource("TestScript", string.Empty))) { robot.RegisterCleanup(() => isCleanedUp = true); } await robot.Reset(); Assert.True(isCleanedUp); }