Exemplo n.º 1
0
        public TestsFixture()
        {
            string apiToken = ConfigurationProvider.TestConfigurations.ApiToken;

            BotClient = new TelegramBotClient(apiToken);

            BotClient.DeleteWebhookAsync().Wait();

            AllowedUserNames = ConfigurationProvider.TestConfigurations.AllowedUserNamesArray;
            UpdateReceiver   = new UpdateReceiver(BotClient, AllowedUserNames);

            string superGroupChatId = ConfigurationProvider.TestConfigurations.SuperGroupChatId;

            #region Validations

            if (string.IsNullOrWhiteSpace(superGroupChatId))
            {
                UpdateReceiver.DiscardNewUpdatesAsync().Wait();
                SuperGroupChatId = GetChatIdFromTesterAsync(ChatType.Supergroup).Result;
            }
            else
            {
                SuperGroupChatId = superGroupChatId;
            }

            #endregion

            var source = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            BotClient.SendTextMessageAsync(SuperGroupChatId,
                                           "```\nTest execution is starting...\n```",
                                           ParseMode.Markdown,
                                           cancellationToken: source.Token)
            .Wait(source.Token);
        }
Exemplo n.º 2
0
        public async Task <ChatId> GetChatIdFromTesterAsync(ChatType chatType)
        {
            var update = (await UpdateReceiver.GetUpdatesAsync(u =>
                                                               u.Message.Text?.StartsWith("/test", StringComparison.OrdinalIgnoreCase) == true &&
                                                               u.Message.Chat.Type == chatType,
                                                               updateTypes: UpdateType.MessageUpdate)).Single();

            await UpdateReceiver.DiscardNewUpdatesAsync();

            ChatId chatid = update.Message.Chat.Id;

            return(chatid);
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            var source = new CancellationTokenSource(TimeSpan.FromSeconds(15));

            UpdateReceiver.DiscardNewUpdatesAsync(source.Token).Wait(source.Token);

            source = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            BotClient.SendTextMessageAsync(SuperGroupChatId,
                                           "```\nTest execution is finished.\n```",
                                           ParseMode.Markdown,
                                           cancellationToken: source.Token)
            .Wait(source.Token);
        }