private async Task ChooseImage(Message message) { var digitalOceanApi = _digitalOceanClientFactory.GetInstance(message.From.Id); var images = await digitalOceanApi.Images.GetAll(ImageType.Distribution); _sessionRepo.Update(message.From.Id, session => { var droplet = new Droplet { Name = message.Text, }; var createDroplet = new CreateDroplet { Droplet = droplet, Images = images }; session.Data = createDroplet; session.State = SessionState.WaitChooseImageDroplet; }); var page = _pageFactory.GetInstance <ImagePage>(); var pageModel = page.GetPage(message.From.Id, 0); var sendMessage = await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, pageModel.Message, ParseMode.Markdown, replyMarkup : pageModel.Keyboard); _handlerCallbackRepo.Update(message.From.Id, callback => { callback.MessageId = sendMessage.MessageId; callback.UserId = message.From.Id; callback.HandlerType = GetType().FullName; }); }
private async Task GetFirewalls(Message message) { await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, "\U0001F4C0 Loading your firewalls...", replyMarkup : Keyboards.GetFirewallMenuKeyboard()); var digitalOceanApi = _digitalOceanClientFactory.GetInstance(message.From.Id); var firewalls = await digitalOceanApi.Firewalls.GetAll(); if (firewalls.Count > 0) { _sessionRepo.Update(message.From.Id, session => { session.Data = firewalls; session.State = SessionState.FirewallsMenu; }); var droplets = await digitalOceanApi.Droplets.GetAll(); var page = _pageFactory.GetInstance <FirewallPage>(droplets); var pageModel = page.GetPage(message.From.Id, 0); var sendMessage = await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, pageModel.Message, ParseMode.Markdown, replyMarkup : pageModel.Keyboard); _handlerCallbackRepo.Update(message.From.Id, callback => { callback.MessageId = sendMessage.MessageId; callback.UserId = message.From.Id; callback.HandlerType = GetType().FullName; }); } else { await _telegramBotClient.SendTextMessageAsync(message.Chat.Id, "You dont have a firewalls \U0001F914"); } }
private void InitTest() { _logger = Substitute.For <ILogger <DigitalOceanWorker> >(); _tg = Substitute.For <ITelegramBotClient>(); _userRepo = Substitute.For <IRepository <DoUser> >(); _sessionRepo = Substitute.For <IRepository <Session> >(); _handlerCallbackRepo = Substitute.For <IRepository <HandlerCallback> >(); _pageFactory = Substitute.For <IPageFactory>(); _digitalOceanClientFactory = Substitute.For <IDigitalOceanClientFactory>(); _message = Substitute.For <Message>(); _message.From = new User { Id = 100 }; _message.Chat = new Chat { Id = 101 }; _digitalOceanClientFactory.GetInstance(Arg.Any <int>()) .Droplets .GetAll() .Returns(new List <Droplet> { new Droplet { Id = 1, CreatedAt = DateTime.Now, Disk = 256, Memory = 1024, Name = "Test droplet", Status = "active", Vcpus = 1, Region = new Region { Name = "Test" }, Image = new Image { Name = "test", Distribution = "test" }, Tags = new List <string> { "test" }, Networks = new Network { V4 = new List <InterfaceV4> { new InterfaceV4 { IpAddress = "0.0.0.0.0" } }, V6 = new List <InterfaceV6> { new InterfaceV6 { IpAddress = "000:0000:000" } } } } }); _userRepo.Get(Arg.Any <int>()).Returns(new DoUser { UserId = 100, Token = "token" }); _pageFactory.GetInstance <IPage>() .GetPage(Arg.Any <int>(), Arg.Any <int>()) .Returns(new PageModel { Message = "Test message", Keyboard = new InlineKeyboardMarkup(new List <List <InlineKeyboardButton> >()) }); }
private void InitTest() { _logger = Substitute.For <ILogger <DigitalOceanWorker> >(); _tg = Substitute.For <ITelegramBotClient>(); _userRepo = Substitute.For <IRepository <DoUser> >(); _sessionRepo = Substitute.For <IRepository <Session> >(); _handlerCallbackRepo = Substitute.For <IRepository <HandlerCallback> >(); _pageFactory = Substitute.For <IPageFactory>(); _digitalOceanClientFactory = Substitute.For <IDigitalOceanClientFactory>(); _message = Substitute.For <Message>(); _callbackQuery = Substitute.For <CallbackQuery>(); _message.From = new User { Id = 100 }; _message.Chat = new Chat { Id = 101 }; _callbackQuery.From = _message.From; _callbackQuery.Message = _message; _digitalOceanClientFactory.GetInstance(Arg.Any <int>()) .Images .GetAll(Requests.ImageType.Distribution) .Returns(new List <Responses.Image> { new Responses.Image { CreatedAt = DateTime.Now, Id = 1, MinDiskSize = 1, SizeGigabytes = 20, Name = "Test OS", Distribution = "test-dist", Public = true, Status = "active", Slug = "slug", Regions = new List <string> { "reg1", "reg2" }, Type = "type" } }); _digitalOceanClientFactory.GetInstance(Arg.Any <int>()) .Regions .GetAll() .Returns(new List <Responses.Region> { new Responses.Region { Available = true, Name = "reg1", Slug = "slug", Sizes = new List <string> { "size-1", "size-2" } } }); _digitalOceanClientFactory.GetInstance(Arg.Any <int>()) .Sizes .GetAll() .Returns(new List <Responses.Size> { new Responses.Size { Available = true, Memory = 1024, Disk = 25, Slug = "slug", PriceHourly = decimal.Zero, PriceMonthly = decimal.One, Vcpus = 1, Regions = new List <string> { "reg1", "reg2" } } }); _pageFactory.GetInstance <IPage>() .GetPage(Arg.Any <int>(), Arg.Any <int>()) .Returns(new PageModel { Message = "Test message", Keyboard = new InlineKeyboardMarkup(new List <List <InlineKeyboardButton> >()) }); _pageFactory.GetInstance <IPage>() .SelectPage(Arg.Any <int>(), Arg.Any <object>()) .Returns(new PageModel { Message = "Test message", Keyboard = new InlineKeyboardMarkup(new List <List <InlineKeyboardButton> >()) }); _userRepo.Get(Arg.Any <int>()).Returns(new DoUser { UserId = 100, Token = "token" }); }
protected StepBase(IPageFactory factory) { Page = factory.GetInstance <T>(); }