public static void SubtractYearToMonth(string value1, string value2, string expected) { var a = SqlYearToMonth.Parse(value1); var b = SqlYearToMonth.Parse(value2); Binary(type => type.Subtract, a, b, expected); }
public static void SubtractNumber(string value1, object value2, string expected) { var a = SqlYearToMonth.Parse(value1); var b = SqlValueUtil.FromObject(value2); Binary(type => type.Subtract, a, b, expected); }
public void CompareYearToMonths() { var value1 = new SqlYearToMonth(22); var value2 = new SqlYearToMonth(1, 2); var result = value1.CompareTo(value2); Assert.AreEqual(1, result); }
public static void GetString(string input, string expected) { var type = PrimitiveTypes.YearToMonth(); var ytm = SqlYearToMonth.Parse(input); var s = type.ToSqlString(ytm); Assert.Equal(expected, s); }
private ISqlValue ToYearToMonth(SqlString value) { SqlYearToMonth ytm; if (!SqlYearToMonth.TryParse(value.Value, out ytm)) { return(SqlNull.Value); } return(ytm); }
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); }
public void SerializeObject_YearToMonth_NotNull() { var type = PrimitiveTypes.YearToMonth(); var obj = new SqlYearToMonth(45); var stream = new MemoryStream(); type.SerializeObject(stream, obj); stream.Seek(0, SeekOrigin.Begin); var serialized = type.DeserializeObject(stream); Assert.AreEqual(obj, serialized); }
public void Add_MonthSpan() { var value = new SqlDateTime(2001, 11, 03, 10, 22, 03, 0); var ms = new SqlYearToMonth(1, 3); var result = new SqlDateTime(); Assert.DoesNotThrow(() => result = value.Add(ms)); Assert.IsFalse(result.IsNull); Assert.AreEqual(2003, result.Year); Assert.AreEqual(02, result.Month); Assert.AreEqual(10, result.Hour); Assert.AreEqual(22, result.Minute); Assert.AreEqual(03, result.Second); Assert.AreEqual(0, result.Millisecond); }
private static void Binary(Func <SqlType, Func <ISqlValue, ISqlValue, ISqlValue> > selector, object value1, object value2, string expected) { var type = new SqlYearToMonthType(); var a = value1 is SqlYearToMonth ? (ISqlValue)(SqlYearToMonth)value1 : (SqlNumber)value1; var b = value2 is SqlYearToMonth ? (ISqlValue)(SqlYearToMonth)value2 : (SqlNumber)value2; var op = selector(type); var result = op(a, b); var exp = SqlYearToMonth.Parse(expected); Assert.Equal(exp, result); }
public void YearToMonthFromInteger(int months, int expectedYears) { var value = new SqlYearToMonth(months); Assert.IsNotNull(value); Assert.IsFalse(value.IsNull); Assert.AreEqual(expectedYears, (int) value.TotalYears); }
public static void CastToYearToMonth(string s, int expected) { var exp = new SqlYearToMonth(expected); Cast(s, SqlTypeCode.YearToMonth, -1, -1, exp); }
public void SerializeObject_YearToMonth_NotNull() { var type = PrimitiveTypes.YearToMonth(); var obj = new SqlYearToMonth(45); var stream = new MemoryStream(); type.SerializeObject(stream, obj); stream.Seek(0, SeekOrigin.Begin); var serialized = type.DeserializeObject(stream); Assert.AreEqual(obj, serialized); }