Ejemplo n.º 1
0
        public async Task should_initialise_connection_with_websocket_and_return_expected_connection()
        {
            // given
            var handshakeResponse = new HandshakeResponse
            {
                Ok           = true,
                WebSocketUrl = _webSocketUrl
            };

            _handshakeClient
            .Setup(x => x.FirmShake(_slackKey))
            .ReturnsAsync(handshakeResponse);

            var expectedConnection = new Mock <ISlackConnection>().Object;

            _slackConnectionFactory
            .Setup(x => x.Create(It.IsAny <ConnectionInformation>()))
            .ReturnsAsync(expectedConnection);

            // when
            var result = await _slackConnector.Connect(_slackKey);

            // then
            result.ShouldBe(expectedConnection);

            _slackConnectionFactory
            .Verify(x => x.Create(It.Is((ConnectionInformation p) => p.WebSocket == _webSocketClient.Object)), Times.Once);
            _connectionFactory.Verify(x => x.CreateWebSocketClient(_webSocketUrl, null));
        }
Ejemplo n.º 2
0
        public async Task should_say_something_on_channel_then_delete_it()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = await slackConnector.Connect(config.Slack.ApiToken);

            var message = new BotMessage
            {
                Text    = "Test delete this text for INT test",
                ChatHub = connection.ConnectedChannel(config.Slack.TestChannel)
            };

            // when
            var messageResponse = await connection.Say(message);

            // Wait for 2 seconds for dramatic pause
            await Task.Delay(2000);

            // Now delete
            var deleteResponse = await connection.DeleteMessage(messageResponse.Channel, messageResponse.Message.TimeStamp);

            // then
            Assert.That(deleteResponse.Channel == message.ChatHub.Id, Is.True);
        }
Ejemplo n.º 3
0
        public async Task should_join_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            if (string.IsNullOrEmpty(config.Slack.TestUserName))
            {
                Assert.Inconclusive("TestUserName is missing from config");
            }

            var slackConnector = new SlackConnector();
            var connection     = await slackConnector.Connect(config.Slack.ApiToken);

            var users = await connection.GetUsers();

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

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

            // then
            Assert.That(result, Is.Not.Null);

            var dmChannel = connection.ConnectedDM($"@{config.Slack.TestUserName}");

            Assert.That(dmChannel, Is.Not.Null);
            await connection.Say(new BotMessage { ChatHub = dmChannel, Text = "Wuzzup - testing in da haus" });
        }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     Console.Title = "IZSlackBot";
     EnviromentLoader.Load();
     AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnClose);
     SlackConnector.Connect();
     Console.ReadLine();
 }
Ejemplo n.º 5
0
        protected IntegrationTest()
        {
            Config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();

            SlackConnection = Task.Run(() => slackConnector.Connect(Config.Slack.ApiToken))
                              .GetAwaiter()
                              .GetResult();
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            _filePath = Path.GetTempFileName();
            File.WriteAllText(_filePath, EmbeddedResourceFileReader.ReadEmbeddedFileAsText("UploadTest.txt"));

            _config = new ConfigReader().GetConfig();
            var slackConnector = new SlackConnector();

            _slackConnection = slackConnector.Connect(_config.Slack.ApiToken).Result;
        }
Ejemplo n.º 7
0
        public void should_join_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = slackConnector.Connect(config.Slack.ApiToken).Result;

            // when
            SlackChatHub result = connection.JoinDirectMessageChannel(config.Slack.TestUserId).Result;

            // then
            Assert.That(result, Is.Not.Null);
        }
        public void should_send_typing_indicator()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection = slackConnector.Connect(config.Slack.ApiToken).Result;
            SlackChatHub channel = connection.ConnectedChannels().First(x => x.Name.Equals("#general", StringComparison.InvariantCultureIgnoreCase));

            // when
            connection.IndicateTyping(channel).Wait();

            // then
        }
        public void should_connect_and_stuff()
        {
            // given
            var config = new ConfigReader().GetConfig();
            var slackConnector = new SlackConnector();

            // when
            var connection = slackConnector.Connect(config.Slack.ApiToken).Result;
            connection.OnDisconnect += SlackConnector_OnDisconnect;
            connection.OnMessageReceived += SlackConnectorOnOnMessageReceived;

            // then
            Assert.That(connection.IsConnected, Is.True);
        }
Ejemplo n.º 10
0
            public async void should_connect_and_get_users()
            {
                // given
                var config         = new ConfigReader().GetConfig();
                var slackConnector = new SlackConnector();

                // when
                var connection = await slackConnector.Connect(config.Slack.ApiToken);

                var users = await connection.GetUsers();

                // then
                Assert.That(users.Any(u => u.Online == true), Is.True);
            }
Ejemplo n.º 11
0
            public async void should_connect_and_get_channels()
            {
                // given
                var config         = new ConfigReader().GetConfig();
                var slackConnector = new SlackConnector();

                // when
                var connection = await slackConnector.Connect(config.Slack.ApiToken);

                var channels = await connection.GetChannels();

                // then
                Assert.That(channels.Any(), Is.True);
            }
Ejemplo n.º 12
0
        public void should_send_typing_indicator()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var          slackConnector = new SlackConnector();
            var          connection     = slackConnector.Connect(config.Slack.ApiToken).Result;
            SlackChatHub channel        = connection.ConnectedChannels().First(x => x.Name.Equals("#-lobby-", StringComparison.InvariantCultureIgnoreCase));

            // when
            connection.IndicateTyping(channel).Wait();

            // then
        }
        public void should_send_typing_indicator()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var          slackConnector = new SlackConnector();
            var          connection     = slackConnector.Connect(config.Slack.ApiToken).Result;
            SlackChatHub channel        = connection.ConnectedChannel(config.Slack.TestChannel);

            // when
            connection.IndicateTyping(channel).Wait();

            // then
        }
Ejemplo n.º 14
0
            public async void should_connect_and_get_users()
            {
                // given
                var config = new ConfigReader().GetConfig();

                var slackConnector = new SlackConnector();

                // when
                var connection = await slackConnector.Connect(config.Slack.ApiToken);
                var users = await connection.GetUsers();

                // then
                Assert.That(users.Any(u => u.Online == true), Is.True);
            }
Ejemplo n.º 15
0
            public async void should_connect_and_get_channels()
            {
                // given
                var config = new ConfigReader().GetConfig();

                var slackConnector = new SlackConnector();

                // when
                var connection = await slackConnector.Connect(config.Slack.ApiToken);
                var channels = await connection.GetChannels();

                // then
                Assert.That(channels.Any(), Is.True);
            }
Ejemplo n.º 16
0
        public void should_join_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection = slackConnector.Connect(config.Slack.ApiToken).Result;

            // when
            SlackChatHub result = connection.JoinDirectMessageChannel(config.Slack.TestUserId).Result;

            // then
            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 17
0
        public async Task should_not_contain_archived_channels()
        {
            // given
            var handshakeResponse = new HandshakeResponse
            {
                Ok       = true,
                Channels = new[]
                {
                    new Channel
                    {
                        Id         = "Id1",
                        Name       = "Name1",
                        IsArchived = true,
                        IsMember   = true //TODO: Need to do self things
                    },
                    new Channel
                    {
                        Id         = "Id2",
                        Name       = "Name2",
                        IsArchived = true,
                        IsMember   = true //TODO: Need to do self things
                    },
                }
            };

            _handshakeClient
            .Setup(x => x.FirmShake(It.IsAny <string>()))
            .ReturnsAsync(handshakeResponse);

            // when
            await _slackConnector.Connect("something");

            // then
            _slackConnectionFactory
            .Verify(x => x.Create(It.Is((ConnectionInformation p) => p.SlackChatHubs.Count == 0)), Times.Once);
        }
Ejemplo n.º 18
0
        public async Task should_send_typing_indicator()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = await slackConnector.Connect(config.Slack.ApiToken);

            SlackChatHub channel = connection.ConnectedChannel(config.Slack.TestChannel);

            // when
            await connection.IndicateTyping(channel);

            // then
        }
        public void should_connect_and_stuff()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();

            // when
            _slackConnection = slackConnector.Connect(config.Slack.ApiToken).Result;
            _slackConnection.OnDisconnect      += SlackConnector_OnDisconnect;
            _slackConnection.OnMessageReceived += SlackConnectorOnMessageReceived;

            // then
            Assert.That(_slackConnection.IsConnected, Is.True);
        }
Ejemplo n.º 20
0
        public void should_say_something_on_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = slackConnector.Connect(config.Slack.ApiToken).Result;
            var message        = new BotMessage
            {
                Text    = "Test text for INT test",
                ChatHub = connection.ConnectedChannel(config.Slack.TestChannel)
            };

            // when
            connection.Say(message).Wait();

            // then
        }
Ejemplo n.º 21
0
        public void should_say_something_on_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();
            
            var slackConnector = new SlackConnector();
            var connection = slackConnector.Connect(config.Slack.ApiToken).Result;
            var message = new BotMessage
            {
                Text = "Test text for INT test",
                ChatHub = connection.ConnectedChannels().First(x => x.Name.Equals("#general", StringComparison.InvariantCultureIgnoreCase))
            };
            
            // when
            connection.Say(message).Wait();

            // then
        }
Ejemplo n.º 22
0
        public void should_say_something_on_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = slackConnector.Connect(config.Slack.ApiToken).Result;
            var message        = new BotMessage
            {
                Text    = "Test text for INT test",
                ChatHub = connection.ConnectedChannels().First(x => x.Name.Equals("#general", StringComparison.InvariantCultureIgnoreCase))
            };

            // when
            connection.Say(message).Wait();

            // then
        }
Ejemplo n.º 23
0
        public async Task should_say_something_on_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = await slackConnector.Connect(config.Slack.ApiToken);

            var message = new BotMessage
            {
                Text    = "Test text for INT test",
                ChatHub = connection.ConnectedChannel(config.Slack.TestChannel)
            };

            // when
            var response = await connection.Say(message);

            // then
            Assert.That(string.CompareOrdinal(response.Message.Text, message.Text) == 0, Is.True);
        }
Ejemplo n.º 24
0
        public void should_say_something_complex_on_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            var slackConnector = new SlackConnector();
            var connection     = slackConnector.Connect(config.Slack.ApiToken).Result;
            var message        = new BotMessage
            {
                Text    = "Test Text for COMPLEX messages",
                Name    = "Jeffery Bot",
                Icon    = "http://lorempixel.com/128/128/cats/",
                ChatHub = connection.ConnectedChannels().First(x => x.Name.Equals("#general", StringComparison.InvariantCultureIgnoreCase))
            };

            // when
            connection.Say(message).Wait();

            // then
        }
Ejemplo n.º 25
0
        public void should_join_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();
            if (string.IsNullOrEmpty(config.Slack.TestUserId))
            {
                Assert.Inconclusive("TestUserId is missing from config");
            }

            var slackConnector = new SlackConnector();
            var connection = slackConnector.Connect(config.Slack.ApiToken).Result;

            // when
            SlackChatHub result = connection.JoinDirectMessageChannel(config.Slack.TestUserId).Result;

            // then
            Assert.That(result, Is.Not.Null);

            List<SlackChatHub> dms = connection.ConnectedDMs().ToList();
            Assert.That(dms.Count, Is.GreaterThan(1));
        }
Ejemplo n.º 26
0
        public void should_join_channel()
        {
            // given
            var config = new ConfigReader().GetConfig();

            if (string.IsNullOrEmpty(config.Slack.TestUserId))
            {
                Assert.Inconclusive("TestUserId is missing from config");
            }

            var slackConnector = new SlackConnector();
            var connection     = slackConnector.Connect(config.Slack.ApiToken).Result;

            // when
            SlackChatHub result = connection.JoinDirectMessageChannel(config.Slack.TestUserId).Result;

            // then
            Assert.That(result, Is.Not.Null);

            List <SlackChatHub> dms = connection.ConnectedDMs().ToList();

            Assert.That(dms.Count, Is.GreaterThan(1));
        }
Ejemplo n.º 27
0
 public static void ClassInit(TestContext testContext)
 {
     EnviromentLoader.Load();
     SlackConnector.Connect();
 }