public static void ToTimeStampString(string s, string expected) { var date = SqlDateTime.Parse(s); var result = date.ToTimeStampString(); Assert.Equal(expected, result); }
public static void GetNextDateForDay(string s, DayOfWeek dayOfWeek, string expected) { var date = SqlDateTime.Parse(s); var nextDate = date.GetNextDateForDay(dayOfWeek); Assert.Equal(expected, nextDate.ToDateString()); }
public static void ToUtc(string s, string expected) { var date = SqlDateTime.Parse(s); var utc = date.ToUtc(); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, utc); }
public static void AtTimeZoneName(string s, string expected) { var date = SqlDateTime.Parse(s); var timeZoneName = TimeZoneInfo.GetSystemTimeZones().First(x => x.BaseUtcOffset.Hours == 1).Id; var result = date.AtTimeZone(timeZoneName); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, result); }
private static void BinaryOp(Func <SqlDateTime, SqlDateTime, SqlBoolean> op, string s1, string s2, bool expected) { var date1 = SqlDateTime.Parse(s1); var date2 = SqlDateTime.Parse(s2); var result = op(date1, date2); var expectedResult = (SqlBoolean)expected; Assert.Equal(expectedResult, result); }
public static void Convert_ToSqlDateTime(string date) { var s = new SqlString(date); var result = Convert.ChangeType(s, typeof(SqlDateTime), CultureInfo.InvariantCulture); Assert.NotNull(result); Assert.IsType <SqlDateTime>(result); var expectedResult = SqlDateTime.Parse(date); Assert.Equal(expectedResult, result); }
private static void BinaryWithInterval(Func<SqlDateTimeType, Func<ISqlValue, ISqlValue, ISqlValue>> selector, string date, string offset, string expected) { var type = new SqlDateTimeType(SqlTypeCode.DateTime); var sqlDate = SqlDateTime.Parse(date); var dts = SqlDayToSecond.Parse(offset); var op = selector(type); var result = op(sqlDate, dts); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, result); }
private static void Binary(Func<SqlDateTimeType, Func<ISqlValue, ISqlValue, SqlBoolean>> selector, string date1, string date2, bool expected) { var type = new SqlDateTimeType(SqlTypeCode.DateTime); var sqlDate1 = SqlDateTime.Parse(date1); var sqlDate2 = SqlDateTime.Parse(date2); var op = selector(type); var result = op(sqlDate1, sqlDate2); var expectedResult = (SqlBoolean) expected; Assert.Equal(expectedResult, result); }
private static void BinaryWithInterval(Func<SqlDateTimeType, Func<ISqlValue, ISqlValue, ISqlValue>> selector, string date, int months, string expected) { var type = new SqlDateTimeType(SqlTypeCode.DateTime); var sqlDate = SqlDateTime.Parse(date); var ytm = new SqlYearToMonth(months); var op = selector(type); var result = op(sqlDate, ytm); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, result); }
private static void BinaryOp(Func <SqlDateTime, SqlDayToSecond, SqlDateTime> op, string s1, string s2, string expected) { var date = SqlDateTime.Parse(s1); var date2 = SqlDayToSecond.Parse(s2); var result = op(date, date2); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, result); }
private static void BinaryOp(Func <SqlDateTime, SqlYearToMonth, SqlDateTime> op, string s, int months, string expected) { var date = SqlDateTime.Parse(s); var ytm = new SqlYearToMonth(months); var result = op(date, ytm); var expectedResult = SqlDateTime.Parse(expected); Assert.Equal(expectedResult, result); }
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 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); }
public static void SerializeValue(string date) { var type = PrimitiveTypes.TimeStamp(); var sqlDate = SqlDateTime.Parse(date); var stream = new MemoryStream(); type.Serialize(stream, sqlDate); stream.Seek(0, SeekOrigin.Begin); var result = type.Deserialize(stream); Assert.Equal(sqlDate, result); }
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); }
public static void CastToDate(string s, SqlTypeCode typeCode) { var type = new SqlBinaryType(SqlTypeCode.Binary); var date = SqlDateTime.Parse(s); var destType = new SqlDateTimeType(typeCode); var bytes = date.ToByteArray(); var binary = new SqlBinary(bytes); Assert.True(type.CanCastTo(binary, destType)); var result = type.Cast(binary, destType); Assert.NotNull(result); Assert.IsType <SqlDateTime>(result); Assert.Equal(date, (SqlDateTime)result); }
public static void CastToDateTime(string s, SqlTypeCode typeCode, string expected) { var expectedResult = SqlDateTime.Parse(expected); Cast(s, typeCode, -1, -1, expectedResult); }