Beispiel #1
0
        public async Task Should_Throw_Exception_When_Answering_Late()
        {
            await TestsFixture.SendTestInstructionsAsync(
                "Write an inline query that I'll never answer!",
                startInlineQuery : true
                );

            Update queryUpdate = await TestsFixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle(
                    id: "article:bot-api",
                    title: "Telegram Bot API",
                    inputMessageContent: new InputTextMessageContent("https://core.telegram.org/bots/api"))
                {
                    Description = "The Bot API is an HTTP-based interface created for developers",
                },
            };

            await Task.Delay(10_000);

            InvalidQueryIdException exception = await Assert.ThrowsAsync <InvalidQueryIdException>(
                async() => await BotClient.AnswerInlineQueryAsync(
                    inlineQueryId: queryUpdate.InlineQuery !.Id,
                    results: results,
                    cacheTime: 0
                    )
                );

            Assert.Equal(400, exception.ErrorCode);
            Assert.Contains("query is too old and response timeout expired or query ID is invalid", exception.Message);
        }
        public async Task Should_Throw_Exception_QueryIdInvalidException()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldThrowExceptionInvalidQueryIdException,
                                                         startInlineQuery : true);

            Update queryUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle(
                    id: "article:bot-api",
                    title: "Telegram Bot API",
                    inputMessageContent: new InputTextMessageContent("https://core.telegram.org/bots/api"))
                {
                    Description = "The Bot API is an HTTP-based interface created for developers",
                },
            };

            await Task.Delay(10_000);

            InvalidQueryIdException e = await Assert.ThrowsAnyAsync <InvalidQueryIdException>(() =>
                                                                                              BotClient.AnswerInlineQueryAsync(
                                                                                                  inlineQueryId: queryUpdate.InlineQuery.Id,
                                                                                                  results: results,
                                                                                                  cacheTime: 0
                                                                                                  )
                                                                                              );

            Assert.Equal("inline_query_id", e.Parameter);
        }