public void TestCurrencyAmount() { // test to string CurrencyAmount amount = new CurrencyAmount(123.45); Assert.AreEqual("123.45", amount.ToString()); // test parse amount = CurrencyAmount.Parse("123.45"); Assert.AreEqual("123.45", amount.ToString()); // test add CurrencyAmount amount2 = new CurrencyAmount(543.21); amount = new CurrencyAmount(123.45); Assert.AreEqual("666.66", CurrencyAmount.Add(amount, amount2).ToString()); amount.AddTo(amount2); Assert.AreEqual("666.66", amount.ToString()); // test minus amount2 = new CurrencyAmount(543.21); amount = new CurrencyAmount(123.45); Assert.AreEqual("-419.76", CurrencyAmount.Minus(amount, amount2).ToString()); Assert.AreEqual("419.76", CurrencyAmount.Minus(amount2, amount).ToString()); Assert.AreEqual("0.00", CurrencyAmount.Minus(amount2, amount2).ToString()); // is zero Assert.AreEqual(true, CurrencyAmount.Minus(amount2, amount2).IsZero()); }
public bool Withdraw(Currency currency, decimal amount) { if (amount < 0 || Currency.IsNullOrEmpty(currency)) { return(false); } lock (syncLock) { CurrencyAmount currencyAmount = null; if (wallet.TryGetValue(currency, out currencyAmount)) { currencyAmount.Add(-amount); } else { currencyAmount = new CurrencyAmount(currency, -amount); wallet[currency] = currencyAmount; UICollection?.Add(currencyAmount); } return(true); } }