Exemple #1
0
        public void Length()
        {
            var type = new SqlChar(5, encoding, CompressionContext.NoCompression);

            Assert.Throws <ArgumentException>(() => type.GetValue(new byte[4]));
            Assert.Throws <ArgumentException>(() => type.GetValue(new byte[6]));
        }
Exemple #2
0
        public void GetRawValue()
        {
            SqlType type = new SqlChar("Test", 10, ParameterDirection.Input);
            Assert.AreEqual("Test", type.GetRawValue());

            type = new SqlChar(null, 10, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Exemple #3
0
        public void GetValue()
        {
            var type = new SqlChar(5, encoding, CompressionContext.NoCompression);

            byte[] input;

            input = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F };
            Assert.AreEqual("Hello", type.GetValue(input));
        }
Exemple #4
0
        public void GetRawValue()
        {
            SqlType type = new SqlChar("Test", 10, ParameterDirection.Input);

            Assert.AreEqual("Test", type.GetRawValue());

            type = new SqlChar(null, 10, ParameterDirection.Input);
            Assert.Null(type.GetRawValue());
        }
Exemple #5
0
        public void CreateMetaData()
        {
            Assert.Throws<TypeCannotBeUsedAsAClrTypeException>(() => SqlChar.GetTypeHandler().CreateMetaData("Test"));

            SqlTypeHandler col = new SqlChar("Test", null, ParameterDirection.Input);
            Assert.Throws<TypePropertiesMustBeSetExplicitlyException>(() => col.CreateMetaData("Test"));

            col = new SqlChar("Test", 10, ParameterDirection.Input);
            var meta = col.CreateMetaData("Test");
            Assert.AreEqual(SqlDbType.Char, meta.SqlDbType);
            Assert.AreEqual(10, meta.MaxLength);
            Assert.AreEqual("Test", meta.Name);
        }
Exemple #6
0
        public void CreateMetaData()
        {
            Assert.Throws <TypeCannotBeUsedAsAClrTypeException>(() => SqlChar.GetTypeHandler().CreateMetaData("Test"));

            SqlTypeHandler col = new SqlChar("Test", null, ParameterDirection.Input);

            Assert.Throws <TypePropertiesMustBeSetExplicitlyException>(() => col.CreateMetaData("Test"));

            col = new SqlChar("Test", 10, ParameterDirection.Input);
            var meta = col.CreateMetaData("Test");

            Assert.AreEqual(SqlDbType.Char, meta.SqlDbType);
            Assert.AreEqual(10, meta.MaxLength);
            Assert.AreEqual("Test", meta.Name);
        }
Exemple #7
0
        protected override string GetColumnCreationMethod(SqlColumn column)
        {
            var type = column.Types[Version];

            return(type.SqlTypeInfo switch
            {
                SqlChar _ => $"{nameof(Generic1Columns.AddChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}",
                SqlNChar _ => $"{nameof(Generic1Columns.AddNChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlVarChar _ => $"{nameof(Generic1Columns.AddVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlNVarChar _ => $"{nameof(Generic1Columns.AddNVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlFloatSmall _ => $"{nameof(Generic1Columns.AddFloatSmall)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlFloatLarge _ => $"{nameof(Generic1Columns.AddFloatLarge)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlBit _ => $"{nameof(Generic1Columns.AddBit)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlByte _ => $"{nameof(Generic1Columns.AddByte)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt16 _ => $"{nameof(Generic1Columns.AddInt16)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt32 _ => $"{nameof(Generic1Columns.AddInt32)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlInt64 _ => $"{nameof(Generic1Columns.AddInt64)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlNumber _ => $"{nameof(Generic1Columns.AddNumber)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.Scale?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlDate _ => $"{nameof(Generic1Columns.AddDate)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlTime _ => $"{nameof(Generic1Columns.AddTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                SqlDateTime _ => $"{nameof(Generic1Columns.AddDateTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}",
                _ => throw new NotImplementedException($"Unmapped type: {type.SqlTypeInfo}"),
            });
Exemple #8
0
 public void CreateParamFromValue()
 {
     Assert.Throws <TypeCannotBeUsedAsAClrTypeException>(() => SqlChar.GetTypeHandler().CreateParamFromValue("Test", null));
 }
Exemple #9
0
 public void GetTypeHandler()
 {
     Assert.IsInstanceOf <SqlTypeHandler>(SqlChar.GetTypeHandler());
 }