public void Dispose() { UpdateReceiver.DiscardNewUpdatesAsync(CancellationToken).GetAwaiter().GetResult(); int passed = RunSummary.Total - RunSummary.Skipped - RunSummary.Skipped; BotClient.SendTextMessageAsync( SupergroupChat.Id, string.Format( Constants.TestExecutionResultMessageFormat, RunSummary.Total, passed, RunSummary.Skipped, RunSummary.Failed ), ParseMode.Markdown, cancellationToken: CancellationToken ).GetAwaiter().GetResult(); }
public async Task <Chat> GetChatFromAdminAsync() { bool IsMatch(Update u) => ( u.Message.Type == MessageType.Contact || u.Message.ForwardFrom?.Id != null ); var update = await UpdateReceiver .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message) .ContinueWith(t => t.Result.Single()); await UpdateReceiver.DiscardNewUpdatesAsync(); int userId = update.Message.Type == MessageType.Contact ? update.Message.Contact.UserId : update.Message.ForwardFrom.Id; return(await BotClient.GetChatAsync(userId)); }
public async Task <Chat> GetChatFromTesterAsync(ChatType chatType) { bool IsMatch(Update u) => ( u.Message.Chat.Type == chatType && u.Message.Text?.StartsWith("/test", StringComparison.OrdinalIgnoreCase) == true ) || ( ChatType.Channel == chatType && ChatType.Channel == u.Message.ForwardFromChat?.Type ); var update = await UpdateReceiver .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message) .ContinueWith(t => t.Result.Single()); await UpdateReceiver.DiscardNewUpdatesAsync(); return(chatType == ChatType.Channel ? update.Message.ForwardFromChat : update.Message.Chat); }
public async Task <Chat> GetChatFromTesterAsync(ChatType chatType, CancellationToken cancellationToken = default) { bool IsMatch(Update u) => ( u.Message.Chat.Type == chatType && u.Message.Text?.StartsWith("/test", StringComparison.OrdinalIgnoreCase) == true ) || ( ChatType.Channel == chatType && ChatType.Channel == u.Message.ForwardFromChat?.Type ); var updates = await UpdateReceiver .GetUpdatesAsync(IsMatch, updateTypes : UpdateType.Message, cancellationToken : cancellationToken); var update = updates.Single(); await UpdateReceiver.DiscardNewUpdatesAsync(cancellationToken); return(chatType == ChatType.Channel ? update.Message.ForwardFromChat : update.Message.Chat); }
public TestsFixture() { string apiToken = ConfigurationProvider.TestConfigurations.ApiToken; BotClient = new TelegramBotClient(apiToken); BotUser = BotClient.GetMeAsync().GetAwaiter().GetResult(); BotClient.DeleteWebhookAsync().GetAwaiter().GetResult(); AllowedUserNames = ConfigurationProvider.TestConfigurations.AllowedUserNamesArray; UpdateReceiver = new UpdateReceiver(BotClient, AllowedUserNames); string supergroupChatId = ConfigurationProvider.TestConfigurations.SuperGroupChatId; #region Validations if (string.IsNullOrWhiteSpace(supergroupChatId)) { UpdateReceiver.DiscardNewUpdatesAsync().GetAwaiter().GetResult(); SupergroupChat = GetChatFromTesterAsync(ChatType.Supergroup).GetAwaiter().GetResult(); } else { SupergroupChat = BotClient.GetChatAsync(supergroupChatId) .GetAwaiter().GetResult(); } #endregion BotClient.SendTextMessageAsync( SupergroupChat.Id, "```\nTest execution is starting...\n```", ParseMode.Markdown, cancellationToken: CancellationToken ).GetAwaiter().GetResult(); }