Пример #1
0
        public void Conversions()
        {
            SqlSingle test0    = new SqlSingle(0);
            SqlSingle test1    = new SqlSingle(250);
            SqlSingle test2    = new SqlSingle(64E+16);
            SqlSingle test3    = new SqlSingle(64E+30);
            SqlSingle TestNull = SqlSingle.Null;

            // ToSqlBoolean ()
            Assert.True(test1.ToSqlBoolean().Value);
            Assert.False(test0.ToSqlBoolean().Value);
            Assert.True(TestNull.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)250, test1.ToSqlByte().Value);
            Assert.Equal((byte)0, test0.ToSqlByte().Value);

            Assert.Throws <OverflowException>(() => test2.ToSqlByte());

            // ToSqlDecimal ()
            Assert.Equal(250M, test1.ToSqlDecimal().Value);
            Assert.Equal(0, test0.ToSqlDecimal().Value);

            Assert.Throws <OverflowException>(() => test3.ToSqlDecimal().Value);

            // ToSqlInt16 ()
            Assert.Equal((short)250, test1.ToSqlInt16().Value);
            Assert.Equal((short)0, test0.ToSqlInt16().Value);

            Assert.Throws <OverflowException>(() => test2.ToSqlInt16());

            // ToSqlInt32 ()
            Assert.Equal(250, test1.ToSqlInt32().Value);
            Assert.Equal(0, test0.ToSqlInt32().Value);

            Assert.Throws <OverflowException>(() => test2.ToSqlInt32());

            // ToSqlInt64 ()
            Assert.Equal(250, test1.ToSqlInt64().Value);
            Assert.Equal(0, test0.ToSqlInt64().Value);

            Assert.Throws <OverflowException>(() => test3.ToSqlInt64());

            // ToSqlMoney ()
            Assert.Equal(250.0000M, test1.ToSqlMoney().Value);
            Assert.Equal(0, test0.ToSqlMoney().Value);

            Assert.Throws <OverflowException>(() => test2.ToSqlMoney());


            // ToSqlString ()
            Assert.Equal(250.ToString(), test1.ToSqlString().Value);
            Assert.Equal(0.ToString(), test0.ToSqlString().Value);
            Assert.Equal(6.4E+17.ToString(), test2.ToSqlString().Value);

            // ToString ()
            Assert.Equal(250.ToString(), test1.ToString());
            Assert.Equal(0.ToString(), test0.ToString());
            Assert.Equal(6.4E+17.ToString(), test2.ToString());
        }
Пример #2
0
        public void Conversions()
        {
            SqlSingle Test0    = new SqlSingle(0);
            SqlSingle Test1    = new SqlSingle(250);
            SqlSingle Test2    = new SqlSingle(64E+16);
            SqlSingle Test3    = new SqlSingle(64E+30);
            SqlSingle TestNull = SqlSingle.Null;

            // ToSqlBoolean ()
            Assert.IsTrue(Test1.ToSqlBoolean().Value, "#M01A");
            Assert.IsTrue(!Test0.ToSqlBoolean().Value, "#M02A");
            Assert.IsTrue(TestNull.ToSqlBoolean().IsNull, "#M03A");

            // ToSqlByte ()
            Assert.AreEqual((byte)250, Test1.ToSqlByte().Value, "#M01B");
            Assert.AreEqual((byte)0, Test0.ToSqlByte().Value, "#M02B");

            try {
                SqlByte b = (byte)Test2.ToSqlByte();
                Assert.Fail("#M03B");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04B");
            }

            // ToSqlDecimal ()
            Assert.AreEqual(250.00000000000000M, Test1.ToSqlDecimal().Value, "#M01C");
            Assert.AreEqual((decimal)0, Test0.ToSqlDecimal().Value, "#M02C");

            try {
                SqlDecimal test = Test3.ToSqlDecimal().Value;
                Assert.Fail("#M03C");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04C");
            }

            // ToSqlInt16 ()
            Assert.AreEqual((short)250, Test1.ToSqlInt16().Value, "#M01D");
            Assert.AreEqual((short)0, Test0.ToSqlInt16().Value, "#M02D");

            try {
                SqlInt16 test = Test2.ToSqlInt16().Value;
                Assert.Fail("#M03D");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04D");
            }

            // ToSqlInt32 ()
            Assert.AreEqual((int)250, Test1.ToSqlInt32().Value, "#M01E");
            Assert.AreEqual((int)0, Test0.ToSqlInt32().Value, "#M02E");

            try {
                SqlInt32 test = Test2.ToSqlInt32().Value;
                Assert.Fail("#M03E");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04E");
            }

            // ToSqlInt64 ()
            Assert.AreEqual((long)250, Test1.ToSqlInt64().Value, "#M01F");
            Assert.AreEqual((long)0, Test0.ToSqlInt64().Value, "#M02F");

            try {
                SqlInt64 test = Test3.ToSqlInt64().Value;
                Assert.Fail("#M03F");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04F");
            }

            // ToSqlMoney ()
            Assert.AreEqual(250.0000M, Test1.ToSqlMoney().Value, "#M01G");
            Assert.AreEqual((decimal)0, Test0.ToSqlMoney().Value, "#M02G");

            try {
                SqlMoney test = Test3.ToSqlMoney().Value;
                Assert.Fail("#M03G");
            } catch (Exception e) {
                Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04G");
            }


            // ToSqlString ()
            Assert.AreEqual("250", Test1.ToSqlString().Value, "#M01H");
            Assert.AreEqual("0", Test0.ToSqlString().Value, "#M02H");
            Assert.AreEqual("6.4E+17", Test2.ToSqlString().Value, "#M03H");

            // ToString ()
            Assert.AreEqual("250", Test1.ToString(), "#M01I");
            Assert.AreEqual("0", Test0.ToString(), "#M02I");
            Assert.AreEqual("6.4E+17", Test2.ToString(), "#M03I");
        }
Пример #3
0
        public void Conversions()
        {
            SqlSingle Test0    = new SqlSingle(0);
            SqlSingle Test1    = new SqlSingle(250);
            SqlSingle Test2    = new SqlSingle(64E+16);
            SqlSingle Test3    = new SqlSingle(64E+30);
            SqlSingle TestNull = SqlSingle.Null;

            // ToSqlBoolean ()
            Assert.True(Test1.ToSqlBoolean().Value);
            Assert.True(!Test0.ToSqlBoolean().Value);
            Assert.True(TestNull.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Assert.Equal((byte)250, Test1.ToSqlByte().Value);
            Assert.Equal((byte)0, Test0.ToSqlByte().Value);

            try
            {
                SqlByte b = (byte)Test2.ToSqlByte();
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlDecimal ()
            Assert.Equal(250.00000000000000M, Test1.ToSqlDecimal().Value);
            Assert.Equal(0, Test0.ToSqlDecimal().Value);

            try
            {
                SqlDecimal test = Test3.ToSqlDecimal().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt16 ()
            Assert.Equal((short)250, Test1.ToSqlInt16().Value);
            Assert.Equal((short)0, Test0.ToSqlInt16().Value);

            try
            {
                SqlInt16 test = Test2.ToSqlInt16().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt32 ()
            Assert.Equal(250, Test1.ToSqlInt32().Value);
            Assert.Equal(0, Test0.ToSqlInt32().Value);

            try
            {
                SqlInt32 test = Test2.ToSqlInt32().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlInt64 ()
            Assert.Equal(250, Test1.ToSqlInt64().Value);
            Assert.Equal(0, Test0.ToSqlInt64().Value);

            try
            {
                SqlInt64 test = Test3.ToSqlInt64().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }

            // ToSqlMoney ()
            Assert.Equal(250.0000M, Test1.ToSqlMoney().Value);
            Assert.Equal(0, Test0.ToSqlMoney().Value);

            try
            {
                SqlMoney test = Test3.ToSqlMoney().Value;
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(OverflowException), e.GetType());
            }


            // ToSqlString ()
            Assert.Equal(250.ToString(), Test1.ToSqlString().Value);
            Assert.Equal(0.ToString(), Test0.ToSqlString().Value);
            Assert.Equal(6.4E+17.ToString(), Test2.ToSqlString().Value);

            // ToString ()
            Assert.Equal(250.ToString(), Test1.ToString());
            Assert.Equal(0.ToString(), Test0.ToString());
            Assert.Equal(6.4E+17.ToString(), Test2.ToString());
        }