ToSqlByte() public method

public ToSqlByte ( ) : SqlByte
return SqlByte
Exemplo n.º 1
0
 /// <summary>
 /// Converts the value of the specified SqlDecimal to its equivalent SqlByte representation.
 /// </summary>
 /// <param name="value">An SqlDecimal.</param>
 /// <returns>The equivalent SqlByte.</returns>
 public static SqlByte ToSqlByte(SqlDecimal value) { return value.ToSqlByte(); }
Exemplo n.º 2
0
		/// <summary>Converts the value from <c>SqlDecimal</c> to an equivalent <c>SqlByte</c> value.</summary>
		public static SqlByte ToSqlByte(SqlDecimal p) { return p.ToSqlByte();                                              }
Exemplo n.º 3
0
        public void Conversions()
        {
            // ToDouble
            Assert.Equal(6464.6464, _test1.ToDouble());

            // ToSqlBoolean ()
            Assert.Equal(new SqlBoolean(1), _test1.ToSqlBoolean());

            SqlDecimal Test = new SqlDecimal(0);
            Assert.True(!Test.ToSqlBoolean().Value);

            Test = new SqlDecimal(0);
            Assert.True(!Test.ToSqlBoolean().Value);
            Assert.True(SqlDecimal.Null.ToSqlBoolean().IsNull);

            // ToSqlByte ()
            Test = new SqlDecimal(250);
            Assert.Equal((byte)250, Test.ToSqlByte().Value);

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

            // ToSqlDouble ()
            Assert.Equal(6464.6464, _test1.ToSqlDouble());

            // ToSqlInt16 ()
            Assert.Equal((short)1, new SqlDecimal(1).ToSqlInt16().Value);

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

            // ToSqlInt32 () 
            // LAMESPEC: 6464.6464 --> 64646464 ??? with windows
            // MS.NET seems to return the first 32 bit integer (i.e. 
            // Data [0]) but we don't have to follow such stupidity.
            //			Assert.Equal ((int)64646464, Test1.ToSqlInt32 ().Value);
            //			Assert.Equal ((int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);

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

            // ToSqlInt64 ()
            Assert.Equal(6464, _test1.ToSqlInt64().Value);

            // ToSqlMoney ()
            Assert.Equal((decimal)6464.6464, _test1.ToSqlMoney().Value);

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

            // ToSqlSingle ()
            Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value);

            // ToSqlString ()
            Assert.Equal("6464.6464", _test1.ToSqlString().Value);

            // ToString ()
            Assert.Equal("6464.6464", _test1.ToString());
            // NOT WORKING
            Assert.Equal("792281625142643375935439503350000.00", SqlDecimal.Multiply(_test5, _test2).ToString());
            Assert.Equal(1E+38, SqlDecimal.MaxValue.ToSqlDouble());
        }
Exemplo n.º 4
0
		public void Conversions ()
		{
			// ToDouble
			Assert.AreEqual (6464.6464, Test1.ToDouble (), "N01");

			// ToSqlBoolean ()
			Assert.AreEqual (new SqlBoolean (1), Test1.ToSqlBoolean (), "#N02");

			SqlDecimal Test = new SqlDecimal (0);
			Assert.IsTrue (!Test.ToSqlBoolean ().Value, "#N03");

			Test = new SqlDecimal (0);
			Assert.IsTrue (!Test.ToSqlBoolean ().Value, "#N04");
			Assert.IsTrue (SqlDecimal.Null.ToSqlBoolean ().IsNull, "#N05");

			// ToSqlByte ()
			Test = new SqlDecimal (250);
			Assert.AreEqual ((byte) 250, Test.ToSqlByte ().Value, "#N06");

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

			// ToSqlDouble ()
			Assert.AreEqual ((SqlDouble) 6464.6464, Test1.ToSqlDouble (), "#N09");

			// ToSqlInt16 ()
			Assert.AreEqual ((short) 1, new SqlDecimal (1).ToSqlInt16 ().Value, "#N10");

			try {
				SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16 ().Value;
				Assert.Fail ("#N11");
			} catch (OverflowException e) {
				Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N12");
			}

			// ToSqlInt32 () 
			// LAMESPEC: 6464.6464 --> 64646464 ??? with windows
			// MS.NET seems to return the first 32 bit integer (i.e. 
			// Data [0]) but we don't have to follow such stupidity.
			//			Assert.AreEqual ((int)64646464, Test1.ToSqlInt32 ().Value, "#N13a");
			//			Assert.AreEqual ((int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value, "#N13b");

			try {
				SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32 ().Value;
				Assert.Fail ("#N14");
			} catch (OverflowException e) {
				Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N15");
			}

			// ToSqlInt64 ()
			Assert.AreEqual ((long) 6464, Test1.ToSqlInt64 ().Value, "#N16");

			// ToSqlMoney ()
			Assert.AreEqual ((decimal) 6464.6464, Test1.ToSqlMoney ().Value, "#N17");

			try {
				SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney ().Value;
				Assert.Fail ("#N18");
			} catch (OverflowException e) {
				Assert.AreEqual (typeof (OverflowException), e.GetType (), "#N19");
			}

			// ToSqlSingle ()
			Assert.AreEqual ((float) 6464.6464, Test1.ToSqlSingle ().Value, "#N20");

			// ToSqlString ()
			Assert.AreEqual ("6464.6464", Test1.ToSqlString ().Value, "#N21");

			// ToString ()
			Assert.AreEqual ("6464.6464", Test1.ToString (), "#N22");
			// NOT WORKING
			Assert.AreEqual ("792281625142643375935439503350000.00", SqlDecimal.Multiply (Test5 , Test2).ToString () , "#N22.1");
			Assert.AreEqual ((SqlDouble) 1E+38, SqlDecimal.MaxValue.ToSqlDouble (), "#N23");

		}
                public void Conversions()
                {
                	// ToDouble
                	AssertEquals ("N01", 6464.6464, Test1.ToDouble ());
                	
                        // ToSqlBoolean ()
                       	AssertEquals ("#N02", new SqlBoolean(1), Test1.ToSqlBoolean ());
                        
                        SqlDecimal Test = new SqlDecimal (0);
                        Assert ("#N03", !Test.ToSqlBoolean ().Value);
                	
                	Test = new SqlDecimal (0);
                	Assert ("#N04", !Test.ToSqlBoolean ().Value);
                        Assert ("#N05", SqlDecimal.Null.ToSqlBoolean ().IsNull);

                        // ToSqlByte ()
                        Test = new SqlDecimal (250);
                        AssertEquals ("#N06", (byte)250, Test.ToSqlByte ().Value);

                        try {
                                SqlByte b = (byte)Test2.ToSqlByte ();
                                Fail ("#N07");
                        } catch (Exception e) {
                                AssertEquals ("#N08", typeof (OverflowException), e.GetType ());
                        }

                        // ToSqlDouble ()
                        AssertEquals ("#N09", (SqlDouble)6464.6464, Test1.ToSqlDouble ());

                        // ToSqlInt16 ()
                        AssertEquals ("#N10", (short)1, new SqlDecimal (1).ToSqlInt16 ().Value);

                        try {
                                SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;
                                Fail ("#N11");
                        } catch (Exception e) {
                                AssertEquals ("#N12", typeof (OverflowException), e.GetType ());
                        }        

                        // ToSqlInt32 () 
                        // LAMESPEC: 6464.6464 --> 64646464 ??? with windows
			// MS.NET seems to return the first 32 bit integer (i.e. 
			// Data [0]) but we don't have to follow such stupidity.
//			AssertEquals ("#N13a", (int)64646464, Test1.ToSqlInt32 ().Value);
//			AssertEquals ("#N13b", (int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);
                	
                        try {
                                SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32 ().Value;
                                Fail ("#N14");
                        } catch (Exception e) { 
                                AssertEquals ("#N15", typeof (OverflowException), e.GetType ());
                        }

                        // ToSqlInt64 ()
                        AssertEquals ("#N16", (long)6464, Test1.ToSqlInt64 ().Value);

                        // ToSqlMoney ()
                        AssertEquals ("#N17", (decimal)6464.6464, Test1.ToSqlMoney ().Value);

                        try {
                                SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney ().Value;
                                Fail ("#N18");
                        } catch (Exception e) {
                                AssertEquals ("#N19", typeof (OverflowException), e.GetType ());
                        }        

                        // ToSqlSingle ()
                        AssertEquals ("#N20", (float)6464.6464, Test1.ToSqlSingle ().Value);

                        // ToSqlString ()
                        AssertEquals ("#N21", "6464.6464", Test1.ToSqlString ().Value);

                        // ToString ()
                        AssertEquals ("#N22", "6464.6464", Test1.ToString ());                        
			AssertEquals ("#N23", (SqlDouble)1E+38, SqlDecimal.MaxValue.ToSqlDouble ());

                }