public void TestSignificantDecimalDigits()
        {
            SimpleMoney money1 = new SimpleMoney(13000123.3349m);

            Assert.AreEqual("$13,000,123.33", money1.ToString());
            // Can also use CurrencyCode string (catch code not found exception)
            SimpleMoney money2 = new SimpleMoney(13000123.335m);

            Assert.AreEqual("$13,000,123.34", money2.ToString());

            // Test Amount rounding
            SimpleMoney money3 = 1.001m;

            Assert.AreEqual(0.40m, (money3 * 0.404).Amount);
            Assert.AreEqual(0.41m, (money3 * 0.40501).Amount);
            Assert.AreEqual(0.41m, (money3 * 0.404999999999999).Amount);
            money3 = 1.0;
            Assert.AreEqual(0.40m, (money3 * 0.404999999999999).Amount);

            //Very large numbers
            //Double is used internally, only 16 digits of accuracy can be guaranteed
            SimpleMoney money6 = 123456789012.34; //14 digits

            money6 *= 1.14;                       //will add another 2 digits of detail
            money6 /= 1.14;
            Assert.AreEqual(money6.Amount, 123456789012.34m);
        }
        public static bool MatchOnMost(AccountLine item, AccountLine candidate)
        {
            SimpleMoney total = item.ActualAmount + candidate.ActualAmount;

            return(item.Date.Equals(candidate.Date) &&
                   total.Equals(SimpleMoney.Zero) &&
                   item.Desc.Equals(candidate.Desc));
        }
Exemple #3
0
        public override void Handle(DepositCommand command)
        {
            SimpleMoney value   = new SimpleMoney(command.Amount);
            var         account = repository.GetExistingById <Account>(command.Id);

            account.Deposit(value);

            repository.Save(account);
        }
Exemple #4
0
 public void ShouldThowUserExceptionOnInsertMoney()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleMoney { Value = (decimal)2.33 };
         repository.TestMinValue.SimpleMoney.Insert(entity);
     }
 }
Exemple #5
0
 public void NormallyInsertMoney()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleMoney { Value = (decimal)2.35 };
         repository.TestMinValue.SimpleMoney.Insert(entity);
     }
 }
        public static SimpleMoney Sum(List <AccountLine> lines)
        {
            SimpleMoney sum = SimpleMoney.Zero;

            foreach (var item in lines)
            {
                sum += item.ActualAmount;
            }
            return(sum);
        }
        public void Comparision()
        {
            // SimpleMoney objects should be equal if their significant digits are the same
            SimpleMoney money1 = new SimpleMoney(5.130000000000001m);
            SimpleMoney money2 = new SimpleMoney(5.13m);
            SimpleMoney money3 = new SimpleMoney(5.12m);

            Assert.IsTrue(money1 == money2);
            Assert.IsTrue(money1.InternalAmount != money2.InternalAmount);
            Assert.IsTrue(money1 != money3);
        }
 public void NormallyInsertMoney()
 {
     using (var scope = TestScope.Create())
     {
         var repository = scope.Resolve <Common.DomRepository>();
         var entity     = new SimpleMoney {
             Value = (decimal)2.35
         };
         repository.TestMinValue.SimpleMoney.Insert(entity);
     }
 }
 public void ShouldThowUserExceptionOnInsertMoney()
 {
     using (var scope = TestScope.Create())
     {
         var repository = scope.Resolve <Common.DomRepository>();
         var entity     = new SimpleMoney {
             Value = (decimal)2.33
         };
         repository.TestMinValue.SimpleMoney.Insert(entity);
     }
 }
        public void TestCreationOfBasicSimpleMoney()
        {
            //Default currency
            SimpleMoney money2 = new SimpleMoney(3000m);

            Assert.AreEqual("USD", money2.CurrencyCode);
            Assert.AreEqual("$", money2.CurrencySymbol);
            Assert.AreEqual("US Dollar", money2.CurrencyName);
            Assert.AreEqual(2, money2.DecimalDigits);

            //Implicit casting of int, decimal and double to SimpleMoney
            SimpleMoney money3  = new SimpleMoney(5.0d);
            SimpleMoney money4  = new SimpleMoney(5.0m);
            SimpleMoney money5  = new SimpleMoney(5);
            SimpleMoney money6  = 5.0d;
            SimpleMoney money7  = 5.0m;
            SimpleMoney money8  = 5;
            SimpleMoney money9  = 5.0f;
            SimpleMoney money10 = 5.0;

            Assert.IsTrue(money3 == money4 && money4 == money5 && money5 == money6 && money6 == money7 && money7 == money8 && money8 == money9 && money9 == money10);
        }
        public void TestOperators()
        {
            SimpleMoney money1 = new SimpleMoney(20);

            Assert.AreEqual("$6.67", (money1 / 3).ToString());
            Assert.AreEqual("$6.67", (money1 / 3m).ToString());
            Assert.AreEqual("$6.67", (money1 / 3.0).ToString());
            Assert.AreEqual("$0.00", (money1 * (1 / 3)).ToString());
            Assert.AreEqual("$6.67", (money1 * (1m / 3m)).ToString());
            Assert.AreEqual("$6.67", (money1 * (1d / 3d)).ToString());
            Assert.AreEqual("$3.33", (money1 / 6).ToString());
            Assert.AreEqual("$3.33", (money1 * (1.0 / 6.0)).ToString());

            // Operators use internal value
            SimpleMoney money2 = new SimpleMoney(0.01m);

            Assert.AreEqual("$0.01", (money2 / 2).ToString());

            SimpleMoney money3 = new SimpleMoney(3);
            SimpleMoney money4 = new SimpleMoney(1d / 3d);
            SimpleMoney money5 = new SimpleMoney(6);
            SimpleMoney money6 = new SimpleMoney(1d / 6d);

            Assert.AreEqual("$6.67", (money1 / money3).ToString());
            Assert.AreEqual("$6.67", (money1 * money4).ToString());
            Assert.AreEqual("$3.33", (money1 / money5).ToString());
            Assert.AreEqual("$3.33", (money1 * money6).ToString());
            Assert.IsTrue((money3 + money5).Amount == 9);
            Assert.IsTrue((money5 - money3).Amount == 3);
            //Using implicit casting
            Assert.IsTrue(money3 == 3);
            Assert.IsTrue(money5 - money3 == 3);
            Assert.IsTrue(money3 + 3d == money5);
            Assert.IsTrue(money5 - 3 == money3);
            Assert.IsTrue(money5 + 2 == 8);
            Assert.IsTrue(money5 - 2 == 4d);
            Assert.IsTrue(2m + money3.Amount == 5);
        }
        public void TestAllocation()
        {
            #region +ve penny allocation
            SimpleMoney   money1          = new SimpleMoney(10);
            SimpleMoney   result1         = new SimpleMoney(3.34);
            SimpleMoney   result2         = new SimpleMoney(3.33);
            SimpleMoney[] allocatedMoney1 = money1.Allocate(3);
            SimpleMoney   total1          = new SimpleMoney();
            for (int i = 0; i < allocatedMoney1.Length; i++)
            {
                total1 += allocatedMoney1[i];
            }

            Assert.AreEqual(money1, total1);
            Assert.AreEqual(result1, allocatedMoney1[0]);
            Assert.AreEqual(result2, allocatedMoney1[1]);
            Assert.AreEqual(result2, allocatedMoney1[2]);
            #endregion

            #region -ve penny allocation
            SimpleMoney money2  = new SimpleMoney(0.09m);
            SimpleMoney result3 = new SimpleMoney(0.02);
            SimpleMoney result4 = new SimpleMoney(0.01);

            SimpleMoney[] allocatedMoney2 = money2.Allocate(5);
            SimpleMoney   total2          = new SimpleMoney();
            for (int i = 0; i < allocatedMoney2.Length; i++)
            {
                total2 += allocatedMoney2[i];
            }
            Assert.AreEqual(money2, total2);
            Assert.AreEqual(result3, allocatedMoney2[0]);
            Assert.AreEqual(result3, allocatedMoney2[1]);
            Assert.AreEqual(result3, allocatedMoney2[2]);
            Assert.AreEqual(result3, allocatedMoney2[3]);
            Assert.AreEqual(result4, allocatedMoney2[4]);
            #endregion
        }
Exemple #13
0
 public void NormallyInsertMoney()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleMoney { Value = (decimal)2.30 };
         repository.TestMaxValue.SimpleMoney.Insert(new[] { entity });
     }
 }
Exemple #14
0
 public void ShouldThowUserExceptionOnInsertMoney()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleMoney { Value = (decimal)3.33 };
         repository.TestMaxValue.SimpleMoney.Insert(new[] { entity });
     }
 }
Exemple #15
0
 public AccountLine(string date, string reference, string type, string desc, string amount, SimpleMoney actualAmount, string accountName)
 {
     // TODO: Complete member initialization
     this.Date         = date;
     this.Reference    = reference;
     this.Type         = type;
     this.Desc         = desc;
     this.Amount       = amount;
     this.ActualAmount = actualAmount;
     this.AccountName  = accountName;
 }
Exemple #16
0
 public void NormallyInsertMoney()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleMoney { Value = (decimal)2.30 };
         repository.TestMaxValue.SimpleMoney.Insert(new[] { entity });
     }
 }
Exemple #17
0
 public void ShouldThowUserExceptionOnInsertMoney()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleMoney { Value = (decimal)3.33 };
         repository.TestMaxValue.SimpleMoney.Insert(new[] { entity });
     }
 }