예제 #1
0
        public void FromClrType_maps_floats(object value)
        {
            var map = SQLiteTypeMap.FromClrType(value.GetType());

            Assert.Equal(SQLiteType.Float, map.SQLiteType);
            Assert.Equal(3.14, (double)map.ToInterop(value), precision: 6);
            Assert.Equal(value, map.FromInterop(3.14));
        }
예제 #2
0
        public void FromInterop_converts_to_string_when_DateTimeOffset()
        {
            var value = new DateTimeOffset(2014, 3, 19, 14, 18, 58, 213, new TimeSpan(-7, 0, 0));

            var map = SQLiteTypeMap.FromClrType <DateTimeOffset>();

            Assert.Equal(value, map.FromInterop("2014-03-19T14:18:58.2130000-07:00"));
        }
예제 #3
0
        public void FromInterop_converts_to_string_when_decimal()
        {
            var value = 3.14m;

            var map = SQLiteTypeMap.FromClrType <decimal>();

            Assert.Equal(value, map.FromInterop("3.14"));
        }
예제 #4
0
        public void FromInterop_converts_to_string_when_DateTime()
        {
            var value = new DateTime(2014, 3, 19, 14, 18, 58);

            var map = SQLiteTypeMap.FromClrType <DateTime>();

            Assert.Equal(value, map.FromInterop("2014-03-19 14:18:58"));
        }
예제 #5
0
        public void FromInterop_overflows_when_ulong()
        {
            var value = 0xFFFFFFFFFFFFFFFF;

            var map = SQLiteTypeMap.FromClrType <ulong>();

            Assert.Equal(value, map.FromInterop(-1L));
        }
예제 #6
0
        public void ToInterop_converts_to_string_when_decimal()
        {
            var value = 3.14m;

            var map = SQLiteTypeMap.FromClrType <decimal>();

            Assert.Equal(SQLiteType.Text, map.SQLiteType);
            Assert.Equal("3.14", map.ToInterop(value));
        }
예제 #7
0
        public void ToInterop_converts_to_string_when_TimeSpan()
        {
            var value = new TimeSpan(19, 14, 18, 58, 213);

            var map = SQLiteTypeMap.FromClrType <TimeSpan>();

            Assert.Equal(SQLiteType.Text, map.SQLiteType);
            Assert.Equal("19.14:18:58.2130000", map.ToInterop(value));
        }
예제 #8
0
        public void FromClrType_maps_integers(object value)
        {
            var map = SQLiteTypeMap.FromClrType(value.GetType());

            Assert.Equal(value.GetType(), map.ClrType);
            Assert.Equal(SQLiteType.Integer, map.SQLiteType);
            Assert.Equal(1L, map.ToInterop(value));
            Assert.Equal(value, map.FromInterop(1L));
        }
예제 #9
0
        public void FromInterop_converts_to_string_when_TimeSpan()
        {
            var value = new TimeSpan(14, 18, 58);

            var map = SQLiteTypeMap.FromClrType <TimeSpan>();

            Assert.Equal(SQLiteType.Text, map.SQLiteType);
            Assert.Equal(value, map.FromInterop("14:18:58"));
        }
예제 #10
0
        public void ToInterop_converts_to_string_when_DateTime()
        {
            var value = new DateTime(2014, 3, 19, 14, 18, 58, 213);

            var map = SQLiteTypeMap.FromClrType <DateTime>();

            Assert.Equal(SQLiteType.Text, map.SQLiteType);
            Assert.Equal("2014-03-19T14:18:58.2130000", map.ToInterop(value));
        }
예제 #11
0
        public void FromClrType_maps_dbNull_to_null()
        {
            var value = DBNull.Value;

            var map = SQLiteTypeMap.FromClrType <DBNull>();

            Assert.Equal(typeof(DBNull), map.ClrType);
            Assert.Equal(SQLiteType.Null, map.SQLiteType);
            Assert.Equal(DBNull.Value, map.ToInterop(value));
            Assert.Equal(value, map.FromInterop(DBNull.Value));
        }
예제 #12
0
        public void FromClrType_maps_byteArray_to_blob()
        {
            var value = new byte[] { 0x7e, 0x57 };

            var map = SQLiteTypeMap.FromClrType <byte[]>();

            Assert.Equal(typeof(byte[]), map.ClrType);
            Assert.Equal(SQLiteType.Blob, map.SQLiteType);
            Assert.Equal(new byte[] { 0x7e, 0x57 }, map.ToInterop(value));
            Assert.Equal(value, map.FromInterop(new byte[] { 0x7e, 0x57 }));
        }
예제 #13
0
        public void FromClrType_maps_string_to_text()
        {
            var value = "test";

            var map = SQLiteTypeMap.FromClrType <string>();

            Assert.Equal(typeof(string), map.ClrType);
            Assert.Equal(SQLiteType.Text, map.SQLiteType);
            Assert.Equal("test", map.ToInterop(value));
            Assert.Equal(value, map.FromInterop("test"));
        }
예제 #14
0
        public void FromInterop_converts_to_blob_when_Giud()
        {
            var value = new Guid("36127aab-3769-45b5-8804-f2d447dc001a");

            var map = SQLiteTypeMap.FromClrType <Guid>();

            Assert.Equal(
                value,
                map.FromInterop(
                    new byte[]
            {
                0xab, 0x7a, 0x12, 0x36,
                0x69, 0x37,
                0xb5, 0x45,
                0x88, 0x04,
                0xf2, 0xd4, 0x47, 0xdc, 0x00, 0x1a
            }));
        }
예제 #15
0
 public void FromClrType_handles_enum_types()
 {
     Assert.Equal(typeof(int), SQLiteTypeMap.FromClrType(typeof(StringComparison)).ClrType);
 }
예제 #16
0
 public void FromClrType_handles_nullable_types()
 {
     Assert.Equal(typeof(int), SQLiteTypeMap.FromClrType(typeof(int?)).ClrType);
 }
예제 #17
0
        public void FromClrType_throws_when_unknown()
        {
            var ex = Assert.Throws <ArgumentException>(() => SQLiteTypeMap.FromClrType(GetType()));

            Assert.Equal(Strings.FormatUnknownDataType(GetType()), ex.Message);
        }