Beispiel #1
0
        public void Login()
        {
            var auth = new TwitchAuthenticationDetails()
            {
                Username = Username,
                Channel  = Channel,
                Password = AuthToken.ToUnsecureString(),
            };

            try
            {
                var stream     = new NetworkStreamTcpAdapter("irc.chat.twitch.tv", 6667);
                var connection = new TwitchChannelConnection(stream, auth);
                var client     = new TwitchClient(connection);

                Save();

                IsBusy = true;
                client.Disconnected += DisplayLoginError;
                client.Connected    += () => {
                    IsBusy = false;
                    client.Disconnected -= DisplayLoginError;
                    (new ChatBotWindow(client)).Show();
                    Close();
                };
                client.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void TwitchChannelConnectionRequestsTwitchCaps()
        {
            using (var connection = new TwitchChannelConnection(stream, auth))
            {
                var lines = ConsumeStream();

                Assert.That(lines, Contains.Item("CAP REQ :twitch.tv/membership"));
                Assert.That(lines, Contains.Item("CAP REQ :twitch.tv/commands"));
                Assert.That(lines, Contains.Item("CAP REQ :twitch.tv/tags"));
            }
        }
        public void TwitchChannelConnectionSendsAuthDetails()
        {
            using (var connection = new TwitchChannelConnection(stream, auth))
            {
                var lines = ConsumeStream();

                Assert.That(lines, Contains.Item("PASS pass123"));
                Assert.That(lines, Contains.Item("NICK test"));
                Assert.That(lines, Contains.Item("JOIN #test"));
            }
        }
        public void TwitchChannelConnectionSendsMessagesCorrectly()
        {
            using (var connection = new TwitchChannelConnection(stream, auth))
            {
                connection.Send("MESSAGE ONE");
                connection.Send("MESSAGE {0}", "TWO");

                var lines = ConsumeStream();
                Assert.That(lines, Contains.Item("PRIVMSG #test :MESSAGE ONE"));
                Assert.That(lines, Contains.Item("PRIVMSG #test :MESSAGE TWO"));
            }
        }
        public void TwitchChannelConnectionFixesChannelName(string channel, string expectedChannel)
        {
            TwitchAuthenticationDetails validAuth = new TwitchAuthenticationDetails()
            {
                Username = "******",
                Password = "******",
                Channel  = channel
            };

            using (var connection = new TwitchChannelConnection(stream, validAuth))
                Assert.That(connection.Channel, Is.EqualTo(expectedChannel));
        }
        public void TwitchChannelConnectionThrowsNothingWithValidData(string name, string pass, string channel)
        {
            TwitchAuthenticationDetails validAuth = new TwitchAuthenticationDetails()
            {
                Username = name,
                Password = pass,
                Channel  = channel
            };

            Assert.That(() => {
                var c = new TwitchChannelConnection(stream, validAuth);
                c.Close();
            }, Throws.Nothing);
        }
        public void TwitchChannelConnectionsReadsFromBaseStream()
        {
            using (var connection = new TwitchChannelConnection(stream, auth))
            {
                var writer = new StreamWriter(memoryStream);

                string testMessage = ":[email protected] #test :test";
                writer.Write(testMessage + "\r\n");
                writer.Flush();

                // Offset including newline characters...
                long offset = testMessage.Length + 2;
                memoryStream.Seek(-offset, SeekOrigin.Current);

                Assert.That(connection.Read(), Is.EqualTo(testMessage));
            }
        }