Exemplo n.º 1
0
        public async Task GetLatestRates()
        {
            var rates = new LatestRatesModel.ExchangeRateModel[]
            {
                new LatestRatesModel.ExchangeRateModel
                {
                    Currency = "U.S. Dollar",
                    Country  = "UNITED STATES",
                    IsoCode  = "USD",
                    UicCode  = "001",
                    EurRate  = 1.1652,
                    UsdRate  = 1,
                    UsdExchangeConvention     = "-",
                    UsdExchangeConventionCode = "-",
                    ReferenceDate             = new DateTime(2020, 12, 30)
                },
                new LatestRatesModel.ExchangeRateModel
                {
                    Currency = "Euro",
                    Country  = "EUROPEAN MONETARY UNION",
                    IsoCode  = "EUR",
                    UicCode  = "242",
                    EurRate  = 1,
                    UsdRate  = 0.8582,
                    UsdExchangeConvention     = "Foreign currency amount for 1 Dollar",
                    UsdExchangeConventionCode = "C",
                    ReferenceDate             = new DateTime(2020, 12, 31)
                }
            };

            var expected = new LatestRatesModel
            {
                ResultsInfo = new LatestRatesModel.ResultsInfoModel
                {
                    TotalRecords      = rates.Length,
                    TimezoneReference = "Dates refer to the Central European Time Zone",
                    Notice            = "Foreign currency amount for 1 Euro"
                },
                LatestRates = rates
            };

            var actual = await _client.GetLatestRates();

            Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual));
        }
Exemplo n.º 2
0
        public static void Execute(IExchangeRatesClient client)
        {
            var model = client.GetLatestRates().Result;
            var usdExchangeConventions = model.LatestRates.Where(e => e.IsoCode != "USD")
                                         .Select(e => new { e.UsdExchangeConventionCode, e.UsdExchangeConvention }).Distinct().ToList();

            System.Console.WriteLine($"Ref. date   EUR rate          USD rate            ISO  Currency, country");
            foreach (var rate in model.LatestRates)
            {
                System.Console.WriteLine(
                    $"{rate.ReferenceDate:yyyy-MM-dd}  {rate.EurRate,16:N6}  {rate.UsdRate,16:N6} {rate.UsdExchangeConventionCode,1}  {rate.IsoCode,-3}  {rate.Currency}, {rate.Country}");
            }
            System.Console.WriteLine();
            System.Console.WriteLine(model.ResultsInfo.TimezoneReference);
            System.Console.WriteLine(model.ResultsInfo.Notice);
            System.Console.WriteLine("USD exchange convention:");
            foreach (var usdExchangeConvention in usdExchangeConventions)
            {
                System.Console.WriteLine(
                    $"{usdExchangeConvention.UsdExchangeConventionCode} {usdExchangeConvention.UsdExchangeConvention}");
            }
        }