Пример #1
0
        public void ShouldContainSerializedMessage()
        {
            //arrange
            const string hookUrl            = "https://hooks.slack.com/invalid";
            SlackMessage postedMessage      = null;
            var          httpMessageHandler = GetMockHttpMessageHandler(callback: (req, token) =>
            {
                var json      = req.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                postedMessage = SlackClient.DeserializeObject(json);
            });

            var httpClient   = new HttpClient(httpMessageHandler.Object, false);
            var client       = new SlackClient(hookUrl, httpClient: httpClient);
            var slackMessage = GetSlackMessage();

            //act
            client.Post(slackMessage);

            //assert
            Assert.NotNull(postedMessage);
            Assert.Equal(slackMessage.Text, postedMessage.Text);
            Assert.Equal(slackMessage.Channel, postedMessage.Channel);
            Assert.Equal(slackMessage.Username, postedMessage.Username);
            Assert.Equal(slackMessage.IconEmoji, postedMessage.IconEmoji);
        }
Пример #2
0
        public void ShouldPostToMultipleChannels()
        {
            //arrange
            const string hookUrl            = "https://hooks.slack.com/invalid";
            var          channelsPostedTo   = new List <string>();
            var          httpMessageHandler = GetMockHttpMessageHandler(callback: (req, token) =>
            {
                var json          = req.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                var postedMessage = SlackClient.DeserializeObject(json);
                channelsPostedTo.Add(postedMessage.Channel);
            });

            var httpClient       = new HttpClient(httpMessageHandler.Object, false);
            var client           = new SlackClient(hookUrl, httpClient: httpClient);
            var slackMessage     = GetSlackMessage();
            var channelsToPostTo = new List <string> {
                "#test1", "#test2", "test3"
            };

            //act
            client.PostToChannels(slackMessage, channelsToPostTo);

            //assert
            Assert.Equal(channelsToPostTo.Count, channelsPostedTo.Count);
            foreach (var c in channelsToPostTo)
            {
                Assert.Contains(c, channelsPostedTo);
            }
        }