Exemplo n.º 1
0
        async Task RunIrc(CancellationToken cancellationToken)
        {
            var firstBot = new ChatBot
            {
                ConnectionString     = Environment.GetEnvironmentVariable("TGS4_TEST_IRC_CONNECTION_STRING"),
                Enabled              = false,
                Name                 = "tgs4_integration_test",
                Provider             = ChatProvider.Irc,
                ReconnectionInterval = 1,
                ChannelLimit         = 1
            };

            var csb = new IrcConnectionStringBuilder(firstBot.ConnectionString);

            Assert.IsTrue(csb.Valid, $"Invalid IRC connection string: {firstBot.ConnectionString}");

            firstBot = await chatClient.Create(firstBot, cancellationToken);

            Assert.AreEqual(csb.ToString(), firstBot.ConnectionString);
            Assert.AreNotEqual(0, firstBot.Id);

            var bots = await chatClient.List(cancellationToken);

            Assert.AreEqual(firstBot.Id, bots.First(x => x.Provider.Value == ChatProvider.Irc).Id);

            var retrievedBot = await chatClient.GetId(firstBot, cancellationToken);

            Assert.AreEqual(firstBot.Id, retrievedBot.Id);

            firstBot.Enabled = true;
            var updatedBot = await chatClient.Update(firstBot, cancellationToken);

            Assert.AreEqual(true, updatedBot.Enabled);

            var channelId = Environment.GetEnvironmentVariable("TGS4_TEST_IRC_CHANNEL");

            firstBot.Channels = new List <ChatChannel>
            {
                new ChatChannel
                {
                    IsAdminChannel    = false,
                    IsUpdatesChannel  = true,
                    IsWatchdogChannel = true,
                    Tag        = "butt2",
                    IrcChannel = channelId
                }
            };

            updatedBot = await chatClient.Update(firstBot, cancellationToken);

            Assert.AreEqual(true, updatedBot.Enabled);
            Assert.IsNotNull(updatedBot.Channels);
            Assert.AreEqual(1, updatedBot.Channels.Count);
            Assert.AreEqual(false, updatedBot.Channels.First().IsAdminChannel);
            Assert.AreEqual(true, updatedBot.Channels.First().IsUpdatesChannel);
            Assert.AreEqual(true, updatedBot.Channels.First().IsWatchdogChannel);
            Assert.AreEqual("butt2", updatedBot.Channels.First().Tag);
            Assert.AreEqual(channelId, updatedBot.Channels.First().IrcChannel);
            Assert.IsNull(updatedBot.Channels.First().DiscordChannelId);
        }
        public void TestBasicParseAndBuild()
        {
            const string exampleString = "server;1234;nick;1;2;asdf";
            var          builder       = new IrcConnectionStringBuilder(exampleString);

            Assert.IsTrue(builder.Valid);
            Assert.AreEqual("server", builder.Address);
            Assert.AreEqual((ushort)1234, builder.Port);
            Assert.AreEqual("nick", builder.Nickname);
            Assert.IsTrue(builder.UseSsl.Value);
            Assert.AreEqual(IrcPasswordType.NickServ, builder.PasswordType);
            Assert.AreEqual("asdf", builder.Password);

            Assert.AreEqual(exampleString, builder.ToString());
        }