public async Task SendMessageTest_ReplyToLastMessage()
        {
            var client = new TelegramBot("161652985:AAHg3nbjt1AduvFzRisQWMsk8ooWl6flx6I");
            var getUpdates = await client.GetUpdates();

            if (getUpdates.Count > 0)
            {
                string text = "SendMessageTest_ReplyToLastMessage";
                var msg = await client.SendMessage(getUpdates[0].Message.Chat.Id, text, false, getUpdates[0].Message.MessageId, null);
                Assert.AreEqual(text, msg.Text);
            }
            Assert.IsNotNull(getUpdates);
        }
        public async Task GetUpdatesTest()
        {
            var client = new TelegramBot("161652985:AAHg3nbjt1AduvFzRisQWMsk8ooWl6flx6I");
            var getUpdates = await client.GetUpdates();

            var ar = getUpdates.ToArray();

            foreach (var a in ar)
            {
                Console.WriteLine("Update id is: " + a.UpdateId);
            }

            Assert.IsNotNull(getUpdates);
        }
Exemple #3
0
        public void Setup()
        {
            string        token         = null;
            DirectoryInfo documentsPath = null;
            string        json          = File.ReadAllText("testobjects.json");

            _testobjects = JsonConvert.DeserializeObject <TestObjects>(json);

            try
            {
                documentsPath = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                var fileInfo = documentsPath.GetFiles("*.testtoken").First();
                token = File.ReadAllText(fileInfo.FullName).Trim();
                _b    = TelegramBot.GetBot(token, true);
                var updates = _b.GetUpdates(true);
                _testMessage     = (from u in updates where u.Message != null select u.Message).First();
                _testChannelPost = (from u in updates where u.ChannelPost != null select u.ChannelPost).First();
            }
            catch
            {
                throw new Exception($"You must first (A) set up a test bot for integration testing (B) make sure that there is a *.testtoken file containing the bots token in {documentsPath} (C) The bot must have at least one unconsumed message in a group (D) The bot must have at least one unconsumed message in a channel");
            }
        }
        public async Task ForwardMessage()
        {
            var client = new TelegramBot("161652985:AAHg3nbjt1AduvFzRisQWMsk8ooWl6flx6I");
            var getUpdates = await client.GetUpdates();

            if (getUpdates.Count > 0)
            {
                var msg = await client.ForwardMessage(getUpdates[0].Message.Chat.Id, getUpdates[0].Message.Chat.Id, getUpdates[0].Message.MessageId);
                Assert.AreEqual(getUpdates[0].Message.Text, msg.Text);
            }
            Assert.IsNotNull(getUpdates);
        }