예제 #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
        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);
 }