ToSqlMoney() public method

public ToSqlMoney ( ) : SqlMoney
return SqlMoney
Beispiel #1
0
 /// <summary>
 /// Converts the value of the specified SqlInt16 to its equivalent SqlMoney representation.
 /// </summary>
 /// <param name="value">An SqlInt16.</param>
 /// <returns>The equivalent SqlMoney.</returns>
 public static SqlMoney ToSqlMoney(SqlInt16 value) { return value.ToSqlMoney(); }
                public void Conversions()
                {
                        SqlInt16 Test12 = new SqlInt16 (12);
                        SqlInt16 Test0 = new SqlInt16 (0);
                        SqlInt16 TestNull = SqlInt16.Null;
                        SqlInt16 Test1000 = new SqlInt16 (1000);
                        SqlInt16 Test288 = new SqlInt16(288);

                        // ToSqlBoolean ()
                        Assert ("TestA#1", Test12.ToSqlBoolean ().Value);
                        Assert ("TestA#2", !Test0.ToSqlBoolean ().Value);
                        Assert ("TestA#3", TestNull.ToSqlBoolean ().IsNull);

                        // ToSqlByte ()
                        AssertEquals ("TestB#1", (byte)12, Test12.ToSqlByte ().Value);
                        AssertEquals ("TestB#2", (byte)0, Test0.ToSqlByte ().Value);

                        try {
                                SqlByte b = (byte)Test1000.ToSqlByte ();
                                Fail ("TestB#4");
                        } catch (Exception e) {
                                AssertEquals ("TestB#5", typeof (OverflowException), e.GetType ());
                        }

                        // ToSqlDecimal ()
                        AssertEquals ("TestC#1", (decimal)12, Test12.ToSqlDecimal ().Value);
                        AssertEquals ("TestC#2", (decimal)0, Test0.ToSqlDecimal ().Value);
                        AssertEquals ("TestC#3", (decimal)288, Test288.ToSqlDecimal ().Value);

                        // ToSqlDouble ()
                        AssertEquals ("TestD#1", (double)12, Test12.ToSqlDouble ().Value);
                        AssertEquals ("TestD#2", (double)0, Test0.ToSqlDouble ().Value);
                        AssertEquals ("TestD#3", (double)1000, Test1000.ToSqlDouble ().Value);

                        // ToSqlInt32 ()
                        AssertEquals ("TestE#1", (int)12, Test12.ToSqlInt32 ().Value);
                        AssertEquals ("TestE#2", (int)0, Test0.ToSqlInt32 ().Value);
                        AssertEquals ("TestE#3", (int)288, Test288.ToSqlInt32().Value);

                        // ToSqlInt64 ()
                        AssertEquals ("TestF#1", (long)12, Test12.ToSqlInt64 ().Value);
                        AssertEquals ("TestF#2", (long)0, Test0.ToSqlInt64 ().Value);
                        AssertEquals ("TestF#3", (long)288, Test288.ToSqlInt64 ().Value);

                        // ToSqlMoney ()
                        AssertEquals ("TestG#1", 12.0000M, Test12.ToSqlMoney ().Value);
                        AssertEquals ("TestG#2", (decimal)0, Test0.ToSqlMoney ().Value);
                        AssertEquals ("TestG#3", 288.0000M, Test288.ToSqlMoney ().Value);

                        // ToSqlSingle ()
                        AssertEquals ("TestH#1", (float)12, Test12.ToSqlSingle ().Value);
                        AssertEquals ("TestH#2", (float)0, Test0.ToSqlSingle ().Value);
                        AssertEquals ("TestH#3", (float)288, Test288.ToSqlSingle().Value);

                        // ToSqlString ()
                        AssertEquals ("TestI#1", "12", Test12.ToSqlString ().Value);
                        AssertEquals ("TestI#2", "0", Test0.ToSqlString ().Value);
                        AssertEquals ("TestI#3", "288", Test288.ToSqlString ().Value);

                        // ToString ()
                        AssertEquals ("TestJ#1", "12", Test12.ToString ());
                        AssertEquals ("TestJ#2", "0", Test0.ToString ());
                        AssertEquals ("TestJ#3", "288", Test288.ToString ());
                }
		/// <summary>Converts the value from <c>SqlInt16</c> to an equivalent <c>SqlMoney</c> value.</summary>
		public static SqlMoney ToSqlMoney(SqlInt16   p) { return p.ToSqlMoney();                                            }
Beispiel #4
0
        public void Conversions()
        {
            SqlInt16 Test12 = new SqlInt16(12);
            SqlInt16 Test0 = new SqlInt16(0);
            SqlInt16 TestNull = SqlInt16.Null;
            SqlInt16 Test1000 = new SqlInt16(1000);
            SqlInt16 Test288 = new SqlInt16(288);

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

            // ToSqlByte ()
            Assert.Equal((byte)12, Test12.ToSqlByte().Value);
            Assert.Equal((byte)0, Test0.ToSqlByte().Value);

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

            // ToSqlDecimal ()
            Assert.Equal(12, Test12.ToSqlDecimal().Value);
            Assert.Equal(0, Test0.ToSqlDecimal().Value);
            Assert.Equal(288, Test288.ToSqlDecimal().Value);

            // ToSqlDouble ()
            Assert.Equal(12, Test12.ToSqlDouble().Value);
            Assert.Equal(0, Test0.ToSqlDouble().Value);
            Assert.Equal(1000, Test1000.ToSqlDouble().Value);

            // ToSqlInt32 ()
            Assert.Equal(12, Test12.ToSqlInt32().Value);
            Assert.Equal(0, Test0.ToSqlInt32().Value);
            Assert.Equal(288, Test288.ToSqlInt32().Value);

            // ToSqlInt64 ()
            Assert.Equal(12, Test12.ToSqlInt64().Value);
            Assert.Equal(0, Test0.ToSqlInt64().Value);
            Assert.Equal(288, Test288.ToSqlInt64().Value);

            // ToSqlMoney ()
            Assert.Equal(12.0000M, Test12.ToSqlMoney().Value);
            Assert.Equal(0, Test0.ToSqlMoney().Value);
            Assert.Equal(288.0000M, Test288.ToSqlMoney().Value);

            // ToSqlSingle ()
            Assert.Equal(12, Test12.ToSqlSingle().Value);
            Assert.Equal(0, Test0.ToSqlSingle().Value);
            Assert.Equal(288, Test288.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("12", Test12.ToSqlString().Value);
            Assert.Equal("0", Test0.ToSqlString().Value);
            Assert.Equal("288", Test288.ToSqlString().Value);

            // ToString ()
            Assert.Equal("12", Test12.ToString());
            Assert.Equal("0", Test0.ToString());
            Assert.Equal("288", Test288.ToString());
        }