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(); await testsFixture.SendTestCollectionNotificationAsync(collectionName, $"No value is set for `{nameof(ConfigurationProvider.TestConfigurations.RegularGroupMemberId)}` " + "in test settings.\n" + "An admin should forward a message from non-admin member or send his/her contact." ); chat = await testsFixture.GetChatFromAdminAsync(); } if (chat.Username is 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); }
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); }
public MessageReplyMarkupTestsFixture(TestsFixture testsFixture) { TestsFixture = testsFixture; var privateChatId = ConfigurationProvider.TestConfigurations.TesterPrivateChatId; if (privateChatId is null) { TestsFixture.SendTestCollectionNotificationAsync( Constants.TestCollections.MessageReplyMarkup, "A tester should send /test command in a private chat to begin") .Wait(); TestsFixture.UpdateReceiver.DiscardNewUpdatesAsync().Wait(); TesterPrivateChatId = TestsFixture.GetChatIdFromTesterAsync(ChatType.Private).Result; } else { TesterPrivateChatId = privateChatId; TestsFixture.SendTestCollectionNotificationAsync(Constants.TestCollections.MessageReplyMarkup, "All messages for this collection will be sent in private chat") .Wait(); TestsFixture.SendTestCollectionNotificationAsync(Constants.TestCollections.MessageReplyMarkup, chatid: TesterPrivateChatId) .Wait(); } }
public ChatMemberAdministrationTestFixture(TestsFixture testsFixture) { TestsFixture = testsFixture; bool isUserIdNull = string.IsNullOrWhiteSpace(ConfigurationProvider.TestConfigurations.RegularMemberUserId); bool isUserNameNull = string.IsNullOrWhiteSpace(ConfigurationProvider.TestConfigurations.RegularMemberUserName); bool isChatIdNull = string.IsNullOrWhiteSpace(ConfigurationProvider.TestConfigurations .RegularMemberPrivateChatId); // All must have values or all must be null if (!(isUserIdNull == isUserNameNull && isUserNameNull == isChatIdNull)) { throw new ArgumentException("All (or none) of Regular Chat Member configurations should be provided"); } bool configValuesExist = !isUserIdNull; if (configValuesExist) { RegularMemberUserId = int.Parse(ConfigurationProvider.TestConfigurations.RegularMemberUserId); RegularMemberUserName = ConfigurationProvider.TestConfigurations.RegularMemberUserName; RegularMemberPrivateChatId = ConfigurationProvider.TestConfigurations.RegularMemberPrivateChatId; TestsFixture.SendTestCollectionNotificationAsync( CommonConstants.TestCollections.ChatMemberAdministration).Wait(); } else { TestsFixture.SendTestCollectionNotificationAsync( CommonConstants.TestCollections.ChatMemberAdministration, "A non-admin chat member should send /me command so bot can use his/her user id during tests") .Wait(); Message replyInGroup = GetRegularGroupChatMemberUserIdAsync().Result; RegularMemberUserId = replyInGroup.From.Id; RegularMemberUserName = replyInGroup.From.Username; TestsFixture.UpdateReceiver.DiscardNewUpdatesAsync().Wait(); TestsFixture.BotClient.SendTextMessageAsync(TestsFixture.SuperGroupChatId, $"Now, {RegularMemberUserName} should send bot /me command in his/her private chat with bot", ParseMode.Markdown, replyToMessageId: replyInGroup.MessageId).Wait(); Message replyInPrivate = GetRegularMemberPrivateChatIdAsync(RegularMemberUserId).Result; RegularMemberPrivateChatId = replyInPrivate.Chat.Id; } }
public async Task InitializeAsync() { _testsFixture.ChannelChat ??= await GetChat(_collectionName); ChannelChat = _testsFixture.ChannelChat; ChannelChatId = ChannelChat.Username is null ? ChannelChat.Id.ToString() : '@' + ChannelChat.Username; await _testsFixture.SendTestCollectionNotificationAsync( _collectionName, $"Tests will be executed in channel {ChannelChatId.Replace("_", @"\_")}" ); }
public PaymentTestsFixture(TestsFixture testsFixture) { TestsFixture = testsFixture; PaymentProviderToken = ConfigurationProvider.TestConfigurations.PaymentProviderToken; if (string.IsNullOrWhiteSpace(PaymentProviderToken)) { throw new ArgumentNullException(nameof(PaymentProviderToken), "Payment provider token is not provided or is empty."); } if (PaymentProviderToken.Length < 15) { throw new ArgumentException("Payment provider token is too short.", nameof(PaymentProviderToken)); } string privateChatId = ConfigurationProvider.TestConfigurations.TesterPrivateChatId; if (string.IsNullOrWhiteSpace(privateChatId)) { TestsFixture.SendTestCollectionNotificationAsync( CommonConstants.TestCollections.Payment, "A tester should send /test command in a private chat to begin") .Wait(); TestsFixture.UpdateReceiver.DiscardNewUpdatesAsync().Wait(); TesterPrivateChatId = TestsFixture.GetChatIdFromTesterAsync(ChatType.Private).Result; } else { TesterPrivateChatId = privateChatId; TestsFixture.SendTestCollectionNotificationAsync(CommonConstants.TestCollections.Payment, "All messages for this collection will be sent in private chat") .Wait(); TestsFixture.SendTestCollectionNotificationAsync(CommonConstants.TestCollections.Payment, chatid: TesterPrivateChatId) .Wait(); } }
public ChatMemberAdministrationTestFixture(TestsFixture testsFixture) { string collectionName = Constants.TestCollections.ChatMemberAdministration; RegularMemberChat = GetChat(testsFixture, collectionName).GetAwaiter().GetResult(); testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Chosen regular member is @{RegularMemberChat.Username.Replace("_", @"\_")}" ).GetAwaiter().GetResult(); RegularMemberUserId = (int)RegularMemberChat.Id; RegularMemberUserName = RegularMemberChat.Username; }
public PrivateChatFixture(TestsFixture testsFixture, string collectionName) { AddLifetime( initialize: async() => { testsFixture.PrivateChat ??= await GetChat(testsFixture, collectionName); PrivateChat = testsFixture.PrivateChat; await testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Tests will be executed in chat with @{PrivateChat.GetSafeUsername()}" ); } ); }
public PrivateChatFixture(TestsFixture testsFixture, string collectionName) { _testsFixture = testsFixture; if (_testsFixture.PrivateChat == null) { _testsFixture.PrivateChat = GetChat(collectionName).GetAwaiter().GetResult(); } PrivateChat = _testsFixture.PrivateChat; _testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Tests will be executed in chat with @{PrivateChat.Username.Replace("_", @"\_")}" ).GetAwaiter().GetResult(); }
public async Task InitializeAsync() { const string collectionName = Constants.TestCollections.BadRequestException; RegularMemberChat = await GetChat(_testsFixture, collectionName); await _testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Chosen regular member is @{RegularMemberChat.Username!.Replace("_", @"\_")}" ); RegularMemberUserId = (int)RegularMemberChat.Id; RegularMemberUserName = RegularMemberChat.Username; // Updates from regular user will be received _testsFixture.UpdateReceiver.AllowedUsernames.Add(RegularMemberUserName); }
public ChatMemberAdministrationTestFixture(TestsFixture testsFixture) { _testsFixture = testsFixture; const string collectionName = Constants.TestCollections.ChatMemberAdministration; RegularMemberChat = GetChat(_testsFixture, collectionName).GetAwaiter().GetResult(); testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Chosen regular member is @{RegularMemberChat.Username.Replace("_", @"\_")}" ).GetAwaiter().GetResult(); RegularMemberUserId = RegularMemberChat.Id; RegularMemberUserName = RegularMemberChat.Username; // Updates from regular user will be received _testsFixture.UpdateReceiver.AllowedUsernames.Add(RegularMemberUserName); }
public ChannelChatFixture(TestsFixture testsFixture, string collectionName) { _testsFixture = testsFixture; if (_testsFixture.ChannelChat == null) { _testsFixture.ChannelChat = GetChat(collectionName).GetAwaiter().GetResult(); } ChannelChat = _testsFixture.ChannelChat; ChannelChatId = ChannelChat.Username == null ? ChannelChat.Id.ToString() : '@' + ChannelChat.Username; _testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Tests will be executed in channel {ChannelChatId.Replace("_", @"\_")}" ).GetAwaiter().GetResult(); }
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)); }
public ChannelChatFixture(TestsFixture testsFixture, string collectionName) { _testsFixture = testsFixture; AddLifetime( initialize: async() => { _testsFixture.ChannelChat ??= await GetChat(collectionName); ChannelChat = _testsFixture.ChannelChat; ChannelChatId = ChannelChat.Username is null ? ChannelChat.Id.ToString() : $"@{ChannelChat.GetSafeUsername()}"; await _testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Tests will be executed in channel {ChannelChatId}" ); } ); }
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); }
private static async Task <int> GetStickerOwnerIdAsync(TestsFixture testsFixture, string collectionName) { int ownerId; if (ConfigurationProvider.TestConfigurations.StickerOwnerUserId == default) { await testsFixture.UpdateReceiver.DiscardNewUpdatesAsync(); Message notifMessage = await testsFixture.SendTestCollectionNotificationAsync(collectionName, $"\nNo value is set for `{nameof(ConfigurationProvider.TestConfigurations.StickerOwnerUserId)}` " + "in test settings.\n\n" + "" ); const string cqData = "sticker_tests:owner"; Message cqMessage = await testsFixture.BotClient.SendTextMessageAsync( testsFixture.SupergroupChat, testsFixture.UpdateReceiver.GetTesters() + "\nUse the following button to become Sticker Set Owner", replyToMessageId : notifMessage.MessageId, replyMarkup : new InlineKeyboardMarkup( InlineKeyboardButton.WithCallbackData("I am the Owner!", cqData) ) ); Update cqUpdate = await testsFixture.UpdateReceiver .GetCallbackQueryUpdateAsync(cqMessage.MessageId, cqData); ownerId = cqUpdate.CallbackQuery.From.Id; } else { ownerId = ConfigurationProvider.TestConfigurations.StickerOwnerUserId.Value; } return(ownerId); }
public ChatMemberAdministrationTestFixture(TestsFixture testsFixture) { AddLifetime( initialize: async() => { const string collectionName = Constants.TestCollections.ChatMemberAdministration; RegularMemberChat = await GetChat(testsFixture, collectionName); await testsFixture.SendTestCollectionNotificationAsync( collectionName, $"Chosen regular member is @{RegularMemberChat.GetSafeUsername()}" ); RegularMemberUserId = RegularMemberChat.Id; RegularMemberUserName = RegularMemberChat.Username; // Updates from regular user will be received testsFixture.UpdateReceiver.AllowedUsernames.Add(RegularMemberUserName); } ); // Remove regular user from AllowedUserNames AddLifetime(() => testsFixture.UpdateReceiver.AllowedUsernames.Remove(RegularMemberUserName)); }