public void TestToDouble()
        {
            Assert.Null(DoubleConverter.ToNullableDouble(null));
            Assert.True(Math.Abs(123 - DoubleConverter.ToDouble(123)) < 0.001);
            Assert.True(Math.Abs(123.456 - DoubleConverter.ToDouble(123.456)) < 0.001);
            Assert.True(Math.Abs(123.456 - DoubleConverter.ToDouble("123.456")) < 0.001);

            Assert.True(Math.Abs(123 - DoubleConverter.ToDoubleWithDefault(null, 123)) < 0.001);
            Assert.True(Math.Abs(0 - DoubleConverter.ToDoubleWithDefault(false, 123)) < 0.001);
            Assert.True(Math.Abs(123 - DoubleConverter.ToDoubleWithDefault("ABC", 123)) < 0.001);
        }
Ejemplo n.º 2
0
        public void TestToLong()
        {
            DateTime date = new DateTime();

            Assert.Equal(date.Ticks, LongConverter.ToLong(date));
            Assert.Equal(100, LongConverter.ToLong(new TimeSpan(100)));
            Assert.Equal(123, LongConverter.ToLong(123));
            Assert.Equal(123, LongConverter.ToLong((short)123));
            Assert.Equal(123, LongConverter.ToLong(123.456));
            Assert.Equal(124, LongConverter.ToLong(123.999));
            Assert.Equal(123, LongConverter.ToLong(DoubleConverter.ToDouble(123.456)));
            Assert.Equal(123, LongConverter.ToLong("123"));
            Assert.Equal(123, LongConverter.ToLong("123.465"));
            Assert.Equal(123, LongConverter.ToLong("123.999"));
            Assert.Equal(0, LongConverter.ToLong(null));
        }