public void CurrencyHasValueEquality() { var currency1 = new Currency("USD"); var currency2 = new Currency("USD"); object boxedCurrency2 = currency2; currency1.Equals(currency2).ShouldBe(true); currency1.Equals(boxedCurrency2).ShouldBe(true); }
public CurrencyMatrixValue GetConversion(Currency source, Currency target) { if (source.Equals(target)) { // This shouldn't happen in sensible code return CurrencyMatrixValue.Create(1.0); } Dictionary<Currency, CurrencyMatrixValue> targets; if (_values.TryGetValue(source, out targets)) { CurrencyMatrixValue ret; if (targets.TryGetValue(target, out ret)) { return ret; } } return null; }
/// <summary> /// this can be reused for whatever currency type you would like to add if you need more in the future /// </summary> /// <param name="currency"></param> /// <param name="userBalance"></param> /// <returns></returns> public static String PrintCurrency(Currency currency, decimal dollarAmmount) { if (currency.Equals(Currency.USD)) { return String.Format("{0:C}", dollarAmmount); } else { decimal exchangeRate = GetTransferRate(Enum.GetName(typeof(Currency), currency)); return String.Format("{0:f2} {1}", (dollarAmmount * exchangeRate), Enum.GetName(typeof(Currency), currency)); } }
public void EqualsTest() { string currencyName = "US"; string symbol = "USD"; Currency target = new Currency(currencyName, symbol); bool actual; actual = target.Equals(null); Assert.AreEqual(false, actual); // currencies are equal if the symbols match currencyName = "United states dollar"; symbol = "USD"; Currency target2 = new Currency(currencyName, symbol); actual = target.Equals(target2); Assert.AreEqual(true, actual); }