コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: RobotBuilderTests.cs プロジェクト: troygizzi/mmbot
        public void WhenUnconfiguredBuildConstructsNewRobot()
        {
            var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All));
            var robot   = builder.Build();

            Assert.IsType <Robot>(robot);
        }
コード例 #3
0
ファイル: RobotTests.cs プロジェクト: troygizzi/mmbot
        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);
        }
コード例 #4
0
ファイル: RobotBuilderTests.cs プロジェクト: dcr25568/mmbot
 public void WhenUnconfiguredBuildConstructsNewRobot()
 {
     var builder = new RobotBuilder(new LoggerConfigurator(LogLevel.All));
     var robot = builder.Build();
     
     Assert.IsType<Robot>(robot);
 }
コード例 #5
0
ファイル: Initializer.cs プロジェクト: dcr25568/mmbot
        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;
        }
コード例 #6
0
ファイル: RobotBuilderTests.cs プロジェクト: troygizzi/mmbot
        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);
        }
コード例 #7
0
ファイル: RobotBuilderTests.cs プロジェクト: dcr25568/mmbot
        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);
        }
コード例 #8
0
ファイル: RobotBuilderTests.cs プロジェクト: troygizzi/mmbot
        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);
        }
コード例 #9
0
ファイル: RobotBuilderTests.cs プロジェクト: dcr25568/mmbot
        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);
        }
コード例 #10
0
ファイル: RobotBuilderTests.cs プロジェクト: dcr25568/mmbot
        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);
        }
コード例 #11
0
ファイル: RobotBuilderTests.cs プロジェクト: troygizzi/mmbot
        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);
        }
コード例 #12
0
ファイル: RobotBuilderTests.cs プロジェクト: dcr25568/mmbot
        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);
        }
コード例 #13
0
ファイル: RobotBuilderTests.cs プロジェクト: troygizzi/mmbot
        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);
        }
コード例 #14
0
ファイル: RobotTests.cs プロジェクト: dcr25568/mmbot
        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);
        }