예제 #1
0
        public void TestPlusReturnsSum()
        {
            Money           five   = Money.Dollar(5);
            MoneyExpression result = five.Plus(five);
            Sum             sum    = (Sum)result;

            Assert.Equal(five, sum.augend);
            Assert.Equal(five, sum.addend);
        }
예제 #2
0
        public void TestSimpleAddition()
        {
            Money           five    = Money.Dollar(5);
            MoneyExpression sum     = five.Plus(five);
            Bank            bank    = new Bank();
            Money           reduced = bank.Reduce(sum, "USD");

            Assert.Equal(Money.Dollar(10), reduced);
        }
예제 #3
0
        public void TestMixedAddition()
        {
            MoneyExpression fiveBucks = Money.Dollar(5);
            MoneyExpression tenFrancs = Money.Franc(10);
            Bank            bank      = new Bank();

            bank.AddRate("CHF", "USD", 2);
            Money result = bank.Reduce(fiveBucks.Plus(tenFrancs), "USD");

            Assert.Equal(Money.Dollar(10), result);
        }
예제 #4
0
        public void TestSumTimes()
        {
            MoneyExpression fiveBucks = Money.Dollar(5);
            MoneyExpression tenFrancs = Money.Franc(10);
            Bank            bank      = new Bank();

            bank.AddRate("CHF", "USD", 2);
            MoneyExpression sum    = new Sum(fiveBucks, tenFrancs).Times(2);
            Money           result = bank.Reduce(sum, "USD");

            Assert.Equal(Money.Dollar(20), result);
        }
예제 #5
0
 public MoneyExpression Plus(MoneyExpression addend)
 {
     return(new Sum(this, addend));
 }
예제 #6
0
 public Money Reduce(MoneyExpression source, string to)
 {
     return(source.Reduce(this, to));
 }
예제 #7
0
 public Sum(MoneyExpression augend, MoneyExpression addend)
 {
     this.augend = augend;
     this.addend = addend;
 }