public async Task ActionFallback() { var container = new Container(); var botClient = Substitute.For <ITelegramBotClient>(); var service = new CallbackQueryService(container, botClient); container.Register <ActionBase, DispatchingExample>(serviceKey: "example"); service.Register("example", typeof(DispatchingExample)); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "1", Data = "example 123" }); await botClient.Received().AnswerCallbackQueryAsync("1", "Number: 123", true); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "2", Data = "example abcd" }); await botClient.Received().AnswerCallbackQueryAsync("2", "Letters: abcd", true); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "3", Data = "example" }); await botClient.Received().AnswerCallbackQueryAsync("3", "No argument", true); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "4", Data = "example 5F625B56-8B66-4510-B5E6-8AF142C7EA16" }); await botClient.Received().AnswerCallbackQueryAsync("4", "Guid: 5f625b56-8b66-4510-b5e6-8af142c7ea16", true); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "5", Data = "example ???" }); await botClient.Received().AnswerCallbackQueryAsync("5"); await Task.CompletedTask; }
public async Task HandleUnknownAction() { var botClient = Substitute.For <ITelegramBotClient>(); var service = new CallbackQueryService(new Container(), botClient); await service.HandleCallbackQueryAsync(new CallbackQuery() { Id = "6", Data = "unknown" }); await botClient.Received().AnswerCallbackQueryAsync("6", "该选项已失效或者没有功能实现", true); }