示例#1
0
        public async Task GetDailyRates()
        {
            var referenceDate = new DateTime(2020, 12, 31);

            var rates = new DailyRatesModel.ExchangeRateModel[]
            {
                new DailyRatesModel.ExchangeRateModel
                {
                    Currency               = "U.S. Dollar",
                    Country                = "UNITED STATES",
                    IsoCode                = "USD",
                    UicCode                = "001",
                    AvgRate                = 1.1652,
                    ExchangeConvention     = "Foreign currency amount for 1 Euro",
                    ExchangeConventionCode = "C",
                    ReferenceDate          = referenceDate
                },
                new DailyRatesModel.ExchangeRateModel
                {
                    Currency               = "Pound Sterling",
                    Country                = "UNITED KINGDOM",
                    IsoCode                = "GBP",
                    UicCode                = "002",
                    AvgRate                = 0.89183,
                    ExchangeConvention     = "Foreign currency amount for 1 Euro",
                    ExchangeConventionCode = "C",
                    ReferenceDate          = referenceDate
                },
                new DailyRatesModel.ExchangeRateModel
                {
                    Currency               = "Swiss Franc",
                    Country                = "SWITZERLAND",
                    IsoCode                = "CHF",
                    UicCode                = "003",
                    AvgRate                = 1.0817,
                    ExchangeConvention     = "Foreign currency amount for 1 Euro",
                    ExchangeConventionCode = "C",
                    ReferenceDate          = referenceDate
                }
            };

            var expected = new DailyRatesModel
            {
                ResultsInfo = new DailyRatesModel.ResultsInfoModel
                {
                    TotalRecords      = rates.Length,
                    TimezoneReference = "Dates refer to the Central European Time Zone"
                },
                Rates = rates
            };

            var actual = await _client.GetDailyRates(referenceDate, "EUR");

            Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual));
        }
示例#2
0
        public static void Execute(IExchangeRatesClient client, DailyRates options)
        {
            var model = client.GetDailyRates(options.ReferenceDate,
                                             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($"Ref. date   Rate                ISO  Currency, country");
            foreach (var rate in model.Rates)
            {
                System.Console.WriteLine(
                    $"{rate.ReferenceDate:yyyy-MM-dd}  {rate.AvgRate,16:N6} {rate.ExchangeConventionCode,1}  {rate.IsoCode,-3}  {rate.Currency}, {rate.Country}");
            }
            System.Console.WriteLine();
            System.Console.WriteLine(model.ResultsInfo.TimezoneReference);
            System.Console.WriteLine("Exchange convention:");
            foreach (var exchangeConvention in exchangeConventions)
            {
                System.Console.WriteLine(
                    $"{exchangeConvention.ExchangeConventionCode} {exchangeConvention.ExchangeConvention}");
            }
        }