Пример #1
0
        public void ArithmeticMethods()
        {
            SqlMoney testMoney2 = new SqlMoney(2);

            // Add
            Assert.Equal(96464.6464m, SqlMoney.Add(_test1, _test2));
            Assert.Equal(180000m, SqlMoney.Add(_test2, _test2));
            Assert.Equal(45000m, SqlMoney.Add(_test2, _test4));

            Assert.Throws <OverflowException>(() => SqlMoney.Add(SqlMoney.MaxValue, _test2));

            Assert.Throws <DivideByZeroException>(() => SqlMoney.Divide(_test2, SqlMoney.Zero));

            // Multiply
            Assert.Equal(581818176m, SqlMoney.Multiply(_test1, _test2));
            Assert.Equal(-4050000000m, SqlMoney.Multiply(_test3, _test4));

            Assert.Throws <OverflowException>(() => SqlMoney.Multiply(SqlMoney.MaxValue, _test2));

            // Subtract
            Assert.Equal(0m, SqlMoney.Subtract(_test2, _test3));
            Assert.Equal(83535.3536m, SqlMoney.Subtract(_test2, _test1));

            Assert.Throws <OverflowException>(() => SqlMoney.Subtract(SqlMoney.MinValue, _test2));
        }
Пример #2
0
        public void ArithmeticMethods()
        {
            SqlMoney TestMoney2 = new SqlMoney(2);

            // Add
            Assert.AreEqual((SqlMoney)96464.6464m, SqlMoney.Add(Test1, Test2), "#D01");
            Assert.AreEqual((SqlMoney)180000m, SqlMoney.Add(Test2, Test2), "#D02");
            Assert.AreEqual((SqlMoney)45000m, SqlMoney.Add(Test2, Test4), "#D03");

            try
            {
                SqlMoney test = SqlMoney.Add(SqlMoney.MaxValue, Test2);
                Assert.Fail("#D04");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D05");
            }

            // Divide
            Assert.AreEqual((SqlMoney)45000m, SqlMoney.Divide(Test2, TestMoney2), "#D06");
            try
            {
                SqlMoney test = SqlMoney.Divide(Test2, SqlMoney.Zero);
                Assert.Fail("#D07");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(DivideByZeroException),
                                e.GetType(), "#D08");
            }

            // Multiply
            Assert.AreEqual((SqlMoney)581818176m, SqlMoney.Multiply(Test1, Test2), "#D09");
            Assert.AreEqual((SqlMoney)(-4050000000m), SqlMoney.Multiply(Test3, Test4), "#D10");

            try
            {
                SqlMoney test = SqlMoney.Multiply(SqlMoney.MaxValue, Test2);
                Assert.Fail("#D11");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D12");
            }

            // Subtract
            Assert.AreEqual((SqlMoney)0m, SqlMoney.Subtract(Test2, Test3), "#D13");
            Assert.AreEqual((SqlMoney)83535.3536m, SqlMoney.Subtract(Test2, Test1), "#D14");

            try
            {
                SqlMoney test = SqlMoney.Subtract(SqlMoney.MinValue, Test2);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#D15");
            }
        }
Пример #3
0
        public void ArithmeticMethods()
        {
            SqlMoney TestMoney2 = new SqlMoney(2);

            // Add
            Assert.Equal(96464.6464m, SqlMoney.Add(_test1, _test2));
            Assert.Equal(180000m, SqlMoney.Add(_test2, _test2));
            Assert.Equal(45000m, SqlMoney.Add(_test2, _test4));

            try
            {
                SqlMoney test = SqlMoney.Add(SqlMoney.MaxValue, _test2);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Divide
            Assert.Equal(45000m, SqlMoney.Divide(_test2, TestMoney2));
            try
            {
                SqlMoney test = SqlMoney.Divide(_test2, SqlMoney.Zero);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(DivideByZeroException), e.GetType());
            }

            // Multiply
            Assert.Equal(581818176m, SqlMoney.Multiply(_test1, _test2));
            Assert.Equal(-4050000000m, SqlMoney.Multiply(_test3, _test4));

            try
            {
                SqlMoney test = SqlMoney.Multiply(SqlMoney.MaxValue, _test2);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // Subtract
            Assert.Equal(0m, SqlMoney.Subtract(_test2, _test3));
            Assert.Equal(83535.3536m, SqlMoney.Subtract(_test2, _test1));

            try
            {
                SqlMoney test = SqlMoney.Subtract(SqlMoney.MinValue, _test2);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }
        }