示例#1
0
        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);
        }
示例#2
0
        public static void EqualToOther(int months1, int months2, bool expected)
        {
            var ytm1 = new SqlYearToMonth(months1);
            var ytm2 = new SqlYearToMonth(months2);

            Assert.Equal(expected, ytm1.Equals(ytm2));
        }
示例#3
0
        public static void Serialize(int years, int months)
        {
            var ytm    = new SqlYearToMonth(years, months);
            var result = BinarySerializeUtil.Serialize(ytm);

            Assert.Equal(result, ytm);
        }
示例#4
0
        public static void FromYearsAndMonths(int years, int months, int expectedMonths)
        {
            var ytm = new SqlYearToMonth(years, months);

            Assert.NotNull(ytm);
            Assert.Equal(expectedMonths, ytm.TotalMonths);
        }
示例#5
0
        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 FromYear(int years, int expectedMonths)
        {
            var ytm = new SqlYearToMonth(years, 0);

            Assert.Equal(expectedMonths, ytm.TotalMonths);
            Assert.Equal(years, ytm.TotalYears);
        }
        public static void FromMonths(int months, double expectedYears)
        {
            var ytm = new SqlYearToMonth(months);

            Assert.Equal(expectedYears, ytm.TotalYears);
            Assert.Equal(months, ytm.TotalMonths);
            ;
        }
示例#8
0
        public static void GetString(string input, string expected)
        {
            var type = PrimitiveTypes.YearToMonth();
            var ytm  = SqlYearToMonth.Parse(input);
            var s    = type.ToString(ytm);

            Assert.Equal(expected, s);
        }
示例#9
0
        public static void Compare_ToSqlValue_Number(int months, int value, int expected)
        {
            var ytm    = new SqlYearToMonth(months);
            var number = (SqlNumber)value;

            var result = (ytm as IComparable <ISqlValue>).CompareTo(number);

            Assert.Equal(expected, result);
        }
示例#10
0
        public static void Compare_ToYearToMonth(int months1, int months2, int expected)
        {
            var ytm1 = new SqlYearToMonth(months1);
            var ytm2 = new SqlYearToMonth(months2);

            var result = ytm1.CompareTo(ytm2);

            Assert.Equal(expected, result);
        }
示例#11
0
        public static void Compare_ToSqlValue_YearToMonth(int months1, int months2, int expected)
        {
            var ytm1 = new SqlYearToMonth(months1);
            var ytm2 = new SqlYearToMonth(months2);

            var result = (ytm1 as IComparable <ISqlValue>).CompareTo(ytm2);

            Assert.Equal(expected, result);
        }
示例#12
0
        private ISqlValue ToYearToMonth(SqlString value)
        {
            SqlYearToMonth ytm;

            if (!SqlYearToMonth.TryParse(value.Value, out ytm))
            {
                return(SqlNull.Value);
            }

            return(ytm);
        }
示例#13
0
        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);
        }
示例#14
0
		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 static void SerializeValue(string input)
        {
            var type = PrimitiveTypes.YearToMonth();
            var ytm  = SqlYearToMonth.Parse(input);

            var stream = new MemoryStream();

            type.Serialize(stream, ytm);

            stream.Seek(0, SeekOrigin.Begin);

            var result = type.Deserialize(stream);

            Assert.Equal(ytm, result);
        }
示例#16
0
        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);
        }
示例#17
0
        private static bool TryParseValue(SqlTypeCode typeCode, string s, IFormatProvider provider, out ISqlValue outValue, out Exception error)
        {
            try {
                switch (typeCode)
                {
                case SqlTypeCode.TinyInt:
                case SqlTypeCode.SmallInt:
                case SqlTypeCode.Integer:
                case SqlTypeCode.BigInt:
                case SqlTypeCode.Real:
                case SqlTypeCode.Double:
                case SqlTypeCode.Decimal:
                case SqlTypeCode.Float:
                case SqlTypeCode.Numeric:
                case SqlTypeCode.VarNumeric: {
                    error = null;
                    var result = SqlNumber.TryParse(s, provider, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.Bit:
                case SqlTypeCode.Boolean: {
                    error = null;
                    var result = SqlBoolean.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.Date:
                case SqlTypeCode.DateTime:
                case SqlTypeCode.TimeStamp: {
                    error = null;
                    var result = SqlDateTime.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.YearToMonth: {
                    error = null;
                    var result = SqlYearToMonth.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.DayToSecond: {
                    error = null;
                    var result = SqlDayToSecond.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                default: {
                    error    = new FormatException($"The type {typeCode} does not support parsing");
                    outValue = null;

                    return(false);
                }
                }
            } catch (Exception ex) {
                error    = ex;
                outValue = null;

                return(false);
            }
        }
        public static void CastToYearToMonth(string s, int expected)
        {
            var exp = new SqlYearToMonth(expected);

            Cast(s, SqlTypeCode.YearToMonth, -1, -1, exp);
        }
示例#19
0
        public SqlDateTime Subtract(SqlYearToMonth interval)
        {
            var result = value.AddMonths(-interval.TotalMonths);

            return(new SqlDateTime(result.Ticks));
        }
示例#20
0
        public static void InvalidComparison()
        {
            var ytm = new SqlYearToMonth(2);

            Assert.Throws <NotSupportedException>(() => (ytm as IComparable <ISqlValue>).CompareTo(SqlBoolean.True));
        }