Example #1
0
        public void DefValue_EmptyString_ToInt32()
        {
            object value = string.Empty;
            int    i     = ConvertTool.DefValue(value, 5);

            Assert.AreEqual(5, i);
        }
Example #2
0
        public void DBNullConvert()
        {
            object value     = DBNull.Value;
            string converted = ConvertTool.DefValue(value, "IS NULL");

            Assert.AreEqual(converted, "IS NULL");
        }
Example #3
0
        public void CanConvertNullableDateTime()
        {
            DateTime?value = DateTime.Today;

            var converted = ConvertTool.DefValue <DateTime?>(value, (DateTime?)null);

            Assert.AreEqual(value, converted, "#1");

            converted = ConvertTool.DefValue <DateTime?>(null, (DateTime?)null);
            Assert.AreEqual(null, converted, "#2");
        }
Example #4
0
        public void ConvertDateTimeTest()
        {
            var    dt      = DateTime.Now - TimeSpan.FromSeconds(5);
            string dateStr = dt.ToString();

            var converted = ConvertTool.DefValue(dateStr, DateTime.Now, true);

            Console.WriteLine("[ dt:" + dt + @" ]");
            Console.WriteLine("[ converted: " + converted + @" ]");

            Assert.AreEqual(dt.ToString(), converted.ToString());
            Assert.AreEqual(dt.Date.Ticks, converted.Date.Ticks);
        }
Example #5
0
        public void DefValueTest()
        {
            object value = 1;
            int    i     = ConvertTool.DefValue(value, 0);

            Assert.AreEqual(1, i);

            value = 12.5m;
            decimal convertedDecimal = ConvertTool.DefValue(value, 0m);

            Assert.AreEqual(12.5m, convertedDecimal);

            value = 9L;
            decimal convertedLong = ConvertTool.DefValue(value, 0L);

            Assert.AreEqual(9L, convertedLong);
        }