Пример #1
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);
		}
Пример #2
0
		public static void CastToDateTime(string s, SqlTypeCode destTypeCode, string expected) {
			var date = SqlDateTime.Parse(s);
			var type = new SqlDateTimeType(SqlTypeCode.DateTime);

			var destType = new SqlDateTimeType(destTypeCode);
			Assert.True(type.CanCastTo(date, destType));

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

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

			var expectedResult = SqlDateTime.Parse(expected);
			Assert.Equal(expectedResult, result);
		}
Пример #3
0
		public static void CastToNumber(string s, SqlTypeCode typeCode, int precision, int scale) {
			var date = SqlDateTime.Parse(s);
			var type = new SqlDateTimeType(SqlTypeCode.DateTime);
			var destType = new SqlNumericType(typeCode, precision, scale);

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

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

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

			var value = (SqlNumber) result;

			var back = new SqlDateTime((long)value);

			Assert.Equal(date, back);
		}