Esempio n. 1
0
        public void TestSimpleAddition()
        {
            Money            five = Money.Dollar(5);
            IMoneyExpression sum  = five.Plus(five);

            Bank  bank    = new Bank();
            Money reduced = bank.Reduce(sum, "USD");

            Assert.Equal(Money.Dollar(10), reduced);
        }
Esempio n. 2
0
        public void TestPlusReturnsSum()
        {
            Money            five   = Money.Dollar(5);
            IMoneyExpression result = five.Plus(five);

            Sum sum = (Sum)result;

            Assert.Equal(five, sum.Augend);
            Assert.Equal(five, sum.Addend);
        }
Esempio n. 3
0
        public void TestMixedAddition()
        {
            IMoneyExpression fiveBucks = Money.Dollar(5);
            IMoneyExpression 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);
        }
Esempio n. 4
0
        public void sum_of_two_franc_with_one_dollar__equals_to_two_dollar() // 2 CHF + 1 USD = 2 USD
        {
            IMoneyExpression franc  = Money.Franc(2);
            IMoneyExpression dollar = Money.Dollar(1);
            var bank = new Bank();

            bank.AddRate("USD", "CHF", 2);
            bank.AddRate("CHF", "USD", 0.5m);

            var reducedAmount = bank.Reduce(dollar.Plus(franc), "USD");

            var expected = Money.Dollar(2);

            reducedAmount.Should().Be(expected);
        }
Esempio n. 5
0
        public void TestSumPlusMoney()
        {
            IMoneyExpression fiveBucks = Money.Dollar(5);
            IMoneyExpression tenFrancs = Money.Franc(10);

            Bank bank = new Bank();

            bank.AddRate("CHF", "USD", 2);

            IMoneyExpression sum =
                new Sum(fiveBucks, tenFrancs).Plus(fiveBucks);

            Money result = bank.Reduce(sum, "USD");

            Assert.Equal(Money.Dollar(15), result);
        }
Esempio n. 6
0
 public Money Reduce(IMoneyExpression expression, string toCurrency)
 {
     return(expression.Reduce(toCurrency, this));
 }
Esempio n. 7
0
 private static Money Evaluate(IMoneyExpression moneyExpression, Func <Money, Money> round, Func <IMoneyExpression, Money> total)
 => round(total(moneyExpression));
 public static IMoneyExpression Subtract(this IMoneyExpression minuend, IMoneyExpression subtrahend)
 => new MoneySum(minuend, new MoneyProduct(subtrahend, -1));
Esempio n. 9
0
 public IMoneyExpression Plus(IMoneyExpression addend)
 {
     return(new Sum(this, addend));
 }
Esempio n. 10
0
 public static Money Evaluate(this IMoneyExpression moneyExpression, Option <MoneyEvaluationContext> context = default)
 => Evaluate(moneyExpression, Round(context), CalculateTotal(context));
Esempio n. 11
0
 public IMoneyExpression Plus(IMoneyExpression moneyExpression)
 {
     return(new Sum(this, moneyExpression));
 }
 public static IMoneyExpression Add(this IMoneyExpression augend, IMoneyExpression addend)
 => new MoneySum(augend, addend);
Esempio n. 13
0
 public static IEnumerable <IMoneyExpression> Distribute(this IMoneyExpression moneyExpression, int numberOfSlices, Option <decimal> precision = default)
 => moneyExpression.Distribute(Enumerable.Repeat(element: 1, count: numberOfSlices), precision);
Esempio n. 14
0
 public static IEnumerable <IMoneyExpression> Distribute(this IMoneyExpression moneyExpression, IEnumerable <int> factors, Option <decimal> precision = default)
 => new MoneyDistribution(moneyExpression, factors, precision);
Esempio n. 15
0
 public static IMoneyExpression Multiply(this IMoneyExpression multiplicand, decimal multiplier)
 => new MoneyProduct(multiplicand, multiplier);
 public static IMoneyExpression Divide(this IMoneyExpression dividend, decimal divisor)
 => new MoneyProduct(dividend, 1.0m / divisor);
Esempio n. 17
0
 public static string ToHumanReadable(this IMoneyExpression moneyExpression)
 => moneyExpression.Accept(ToHumanReadableVisitor.Instance);
Esempio n. 18
0
 public Sum(IMoneyExpression augEnd, IMoneyExpression addEnd)
 {
     AugEnd = augEnd;
     AddEnd = addEnd;
 }
Esempio n. 19
0
 public Money Reduce(IMoneyExpression source, String to)
 {
     return(source.Reduce(this, to));
 }