public void DelegatesMessageProcessingToUnderlyingProcessor()
        {
            var underlying = new Mock <IMessageProcessor>();

            underlying.Setup(x => x.ProcessMessage(It.IsAny <Message>())).Returns(new Response("", ""));
            var feature = new BasicFeature("test", "test feature please ignore", "this is a test feature", underlying.Object);

            var commandParser = new Mock <ICommandParser>();
            var processor     = new FeatureMessageProcessor(commandParser.Object, feature);

            var message = new Message("a-channel", "a-user", "some random message text");
            var result  = processor.ProcessMessage(message).Responses.Single();

            underlying.Verify(x => x.ProcessMessage(message));
        }
Exemplo n.º 2
0
        public static async Task MainAsync(Configuration configuration, CancellationToken cancel)
        {
            var persistence      = new JsonFileKeyValueStore(new FileInfo(configuration.Get("db-file-location")));
            var gamesPersistence = new JsonFileKeyValueStore(new FileInfo(configuration.Get("games-db-location")));

            var slackApi = new SlackApi(configuration.Get("slack-api-key"));

            var slackRtm = await(ReconnectingSlackRealTimeMessaging.CreateAsync(
                                     async() => await slackApi.StartRtm()));
            var aliasList = GetAliasList(slackRtm.InstanceInfo.Users);

            var commandParser = new SlackCommandParser("scbot", slackRtm.InstanceInfo.BotId);

            var webClient = new WebClient();

            var features = new FeatureMessageProcessor(commandParser,
                                                       NoteProcessor.Create(commandParser, persistence),
                                                       //ZendeskTicketTracker.Create(commandParser, persistence, configuration),
                                                       RecordReplayTraceManagement.Create(commandParser),
                                                       SeatingPlans.Create(commandParser, webClient),
                                                       Webcams.Create(commandParser, configuration),
                                                       Silly.Create(commandParser, webClient),
                                                       Installers.Create(commandParser, webClient),
                                                       Polls.Create(commandParser),
                                                       RollBuildNumbers.Create(commandParser, configuration),
                                                       ReviewFactory.Create(commandParser, webClient, configuration),
                                                       LabelPrinting.Create(commandParser, webClient, configuration),
                                                       Jira.Create(commandParser),
                                                       CompareTeamEmails.Create(commandParser, configuration),
                                                       GamesProcessor.Create(commandParser, gamesPersistence, aliasList)
                                                       );

            var pasteBin = new HasteServerPasteBin(webClient, configuration.Get("haste-server-url"));

            var newChannelNotificationsChannel = configuration.GetWithDefault("new-channels-notification-channel", null);
            var newChannelProcessor            = GetNewChannelProcessor(newChannelNotificationsChannel);

            var bot = new Bot(
                new ErrorReportingMessageProcessor(
                    new ConcattingMessageProcessor(features),
                    pasteBin),
                newChannelProcessor);

            var handler = new SlackMessageHandler(bot, slackRtm.InstanceInfo.BotId);

            MainLoop(slackRtm, handler, slackApi, cancel);
        }
        public void ReturnsErrorIfSpecificHelpNotFound()
        {
            var underlying    = new Mock <IMessageProcessor>();
            var feature1      = new BasicFeature("test", "test feature please ignore", "this is a test feature", underlying.Object);
            var feature2      = new BasicFeature("test2", "test feature please ignore", "this is another test feature", underlying.Object);
            var commandParser = new Mock <ICommandParser>();

            commandParser.SetupTryGetCommand("help test3");

            var processor = new FeatureMessageProcessor(commandParser.Object, feature1, feature2);

            var message = new Message("a-channel", "a-user", "help test3");
            var result  = processor.ProcessMessage(message);

            Assert.AreEqual("Sorry, I don't know about 'test3'.", result.Responses.Single().Message);
            underlying.Verify(x => x.ProcessMessage(message), Times.Never);
        }
        public void ReturnsHelpTextForHelpCommand()
        {
            var underlying    = new Mock <IMessageProcessor>();
            var feature1      = new BasicFeature("test", "test feature please ignore", "this is a test feature", underlying.Object);
            var feature2      = new BasicFeature("test2", "test feature please ignore", "this is another test feature", underlying.Object);
            var commandParser = new Mock <ICommandParser>();

            commandParser.SetupTryGetCommand("help");

            var processor = new FeatureMessageProcessor(commandParser.Object, feature1, feature2);

            var message = new Message("a-channel", "a-user", "help");
            var result  = processor.ProcessMessage(message);

            Assert.AreEqual("*test*: test feature please ignore\n*test2*: test feature please ignore\n\nuse `help <feature>` for help on a specific feature",
                            result.Responses.Single().Message);
            underlying.Verify(x => x.ProcessMessage(message), Times.Never);
        }