public void Conversions() { SqlDouble Test0 = new SqlDouble(0); SqlDouble Test1 = new SqlDouble(250); SqlDouble Test2 = new SqlDouble(64e64); SqlDouble Test3 = new SqlDouble(64e164); SqlDouble TestNull = SqlDouble.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 (OverflowException 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 (OverflowException 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 (OverflowException 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 (OverflowException 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 = Test2.ToSqlInt64().Value; Assert.Fail("#M03F"); } catch (OverflowException 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 = Test2.ToSqlMoney().Value; Assert.Fail("#M03G"); } catch (OverflowException e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04G"); } // ToSqlSingle () Assert.AreEqual((float)250, Test1.ToSqlSingle().Value, "#M01H"); Assert.AreEqual((float)0, Test0.ToSqlSingle().Value, "#M02H"); try { SqlSingle test = Test2.ToSqlSingle().Value; Assert.Fail("#MO3H"); } catch (OverflowException e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "#M04H"); } // ToSqlString () Assert.AreEqual("250", Test1.ToSqlString().Value, "#M01I"); Assert.AreEqual("0", Test0.ToSqlString().Value, "#M02I"); Assert.AreEqual("6.4E+65", Test2.ToSqlString().Value, "#M03I"); // ToString () Assert.AreEqual("250", Test1.ToString(), "#M01J"); Assert.AreEqual("0", Test0.ToString(), "#M02J"); Assert.AreEqual("6.4E+65", Test2.ToString(), "#M03J"); }
public void Conversions() { SqlDouble Test0 = new SqlDouble(0); SqlDouble Test1 = new SqlDouble(250); SqlDouble Test2 = new SqlDouble(64e64); SqlDouble Test3 = new SqlDouble(64e164); SqlDouble TestNull = SqlDouble.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 (OverflowException 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 (OverflowException 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 (OverflowException 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 (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt64 () Assert.Equal(250, Test1.ToSqlInt64().Value); Assert.Equal(0, Test0.ToSqlInt64().Value); try { SqlInt64 test = Test2.ToSqlInt64().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlMoney () Assert.Equal(250.0000M, Test1.ToSqlMoney().Value); Assert.Equal(0, Test0.ToSqlMoney().Value); try { SqlMoney test = Test2.ToSqlMoney().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlSingle () Assert.Equal(250, Test1.ToSqlSingle().Value); Assert.Equal(0, Test0.ToSqlSingle().Value); try { SqlSingle test = Test2.ToSqlSingle().Value; Assert.False(true); } catch (OverflowException e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlString () Assert.Equal("250", Test1.ToSqlString().Value); Assert.Equal("0", Test0.ToSqlString().Value); Assert.Equal("6.4E+65", Test2.ToSqlString().Value); // ToString () Assert.Equal("250", Test1.ToString()); Assert.Equal("0", Test0.ToString()); Assert.Equal("6.4E+65", Test2.ToString()); }
public void Conversions() { SqlDouble test0 = new SqlDouble(0); SqlDouble test1 = new SqlDouble(250); SqlDouble test2 = new SqlDouble(64e64); SqlDouble test3 = new SqlDouble(64e164); SqlDouble TestNull = SqlDouble.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()); // 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>(() => test2.ToSqlInt64()); // ToSqlMoney () Assert.Equal(250M, test1.ToSqlMoney().Value); Assert.Equal(0, test0.ToSqlMoney().Value); Assert.Throws <OverflowException>(() => test2.ToSqlMoney()); // ToSqlSingle () Assert.Equal(250, test1.ToSqlSingle().Value); Assert.Equal(0, test0.ToSqlSingle().Value); Assert.Throws <OverflowException>(() => test2.ToSqlSingle()); // ToSqlString () Assert.Equal(250.ToString(), test1.ToSqlString().Value); Assert.Equal(0.ToString(), test0.ToSqlString().Value); Assert.Equal(6.4E+65.ToString(), test2.ToSqlString().Value); // ToString () Assert.Equal(250.ToString(), test1.ToString()); Assert.Equal(0.ToString(), test0.ToString()); Assert.Equal(6.4E+65.ToString(), test2.ToString()); }