Ejemplo n.º 1
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "something-that-looks-like-a-slack-key";
            const string channel  = "channel-name";
            const string text     = "some-text-for-you";

            var expectedResponse = new StandardResponse();

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _chatClient.PostMessage(slackKey, channel, text, null);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH))
            .WithQueryParamValue("token", slackKey)
            .WithQueryParamValue("channel", channel)
            .WithQueryParamValue("text", text)
            .WithQueryParamValue("as_user", "true")
            .WithoutQueryParam("attachments")
            .Times(1);
        }
Ejemplo n.º 2
0
        public async Task should_call_expected_url_with_given_slack_key()
        {
            // given
            const string slackKey = "something-that-looks-like-a-slack-key";
            const string channel  = "channel-name";
            const string text     = "some-text-for-you";

            var expectedResponse = new DefaultStandardResponse();

            _httpTest.RespondWithJson(expectedResponse);

            // when
            await _chatClient.PostMessage(slackKey, channel, text, null);

            // then
            _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse)));
            _httpTest
            .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH))
            .WithRequestUrlEncoded(new
            {
                token      = slackKey,
                channel    = channel,
                text       = text,
                as_user    = "******",
                link_names = "true"
            })
            .Times(1);
        }
Ejemplo n.º 3
0
        public async Task should_update_message_with_flurl()
        {
            // given
            var config   = new ConfigReader().GetConfig();
            var client   = new FlurlChatClient(new ResponseVerifier());
            var response = await client.PostMessage(config.Slack.ApiToken,
                                                    config.Slack.TestChannel, "Kikoo");

            // when
            await client.Update(config.Slack.ApiToken,
                                response.Timestamp, response.Channel, "Kikoo lol");
        }
Ejemplo n.º 4
0
        public async Task should_send_message_blocks_with_flurl()
        {
            // given
            var config = new ConfigReader().GetConfig();
            var client = new FlurlChatClient(new ResponseVerifier());
            var blocks = this.CreateBlocks();

            // when
            var response = await client.PostMessage(config.Slack.ApiToken,
                                                    config.Slack.TestChannel, null, blocks : blocks);

            // then
            response.ShouldNotBeNull();
            response.Ok.ShouldBeTrue();
        }
Ejemplo n.º 5
0
        public async Task WhenSendingMessageThenServerReceive()
        {
            var port = GetRandomPort;

            using (var server = new SlackServer(port))
            {
                server.MockDefaultSendMessage();

                ClientConstants.SlackApiHost = $"http://localhost:{port}";

                var client = new FlurlChatClient(new ResponseVerifier());

                var channel  = "fake-channel";
                var text     = "This is a message for a test";
                var response = await client.PostMessage("fake-key", channel, text);

                Assert.Equal(channel, response.Channel);
                Assert.Equal(text, response.Message.Text);
            }
        }