Ejemplo n.º 1
0
        public void GetExchangeRates_InvalidURL_ThrowsException()
        {
            Mock <IRateProviderSettings> settingsMock = new Mock <IRateProviderSettings>();

            settingsMock.Setup(mock => mock.CZKExchangeRateProviderUrl).Returns("Invalid Url");

            IRateProvider rateProvider = ContainerConfiguration.Container.Resolve <IRateProvider>(
                new Unity.Resolution.ParameterOverride("rateProviderSettings", settingsMock.Object)
                );

            Assert.ThrowsException <ArgumentException>(() =>
            {
                rateProvider.GetExchangeRates();
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Should return exchange rates among the specified currencies that are defined by the source. But only those defined
        /// by the source, do not return calculated exchange rates. E.g. if the source contains "EUR/USD" but not "USD/EUR",
        /// do not return exchange rate "USD/EUR" with value calculated as 1 / "EUR/USD". If the source does not provide
        /// some of the currencies, ignore them.
        /// </summary>
        public IEnumerable <ExchangeRate> GetExchangeRates(IEnumerable <Currency> currencies)
        {
            List <ExchangeRate> exchangeRates = new List <ExchangeRate>();

            IRateProvider rateProvider = RateProviderFactory.Create();

            IDictionary <string, decimal> exchangeRatesDictionary = rateProvider.GetExchangeRates();

            foreach (Currency currency in currencies)
            {
                if (exchangeRatesDictionary.ContainsKey(currency.Code))
                {
                    ExchangeRate exchangeRate = ExchangeRateFactory.Create(rateProvider.SourceCurrencyCode, currency, exchangeRatesDictionary[currency.Code]);

                    exchangeRates.Add(exchangeRate);
                }
            }

            return(exchangeRates);
        }
Ejemplo n.º 3
0
        public void GetExchangeRates_CNBRateUrl_ReturnRateWithAmount1()
        {
            Mock <IRateProviderSettings> settingsMock = new Mock <IRateProviderSettings>();

            settingsMock.Setup(mock => mock.CZKExchangeRateProviderUrl).Returns(
                "https://www.cnb.cz/en/financial-markets/foreign-exchange-market/central-bank-exchange-rate-fixing/central-bank-exchange-rate-fixing/daily.txt"
                );

            IRateProvider rateProvider = ContainerConfiguration.Container.Resolve <IRateProvider>(
                new Unity.Resolution.ParameterOverride("rateProviderSettings", settingsMock.Object)
                );

            var rates = rateProvider.GetExchangeRates(new DateTime(2020, 1, 1));

            if (rates.ContainsKey("PHP"))
            {
                Assert.AreEqual((decimal)(44.661 / 100), rates["PHP"]);
            }
            else
            {
                Assert.Fail();
            }
        }