コード例 #1
0
        private static async Task <Chat> GetChat(TestsFixture testsFixture, string collectionName)
        {
            Chat chat;

            if (int.TryParse(ConfigurationProvider.TestConfigurations.RegularGroupMemberId, out int userId))
            {
                chat = await testsFixture.BotClient.GetChatAsync(userId);
            }
            else
            {
                await testsFixture.UpdateReceiver.DiscardNewUpdatesAsync();

                string botUserName = testsFixture.BotUser.Username;
                await testsFixture.SendTestCollectionNotificationAsync(collectionName,
                                                                       $"No value is set for `{nameof(ConfigurationProvider.TestConfigurations.RegularGroupMemberId)}` " +
                                                                       $"in test settings. A non-admin chat member should send /test command in private chat with " +
                                                                       $"@{botUserName.Replace("_", @"\_")}."
                                                                       );

                chat = await testsFixture.GetChatFromTesterAsync(ChatType.Private);
            }

            if (chat.Username == null)
            {
                await testsFixture.SendTestCollectionNotificationAsync(collectionName,
                                                                       $"[{chat.FirstName}](tg://user?id={chat.Id}) doesn't have a username.\n" +
                                                                       "❎ Failing tests...");

                throw new ArgumentNullException(nameof(chat.Username), "Chat member doesn't have a username");
            }

            return(chat);
        }
コード例 #2
0
        private async Task <Chat> GetChat(string collectionName)
        {
            string chatId = ConfigurationProvider.TestConfigurations.ChannelChatId;

            if (chatId is not null)
            {
                return(await _testsFixture.BotClient.GetChatAsync(chatId));
            }

            await _testsFixture.UpdateReceiver.DiscardNewUpdatesAsync();

            string botUserName = _testsFixture.BotUser.GetSafeUsername();
            await _testsFixture.SendTestCollectionNotificationAsync(collectionName,
                                                                    "No channel is set in test settings. Tester should forward a message from a channel " +
                                                                    $"so bot can run tests there. @{botUserName} must be an admin in that channel."
                                                                    );

            return(await _testsFixture.GetChatFromTesterAsync(ChatType.Channel));
        }
コード例 #3
0
        private async Task <Chat> GetChat(string collectionName)
        {
            Chat chat;
            long?chatId = ConfigurationProvider.TestConfigurations.TesterPrivateChatId;

            if (chatId.HasValue)
            {
                chat = await _testsFixture.BotClient.GetChatAsync(chatId);
            }
            else
            {
                await _testsFixture.UpdateReceiver.DiscardNewUpdatesAsync();

                string botUserName = _testsFixture.BotUser.Username;
                await _testsFixture.SendTestCollectionNotificationAsync(collectionName,
                                                                        $"No value is set for `{nameof(ConfigurationProvider.TestConfigurations.TesterPrivateChatId)}` in test " +
                                                                        $"settings. Tester should send /test command in private chat with @{botUserName.Replace("_", @"\_")}."
                                                                        );

                chat = await _testsFixture.GetChatFromTesterAsync(ChatType.Private);
            }
            return(chat);
        }