public async Task GetAnnualAverageRates() { var year = 2020; var rates = new AnnualAverageRatesModel.ExchangeRateModel[] { new AnnualAverageRatesModel.ExchangeRateModel { Currency = "U.S. Dollar", Country = "UNITED STATES", IsoCode = "USD", UicCode = "001", AvgRate = 1.1652, ExchangeConvention = "Foreign currency amount for 1 Euro", ExchangeConventionCode = "C", Year = year }, new AnnualAverageRatesModel.ExchangeRateModel { Currency = "Pound Sterling", Country = "UNITED KINGDOM", IsoCode = "GBP", UicCode = "002", AvgRate = 0.89183, ExchangeConvention = "Foreign currency amount for 1 Euro", ExchangeConventionCode = "C", Year = year }, new AnnualAverageRatesModel.ExchangeRateModel { Currency = "Swiss Franc", Country = "SWITZERLAND", IsoCode = "CHF", UicCode = "003", AvgRate = 1.0817, ExchangeConvention = "Foreign currency amount for 1 Euro", ExchangeConventionCode = "C", Year = year } }; var expected = new AnnualAverageRatesModel { ResultsInfo = new AnnualAverageRatesModel.ResultsInfoModel { TotalRecords = rates.Length }, Rates = rates }; var actual = await _client.GetAnnualAverageRates(year, "EUR"); Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual)); }
public static void Execute(IExchangeRatesClient client, AnnualAverageRates options) { var model = client.GetAnnualAverageRates(options.Year, options.BaseCurrencyIsoCodes.Select(e => e.ToUpper()), options.CurrencyIsoCode.ToUpper()).Result; var exchangeConventions = model.Rates .Select(e => new { e.ExchangeConventionCode, e.ExchangeConvention }).Distinct().ToList(); System.Console.WriteLine($"Year Rate ISO Currency, country"); foreach (var rate in model.Rates) { System.Console.WriteLine( $"{rate.Year:0000} {rate.AvgRate,16:N6} {rate.ExchangeConventionCode,1} {rate.IsoCode,-3} {rate.Currency}, {rate.Country}"); } System.Console.WriteLine(); System.Console.WriteLine("Exchange convention:"); foreach (var exchangeConvention in exchangeConventions) { System.Console.WriteLine( $"{exchangeConvention.ExchangeConventionCode} {exchangeConvention.ExchangeConvention}"); } }