Example #1
0
        private ISqlString ToString(SqlDateTime date, SqlCharacterType destType)
        {
            var dateString = ToSqlString(date);
            var s          = new SqlString(dateString);

            return((ISqlString)destType.NormalizeValue(s));
        }
        public static void GetTypeString(SqlTypeCode typeCode, int maxSize, string locale, string expected)
        {
            var culture = String.IsNullOrEmpty(locale) ? null : new CultureInfo(locale);
            var type    = new SqlCharacterType(typeCode, maxSize, culture);

            var sql = type.ToString();

            Assert.Equal(expected, sql);
        }
        public static void Serialize(SqlTypeCode typeCode, int maxSize, string locale)
        {
            var culture = String.IsNullOrEmpty(locale) ? null : new CultureInfo(locale);
            var type    = new SqlCharacterType(typeCode, maxSize, culture);

            var result = BinarySerializeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
        public static void Greater(string s1, string s2, string locale, bool expected)
        {
            var sqlString1 = new SqlString(s1);
            var sqlString2 = new SqlString(s2);

            var culture = String.IsNullOrEmpty(locale) ? null : new CultureInfo(locale);
            var type    = new SqlCharacterType(SqlTypeCode.String, -1, culture);

            Assert.Equal(expected, (bool)type.Greater(sqlString1, sqlString2));
        }
        private static void InvalidOp(Func <SqlType, Func <ISqlValue, ISqlValue> > selector)
        {
            var s1 = new SqlString("foo");

            var type   = new SqlCharacterType(SqlTypeCode.String, -1, null);
            var op     = selector(type);
            var result = op(s1);

            Assert.NotNull(result);
            Assert.IsType <SqlNull>(result);
        }
        private ISqlValue ToString(SqlNumber number, SqlCharacterType destType)
        {
            if (destType.HasMaxSize && number.Precision > destType.MaxSize)
            {
                return(SqlNull.Value);
            }

            var s = number.ToString();

            return(destType.NormalizeValue(new SqlString(s)));
        }
Example #7
0
        private ISqlValue ToString(ISqlBinary binary, SqlCharacterType destType)
        {
            if (binary == null)
            {
                throw new InvalidCastException();
            }

            var bytes = binary.ToArray();
            var s     = new SqlString(bytes);

            return(destType.NormalizeValue(s));
        }
        public static void CreateStringType(SqlTypeCode typeCode, int maxSize, string locale)
        {
            var culture = String.IsNullOrEmpty(locale) ? null : new CultureInfo(locale);
            var type    = new SqlCharacterType(typeCode, maxSize, culture);

            Assert.Equal(typeCode, type.TypeCode);
            Assert.Equal(maxSize, type.MaxSize);
            Assert.Equal(maxSize > 0, type.HasMaxSize);
            Assert.Equal(locale, type.Locale == null ? null : type.Locale.Name);
            Assert.True(type.IsIndexable);
            Assert.False(type.IsReference);
            Assert.False(type.IsLargeObject);
            Assert.True(type.IsPrimitive);
        }
Example #9
0
        public static void CastToString(string s, SqlTypeCode typeCode, SqlTypeCode destTypeCode, int maxSize, string expected)
        {
            var date = SqlDateTime.Parse(s);
            var type = new SqlDateTimeType(typeCode);

            var destType = new SqlCharacterType(destTypeCode, maxSize, null);

            Assert.True(type.CanCastTo(date, destType));

            var result = type.Cast(date, destType);

            Assert.NotNull(result);
            Assert.IsType <SqlString>(result);

            Assert.Equal(expected, (SqlString)result);
        }
        public static void CastToString(string s, SqlTypeCode typeCode, int maxSize, string expected)
        {
            var type     = new SqlBinaryType(SqlTypeCode.Binary);
            var input    = (SqlString)s;
            var destType = new SqlCharacterType(typeCode, maxSize, null);

            var bytes  = input.ToByteArray();
            var binary = new SqlBinary(bytes);

            Assert.True(type.CanCastTo(binary, destType));

            var result = type.Cast(binary, destType);

            Assert.NotNull(result);
            Assert.IsType <SqlString>(result);

            Assert.Equal(expected, (SqlString)result);
        }
Example #11
0
        private ISqlString ToString(SqlBoolean value, SqlCharacterType destType)
        {
            var s = new SqlString(ToSqlString(value));

            return((ISqlString)destType.NormalizeValue(s));
        }
Example #12
0
        private ISqlValue ToString(SqlDayToSecond dts, SqlCharacterType destType)
        {
            var s = new SqlString(dts.ToString());

            return(destType.NormalizeValue(s));
        }