/// <summary> /// Converts the value of the specified SqlMoney to its equivalent SqlByte representation. /// </summary> /// <param name="value">An SqlMoney.</param> /// <returns>The equivalent SqlByte.</returns> public static SqlByte ToSqlByte(SqlMoney value) { return value.ToSqlByte(); }
public void Conversions() { SqlMoney TestMoney100 = new SqlMoney (100); // ToDecimal Assert.AreEqual ( (decimal)6464.6464, Test1.ToDecimal (), "#M01"); // ToDouble Assert.AreEqual ( (double)6464.6464, Test1.ToDouble (), "#M02"); // ToInt32 Assert.AreEqual ( (int)90000, Test2.ToInt32 (), "#M03"); Assert.AreEqual ( (int)6465, Test1.ToInt32 (), "#M04"); // ToInt64 Assert.AreEqual ( (long)90000, Test2.ToInt64 (), "#M05"); Assert.AreEqual ( (long)6465, Test1.ToInt64 (), "#M06"); // ToSqlBoolean () Assert.IsTrue (Test1.ToSqlBoolean ().Value, "#M07"); Assert.IsTrue (!SqlMoney.Zero.ToSqlBoolean ().Value, "#M08"); Assert.IsTrue (SqlMoney.Null.ToSqlBoolean ().IsNull, "#M09"); // ToSqlByte () Assert.AreEqual ( (byte)100, TestMoney100.ToSqlByte ().Value, "#M10"); try { SqlByte b = (byte)Test2.ToSqlByte (); Assert.Fail ("#M11"); } catch (Exception e) { Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M12"); } // ToSqlDecimal () Assert.AreEqual ( (decimal)6464.6464, Test1.ToSqlDecimal ().Value, "#M13"); Assert.AreEqual ( -45000.0000m, Test4.ToSqlDecimal ().Value, "#M14"); // ToSqlInt16 () Assert.AreEqual ( (short)6465, Test1.ToSqlInt16 ().Value, "#M15"); try { SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value; Assert.Fail ("#M17"); } catch (Exception e) { Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M18"); } // ToSqlInt32 () Assert.AreEqual ( (int)6465, Test1.ToSqlInt32 ().Value, "#M19"); Assert.AreEqual ( (int)(-45000), Test4.ToSqlInt32 ().Value, "#M20"); try { SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32 ().Value; Assert.Fail ("#M21"); } catch (Exception e) { Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M22"); } // ToSqlInt64 () Assert.AreEqual ( (long)6465, Test1.ToSqlInt64 ().Value, "#M23"); Assert.AreEqual ( (long)(-45000), Test4.ToSqlInt64 ().Value, "#M24"); // ToSqlSingle () Assert.AreEqual ( (float)6464.6464, Test1.ToSqlSingle ().Value, "#M25"); // ToSqlString () Assert.AreEqual ( "6464.6464", Test1.ToSqlString ().Value, "#M26"); Assert.AreEqual ( "90000.00", Test2.ToSqlString ().Value, "#M27"); // ToString () Assert.AreEqual ( "6464.6464", Test1.ToString (), "#M28"); Assert.AreEqual ( "90000.00", Test2.ToString (), "#M29"); }
/// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlByte</c> value.</summary> public static SqlByte ToSqlByte(SqlMoney p) { return p.ToSqlByte(); }
public void Conversions() { SqlMoney TestMoney100 = new SqlMoney(100); // ToDecimal Assert.Equal((decimal)6464.6464, _test1.ToDecimal()); // ToDouble Assert.Equal(6464.6464, _test1.ToDouble()); // ToInt32 Assert.Equal(90000, _test2.ToInt32()); Assert.Equal(6465, _test1.ToInt32()); // ToInt64 Assert.Equal(90000, _test2.ToInt64()); Assert.Equal(6465, _test1.ToInt64()); // ToSqlBoolean () Assert.True(_test1.ToSqlBoolean().Value); Assert.True(!SqlMoney.Zero.ToSqlBoolean().Value); Assert.True(SqlMoney.Null.ToSqlBoolean().IsNull); // ToSqlByte () Assert.Equal((byte)100, TestMoney100.ToSqlByte().Value); try { SqlByte b = (byte)_test2.ToSqlByte(); Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlDecimal () Assert.Equal((decimal)6464.6464, _test1.ToSqlDecimal().Value); Assert.Equal(-45000.0000m, _test4.ToSqlDecimal().Value); // ToSqlInt16 () Assert.Equal((short)6465, _test1.ToSqlInt16().Value); try { SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value; Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt32 () Assert.Equal(6465, _test1.ToSqlInt32().Value); Assert.Equal(-45000, _test4.ToSqlInt32().Value); try { SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32().Value; Assert.False(true); } catch (Exception e) { Assert.Equal(typeof(OverflowException), e.GetType()); } // ToSqlInt64 () Assert.Equal(6465, _test1.ToSqlInt64().Value); Assert.Equal(-45000, _test4.ToSqlInt64().Value); // ToSqlSingle () Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value); // ToSqlString () Assert.Equal("6464.6464", _test1.ToSqlString().Value); Assert.Equal("90000.00", _test2.ToSqlString().Value); // ToString () Assert.Equal("6464.6464", _test1.ToString()); Assert.Equal("90000.00", _test2.ToString()); }