private static async Task ConvertCurrency(RatesExchangeApiService client, string fromCurrency, string amount, string date, List <string> currencies) { Console.WriteLine($"-- Convert {amount} {fromCurrency} to {currencies}."); var parsed = JsonConvert.SerializeObject(await client.ConvertCurrency(fromCurrency, amount, date, currencies), Formatting.Indented); Console.WriteLine(parsed); }
private static async Task CheckIfApiIsOnline(RatesExchangeApiService client) { Console.WriteLine("-- Check if API is online"); var parsed = JsonConvert.SerializeObject(await client.CheckIfApiIsOnline(), Formatting.Indented); Console.WriteLine(parsed); }
private static async Task GetLatestRates(RatesExchangeApiService client, string baseCurrency, List <string> currencies) { Console.WriteLine("-- Get latest rates from ECB"); var parsed = JsonConvert.SerializeObject(await client.GetLatestRates(baseCurrency, currencies), Formatting.Indented); Console.WriteLine(parsed); }
public async Task CanGetCurrencies() { var client = new RatesExchangeApiService(ApiKey); var result = await client.GetCurrencies(); Assert.That(result, Is.Not.Null); }
public async Task CanConvertCurrency() { var client = new RatesExchangeApiService(ApiKey); var result = await client.ConvertCurrency(BaseCurrency, "100", HistoryDateForRates); Assert.That(result, Is.Not.Null); Assert.That(result.Rates, Is.Not.Null); }
public async Task CanGetHistoryRatesForDate() { var client = new RatesExchangeApiService(ApiKey); var result = await client.GetHistoryRatesForCurrency(OtherCurrency, HistoryDateForRates); Assert.That(result, Is.Not.Null); Assert.That(result.Rates, Is.Not.Null); }
public async Task CanGetLatestDetailsRates() { var client = new RatesExchangeApiService(ApiKey); var result = await client.GetLatestDetailsRates(BaseCurrency); Assert.That(result, Is.Not.Null); Assert.That(result.Rates, Is.Not.Null); }
public async Task ValidApiKeyRetrievesData() { var client = new RatesExchangeApiService(ApiKey); var result = await client.CheckIfApiIsOnline(); Assert.That(result, Is.Not.Null); Assert.That(result.Result, Is.Not.Null); }
public async Task CanGetLatestRates() { var client = new RatesExchangeApiService(ApiKey); var currencies = new List <string> { "USD", "CHF", "GBP" }; var result = await client.GetLatestRates(BaseCurrency, currencies); Assert.That(result, Is.Not.Null); Assert.That(result.Rates, Is.Not.Null); }
private static async Task <decimal> GetExchangeRateForDate(string date, string apiKey) { var client = new RatesExchangeApiService(apiKey); var isoCurrencies = new List <string> { "BRL" }; var rates = await client.GetHistoryRates("USD", date, isoCurrencies); var rate = rates.Rates["BRL"]; return(rate); }
private static void Main() { try { var client = new RatesExchangeApiService(ApiKey); CheckIfApiIsOnline(client).Wait(); GetLatestRates(client, "EUR", IsoCurrencies).Wait(); ConvertCurrency(client, "USD", "100", "2018-06-25", IsoCurrencies).Wait(); } catch (Exception exception) { Console.WriteLine($"{exception.Message}"); } Console.ReadKey(); }
public void EmptyApiKeyThrowsException() { var client = new RatesExchangeApiService(string.Empty); Assert.That(async() => await client.GetLatestRates(BaseCurrency), Throws.InvalidOperationException); }