コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public async Task CanGetCurrencies()
        {
            var client = new RatesExchangeApiService(ApiKey);
            var result = await client.GetCurrencies();

            Assert.That(result, Is.Not.Null);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 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();
 }
コード例 #12
0
        public void EmptyApiKeyThrowsException()
        {
            var client = new RatesExchangeApiService(string.Empty);

            Assert.That(async() => await client.GetLatestRates(BaseCurrency), Throws.InvalidOperationException);
        }