public void GivenHistoricRate_ConvertFromCurrency_UsingMostRecent() { var today = this.Session.Now().Date; var fromCurrency = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "TRY"); var toCurrency = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "GBP"); new ExchangeRateBuilder(this.Session) .WithValidFrom(today.AddDays(-2)) .WithFromCurrency(fromCurrency) .WithToCurrency(toCurrency) .WithRate(0.085M) .Build(); new ExchangeRateBuilder(this.Session) .WithValidFrom(today.AddDays(-1)) .WithFromCurrency(fromCurrency) .WithToCurrency(toCurrency) .WithRate(0.085945871M) .Build(); this.Session.Derive(); var amount = Currencies.ConvertCurrency(270000M, today, fromCurrency, toCurrency); Assert.Equal(23205.39M, amount); }
public void CalculateRates() { var euroCurrency = ISOCurrencies.AllCurrencies.First(x => x.ISOName == new CurrencyName_ISO4217("EUR")); var philippineCurrency = ISOCurrencies.AllCurrencies.First(x => x.ISOName == new CurrencyName_ISO4217("PHP")); Assert.InRange( Currencies.ConvertCurrency(euroCurrency, philippineCurrency, 10).Value, 0.172M, 0.173M); var usaCurrency = ISOCurrencies.AllCurrencies.First(x => x.ISOName == new CurrencyName_ISO4217("USD")); Assert.InRange( Currencies.ConvertCurrency(euroCurrency, usaCurrency, 10).Value, 8.393M, 8.394M); var singaporeCurrency = ISOCurrencies.AllCurrencies.First(x => x.ISOName == new CurrencyName_ISO4217("SGD")); Assert.InRange( Currencies.ConvertCurrency(euroCurrency, singaporeCurrency, 10).Value, 6.262M, 6.263M); }
public void GivenRateForExactDate_ConvertFromCurrencyUsingInvertedRate() { var today = this.Session.Now().Date; var fromTry = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "TRY"); var toGbp = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "GBP"); new ExchangeRateBuilder(this.Session) .WithValidFrom(today) .WithFromCurrency(toGbp) .WithToCurrency(fromTry) .WithRate(11.635230272M) .Build(); this.Session.Derive(); var amount = Currencies.ConvertCurrency(270000M, today, fromTry, toGbp); Assert.Equal(23205.39M, amount); }
private static SuperChat FetchSuperChatData(ISOCurrency?currency, decimal?amount) { if (currency is null || amount is null) { return(SuperChatData.UNKNOWN); } var superchatData = SuperChatData.OrderedSuperchats; if (currency != SuperChatData.KNOWN_CURRENCY) { amount = Currencies.ConvertCurrency(SuperChatData.KNOWN_CURRENCY, currency, amount.Value)?.Value; } foreach (var targetData in superchatData) { if (amount >= targetData.MinimumValuta.Value) { return(targetData); } } return(SuperChatData.UNKNOWN); }