public override async Task <OperationResult> ExecuteAsync(ViberCommand commandBase) { return(await MessageSender.SendTextAsync(new ViberMessage { Keyboard = GetCurrencyRateKeyboard.Keyboard, Receiver = commandBase.Receiver, Text = "Hi!", SenderDisplayName = "Currency Bot" })); }
public async Task ExecuteActionAsync_NotExistedCommand_CommandNotFount() { var actionExecutor = GetService <IActionExecutor <ViberCommand> >(); var command = new ViberCommand("Not existed"); var result = await actionExecutor.ExecuteActionAsync(command); Assert.False(result.Success); Assert.AreEqual(Constants.CommandNotFound, result.Error); }
public async Task ExecuteActionAsync_CorrectCommand_SuccessfullyResult() { var actionExecutor = GetService <IActionExecutor <ViberCommand> >(); var command = new ViberCommand(nameof(TestAction) .Replace(TestConstants.Action, string.Empty)) { Receiver = "1", }; var result = await actionExecutor.ExecuteActionAsync(command); Assert.True(result.Success); Assert.AreEqual(string.Empty, result.Error); }
public override async Task <OperationResult> ExecuteAsync(ViberCommand command) { var defaultCurrencies = await _usersService.GetUserDefaultCurrencies(command.Receiver); if (!defaultCurrencies.Any()) { defaultCurrencies = new List <Currency> { new Currency { Abbreviation = "USD" }, new Currency { Abbreviation = "EUR" }, new Currency { Abbreviation = "RUB" } } } ; var sb = new StringBuilder(); foreach (var currency in defaultCurrencies) { var gain = await _currencyService.GetCurrencyRateGain(currency.Abbreviation, DateTime.UtcNow); sb.Append(_messageService.GetCurrencyRateMessageAsync(gain)); } return(await MessageSender.SendTextAsync(new ViberMessage { Receiver = command.Receiver, Keyboard = GetCurrencyRateKeyboard.Keyboard, Text = sb.ToString(), SenderDisplayName = "Qwe" })); } }
public override async Task <OperationResult> ExecuteAsync(ViberCommand command) { var count = await _currencyService.GetCurrenciesCountAsync(); var currencies = await _currencyService.GetAllCurrencies(); var pageCount = Math.Ceiling((double)count / PageSize); for (var i = 0; i < pageCount; i++) { var message = _messageService.GetAllCurrenciesMessageAsync(currencies); await MessageSender.SendTextAsync(new ViberMessage { Receiver = command.Receiver, Keyboard = GetCurrencyRateKeyboard.Keyboard, Text = message, SenderDisplayName = "Qwe" }); } return(new OperationResult()); }
public override Task <OperationResult> ExecuteAsync(ViberCommand commandBase) { return(Task.FromResult(new OperationResult())); }