public void TestIdentityRate() { Bank bank = new Bank(); var actual = bank.Rate("USD", "USD"); Assert.Equal(1, actual); }
public void TestReduceMoney() { Bank bank = new Bank(); Money actual = bank.Reduce(Money.Dollar(1), "USD"); Assert.Equal(Money.Dollar(1), actual); }
public void TestReduceSum() { Expression sum = new Sum(Money.Dollar(3), Money.Dollar(4)); Bank bank = new Bank(); Money actual = bank.Reduce(sum, "USD"); Assert.Equal(Money.Dollar(7), actual); }
public void TestReduceMoneyDifferentCurrency() { Bank bank = new Bank(); bank.AddRate("CHF", "USD", 2); Money actual = bank.Reduce(Money.Franc(2), "USD"); Assert.Equal(Money.Dollar(1), actual); }
public void TestSumTimes() { Expression fiveBucks = Money.Dollar(5); Expression tenFrancs = Money.Franc(10); Bank bank = new Bank(); bank.AddRate("CHF", "USD", 2); Expression sum = new Sum(fiveBucks, tenFrancs).Times(2); Money actual = bank.Reduce(sum, "USD"); Assert.Equal(Money.Dollar(20), actual); }
public void TestSimpleAddition() { Money five = Money.Dollar(5); Expression sum = five.Plus(five); var bank = new Bank(); Money reduced = bank.Reduce(sum, "USD"); Assert.Equal(Money.Dollar(10), reduced); }
public void TestMixedAddition() { Expression fiveBucks = Money.Dollar(5); Expression tenFrancs = Money.Franc(10); Bank bank = new Bank(); bank.AddRate("CHF", "USD", 2); Money actual = bank.Reduce(fiveBucks.Plus(tenFrancs), "USD"); Assert.Equal(Money.Dollar(10), actual); }
public Money Reduce(Bank bank, string toCurrency) { int amount = Augend.Reduce(bank, toCurrency).Amount + Addend.Reduce(bank, toCurrency).Amount; return new Money(amount, toCurrency); }
public Money Reduce(Bank bank, string toCurrency) { int rate = bank.Rate(Currency, toCurrency); return new Money(Amount / rate, toCurrency); }