private async Task AssertProviderAsync(IExchangeRateProvider provider) { IEnumerable <ExchangeRate> rates = await provider.GetExchangeRateAsync(); var usdRate = Assert.Single(rates, x => x.Ticker == "USD"); Assert.NotEqual(0.0m, usdRate.Rate); }
/// <summary> /// Wrap a given exchange rate provider to allow to use the same rate for conversion in both directions /// </summary> /// <param name="rates">The provider to wrap</param> public ExchangeRateBothWaysWrapper(IExchangeRateProvider rates) { if (rates == null) { throw new ArgumentNullException(nameof(rates)); } _rates = rates; }
public CurrencyParser(IExchangeRateProvider provider) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } this.provider = provider; }
public CurrencyConverter(IExchangeRateProvider exchangeRateProvider) { if (exchangeRateProvider == null) { throw new ArgumentNullException(nameof(exchangeRateProvider)); } this.exchangeRateProvider = exchangeRateProvider; }
public ExchangeRateUpdater(IJobManager jobManager, IExchangeRateProvider exchangeRateProvider, IContextHolder contextHolder) { _jobManager = jobManager; _exchangeRateProvider = exchangeRateProvider; _contextHolder = contextHolder; LastExecuted = DateTime.Now.AddSeconds(-RepetitionIntervalInSeconds * 2); _jobManager.Add(this); }
/// <summary> /// Convert the amount into a different currency /// </summary> /// <param name="exchangeRates">The exchange rates</param> /// <param name="amount">The amount to convert</param> /// <param name="targetCurrency">The currency to convert to</param> /// <returns>The converted currency</returns> ///<exception cref="KeyNotFoundException" /> public static Money Convert(this IExchangeRateProvider exchangeRates, Money amount, Currency targetCurrency) { if (exchangeRates == null) { throw new ArgumentNullException(nameof(exchangeRates)); } return (exchangeRates.TryConvert(amount, targetCurrency) ?? throw new KeyNotFoundException(Resources.ExchangeRates_CannotFindExchangeRateForCurrencies)); }
/// <summary> /// Try to get the exchange rate SOURCE->TARGET /// </summary> /// <param name="exchangeRates">The exchange rates</param> /// <param name="sourceCurrency">The currency to convert from</param> /// <param name="targetCurrency">The currency to convert to</param> /// <returns>Either the exchange rate, or an exception</returns> /// <exception cref="KeyNotFoundException"/> public static ExchangeRate Get(this IExchangeRateProvider exchangeRates, Currency sourceCurrency, Currency targetCurrency) { if (exchangeRates == null) { throw new ArgumentNullException(nameof(exchangeRates)); } return (exchangeRates.TryGet(sourceCurrency, targetCurrency) ?? throw new KeyNotFoundException(Resources.ExchangeRates_CannotFindExchangeRateForCurrencies)); }
/// <summary> /// ctor /// </summary> /// <param name="currencyRepository">currencyRepository</param> /// <param name="exchangeRateProvider">exchangeRateProvider</param> /// <param name="cacheManager">cacheManager</param> public CurrencyService( IRepository <Currency> currencyRepository, IExchangeRateProvider exchangeRateProvider, ICacheManager cacheManager ) { this._currencyRepository = currencyRepository; this._exchangeRateProvider = exchangeRateProvider; this._cacheManager = cacheManager; }
public ExchangeRateService( IExchangeRateProvider exchangeRateProvider, ICoinbaseConnector coinbaseConnector, IHubDbRepository dbRepository, ILogger <ExchangeRateService> logger) { _exchangeRateProvider = exchangeRateProvider; _coinbaseConnector = coinbaseConnector; _dbRepository = dbRepository; _logger = logger; }
/// <summary> /// Ctor /// </summary> /// <param name="cacheManager">Cache manager</param> /// <param name="currencyRepository">Currency repository</param> /// <param name="currencySettings">Currency settings</param> /// <param name="eventPublisher">Event published</param> /// <param name="exchangeRateProvider">Exchange rate provider</param> public CurrencyService(ICacheManager cacheManager, IRepository <Currency> currencyRepository, CurrencySettings currencySettings, IEventPublisher eventPublisher, IExchangeRateProvider exchangeRateProvider) { this._cacheManager = cacheManager; this._currencyRepository = currencyRepository; this._currencySettings = currencySettings; this._eventPublisher = eventPublisher; this._exchangeRateProvider = exchangeRateProvider; }
public async Task <IReadOnlyCollection <ExchangeRateProviderModel> > FetchProviderExchangeRateAsync( string providerName, string counterCurrency, List <string> baseCurrencies) { IExchangeRateProvider provider = _exchangeRateProviderResolver.Resolve(providerName); IReadOnlyCollection <ExchangeRateProviderModel> result = await provider .FetchCurrencyRatesAsync(baseCurrencies, counterCurrency); return(result); }
public IExchangeRateProvider Resolve(string name) { IExchangeRateProvider provider = _exchangeRateProviders .FirstOrDefault(p => p.ProviderName.Equals(name, StringComparison.OrdinalIgnoreCase)); if (provider == null) { throw new Exception("Exchange Rate Provider is not supported"); } return(provider); }
private void BindData() { string prv1 = SettingManager.GetSettingValue("ExchangeRateProvider1.Classname"); string prv2 = SettingManager.GetSettingValue("ExchangeRateProvider2.Classname"); string prv3 = SettingManager.GetSettingValue("ExchangeRateProvider3.Classname"); if (!String.IsNullOrEmpty(prv1)) { Type t = Type.GetType(prv1, false); if (t != null) { IExchangeRateProvider instance = Activator.CreateInstance(t) as IExchangeRateProvider; if (instance != null) { ddlExchangeRateProviders.Items.Add(new ListItem(instance.Name, "1")); } } } if (!String.IsNullOrEmpty(prv2)) { Type t = Type.GetType(prv2, false); if (t != null) { IExchangeRateProvider instance = Activator.CreateInstance(t) as IExchangeRateProvider; if (instance != null) { ddlExchangeRateProviders.Items.Add(new ListItem(instance.Name, "2")); } } } if (!String.IsNullOrEmpty(prv3)) { Type t = Type.GetType(prv3, false); if (t != null) { IExchangeRateProvider instance = Activator.CreateInstance(t) as IExchangeRateProvider; if (instance != null) { ddlExchangeRateProviders.Items.Add(new ListItem(instance.Name, "3")); } } } ddlExchangeRateProviders.DataBind(); ddlExchangeRateProviders.SelectedValue = SettingManager.GetSettingValue("ExchangeRateProvider.Current"); }
/// <summary> /// Convert the amount into a different currency /// </summary> /// <param name="exchangeRates">The exchange rates</param> /// <param name="amount">The amount to convert</param> /// <param name="targetCurrency">The currency to convert to</param> /// <returns>The converted currency</returns> public static Money?TryConvert(this IExchangeRateProvider exchangeRates, Money amount, Currency targetCurrency) { if (exchangeRates == null) { throw new ArgumentNullException(nameof(exchangeRates)); } var rate = exchangeRates.TryGet(amount.Currency, targetCurrency); if (rate == null) { return(null); } return(amount * rate); }
public UpdateCurrencyCommand(IExchangeRateProvider provider, Currency currency, decimal rate) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } if (currency == null) { throw new ArgumentNullException(nameof(currency)); } this.provider = provider; this.currency = currency; this.rate = rate; }
public void Setup() { mock = new Mock <IExchangeRateProvider>(); mock.Setup(e => e.GetExchangeRate(It.IsAny <string>())) .Throws(new NotSupportedException(NOT_A_VALID_CURRENCY)); mock.Setup(e => e.GetExchangeRate("INR")).Returns(inr); mock.Setup(e => e.GetExchangeRate("USD")).Returns(usd); mock.Setup(e => e.GetExchangeRate("THB")).Returns(thb); mock.Setup(e => e.GetExchangeRate("EUR")).Returns(eur); mock.Setup(e => e.GetExchangeRate(It.Is <string>(s => s.Length != 3))) .Throws(new ArgumentException(INVALID_CURRENCY_FORMAT)); provider = mock.Object; converter = new CurrencyConverter(provider); }
public void Setup() { mock = new Mock <IExchangeRateProvider>(); //mock.Setup(e => e.GetExchangeRate(It.IsAny<string>())) // .Throws(new NotSupportedException(NOT_A_VALID_CURRENCY)); mock.Setup(e => e.Add(It.IsAny <String>(), It.IsAny <double>())) .Callback <string, double>((s, r) => rates[s.ToLower()] = r); mock.Setup(e => e.GetExchangeRate(It.IsAny <String>())) .Returns <string>(s => { if (s.Length != 3) { throw new ArgumentException(INVALID_CURRENCY_FORMAT); } s = s.ToLower(); if (rates.ContainsKey(s)) { return(rates[s]); } else { throw new NotSupportedException(NOT_A_VALID_CURRENCY); } }); provider = mock.Object; provider.Add("INR", inr); provider.Add("USD", usd); provider.Add("THB", thb); provider.Add("EUR", eur); converter = new CurrencyConverter(provider); }
public ExchangeConversion(IExchangeRateProvider provider, Money from) { _provider = provider; _from = from; }
public ExchangeRateProvider(IExchangeRateProvider provider) { this.provider = provider ?? throw new System.Exception("Provider should be set!"); }
public OffchainController(IMemoryCache memoryCache, IExchangeRateProvider exchangeRateProvider) { Cache = memoryCache; ExchangeRateProvider = exchangeRateProvider; }
public CurrencyConvertService(IExchangeRateProvider exchangeRateProvider) { _exchangeRateProvider = exchangeRateProvider; }
public CurrencyConverter(IExchangeRateProvider provider) { this.provider = provider; }
public HomeController(IEnumerable <IExchangeRateProvider> providerServices, ICalculationService calculationService, IExchangeRateProvider referenceExchangeRateProvider) { this.providerServices = providerServices; this.calculationService = calculationService; this.referenceExchangeRateProvider = referenceExchangeRateProvider; }
private static CurrencyConverter CreateCurrencyConverter(IExchangeRateProvider provider = null) { return(new CurrencyConverter(provider)); }
public ExchangeService(IExchangeRateProvider ratesProvider) { _ratesProvider = ratesProvider; }
public BlockchainController(IMemoryCache memoryCache, IExchangeRateProvider exchangeRateProvider) { _cache = memoryCache; _exchangeRateProvider = exchangeRateProvider; }
public CurrencyParser(IExchangeRateProvider provider) { _provider = provider ?? throw new ArgumentNullException(nameof(provider)); }
public UpdateCurrencyCommand(IExchangeRateProvider provider, Currency currency, decimal rate) { _provider = provider ?? throw new ArgumentNullException(nameof(provider)); _currency = currency ?? throw new ArgumentNullException(nameof(currency)); _rate = rate; }
public RatesController(IExchangeRateProvider exchangeRateProvider) { _exchangeRateProvider = exchangeRateProvider; }
public Exchanger(RoundCalculator roundCalculator, IExchangeRateProvider exchangeRateProvider) { RoundCalculator = roundCalculator; ExchangeRateProvider = exchangeRateProvider; }