public static decimal CurrencyConvert(decimal amount, CurrencyType fromCur, CurrencyType toCur) { decimal converted = 0.0M; ConvertibleCurrency currency = new ConvertibleCurrency(fromCur, amount); converted = currency.ConvertTo(toCur); return(converted); }
public void ConvertTo() { ConvertibleCurrency currency; decimal result; decimal expected; currency = new ConvertibleCurrency(new USCurrency(), 100.0M); result = currency.ConvertTo(new USCurrency()); Assert.AreEqual(100.0M, result, "US to US should be no change"); currency = new ConvertibleCurrency(new AUSCurrency(), 100.0M); result = currency.ConvertTo(new UKCurrency()); expected = 100.0M / 2 * 0.5M; Assert.AreEqual(expected, result, "AUS to UK incorrect result"); }
public void ConvertTo() { ConvertibleCurrency currency; decimal result; decimal expected; currency = new ConvertibleCurrency(new UsdCurrency(), 100.0M); result = currency.ConvertTo(new UsdCurrency()); Assert.AreEqual(100.0M, result, "USD to USD no cambia"); currency = new ConvertibleCurrency(new EurCurrency(), 100.0M); result = currency.ConvertTo(new PenCurrency()); expected = 100.0M / (decimal)4.16; Assert.AreEqual(expected, result, " EUR a PEN resultado incorrecto"); }
public void ConvertTo() { ConvertibleCurrency currency; decimal result; decimal expected; currency = new ConvertibleCurrency(new USDCurrency(), 100.0M); result = currency.ConvertTo(new USDCurrency()); Assert.AreEqual(100.0M, result, "USD to USD should be no change"); currency = new ConvertibleCurrency(new EURCurrency(), 100.0M); result = currency.ConvertTo(new PENCurrency()); expected = 100.0M / 0.85M * 3.53M; Assert.AreEqual(expected, result, "EUR to PEN incorrect result"); }