public void AddExchangeRate_CHFtoUSD_GetExchangeRate_CHFtoUSD() { var repository = new CurrencyExchangeRepository(); repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); var rate = repository.GetExchangeRate(Currency.CHF, Currency.USD); Assert.IsTrue(Math.Abs(1.0 / 2.0 - rate) < double.Epsilon); }
public Money Exchange(Money srcMoney, Currency dstCurrency) { if (srcMoney.Currency == dstCurrency) { return(srcMoney); } var rate = _repository.GetExchangeRate(srcMoney.Currency, dstCurrency); return(new Money(srcMoney.Amount * rate, dstCurrency)); }