コード例 #1
0
        private async Task should_send_message(
            [Frozen] Mock <IConnectionFactory> connectionFactory,
            Mock <IChatClient> chatClient,
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            const string slackKey = "key-yay";

            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object, SlackKey = slackKey
            };
            await slackConnection.Initialise(connectionInfo);

            connectionFactory
            .Setup(x => x.CreateChatClient())
            .Returns(chatClient.Object);

            var message = new BotMessage
            {
                Text    = "some text",
                ChatHub = new SlackChatHub {
                    Id = "channel-id"
                },
                Attachments = new List <SlackAttachment>()
            };

            // when
            await slackConnection.Say(message);

            // then
            chatClient
            .Verify(x => x.PostMessage(slackKey, message.ChatHub.Id, message.Text, message.Attachments), Times.Once);
        }
コード例 #2
0
ファイル: SayTests.cs プロジェクト: liqdfire/SlackConnector
        public async Task should_say_something_on_channel()
        {
            // given
            var message = new BotMessage
            {
                Text    = "Test text for INT test",
                ChatHub = SlackConnection.ConnectedChannel(Config.Slack.TestChannel)
            };

            // when
            await SlackConnection.Say(message);

            // then
        }
コード例 #3
0
        private async Task should_throw_exception_given_null_chat_hub(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object
            };
            await slackConnection.Initialise(connectionInfo);

            // when
            var exception = await Assert.ThrowsAsync <MissingChannelException>(() => slackConnection.Say(new BotMessage {
                ChatHub = null
            }));

            // then
            exception.Message.ShouldBe("When calling the Say() method, the message parameter must have its ChatHub property set.");
        }
コード例 #4
0
        public async Task should_say_something_on_channel()
        {
            // given
            var message = new BotMessage
            {
                Text    = "Test text for INT test",
                ChatHub = SlackConnection.ConnectedChannel(Config.Slack.TestChannel)
            };

            // when
            await SlackConnection.Say(message);

            SlackConnection.OnMessageReceived += slackMessage =>
            {
                _output.WriteLine(slackMessage.Text);
                return(Task.CompletedTask);
            };

            // then
            //await Task.Delay(TimeSpan.FromMinutes(2));
        }
コード例 #5
0
        public async Task should_join_channel()
        {
            // given
            if (string.IsNullOrEmpty(Config.Slack.TestUserName))
            {
                throw new InvalidConfiguration("TestUserName is missing from config");
            }

            var users = await SlackConnection.GetUsers();

            string userId = users.First(x => x.Name.Equals(Config.Slack.TestUserName, StringComparison.InvariantCultureIgnoreCase)).Id;

            // when
            SlackChatHub result = await SlackConnection.JoinDirectMessageChannel(userId);

            // then
            result.ShouldNotBeNull();

            var dmChannel = SlackConnection.ConnectedDM($"@{Config.Slack.TestUserName}");

            dmChannel.ShouldNotBeNull();
            await SlackConnection.Say(new BotMessage { ChatHub = dmChannel, Text = "Wuzzup - testing in da haus" });
        }
コード例 #6
0
ファイル: SlackCore.cs プロジェクト: jarleli/Oppsyn
 public async Task SendMessage(BotMessage message)
 {
     _logger.Information($"Sending message '{message.Text.SafeSubstring(0, 90)}'");
     await SlackConnection.Say(message);
 }