public void Transform_SingleObject () { var argument0 = Expression.Constant (new object()); var expression = Expression.Call (typeof (string), "Concat", Type.EmptyTypes, argument0); var result = _transformer.Transform (expression); var expectedExpression = new SqlConvertExpression (typeof (string), argument0); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedExpression, result); }
public void Transform () { var method = typeof (object).GetMethod ("ToString", new Type[] { }); var argument = Expression.Constant (1); var expression = Expression.Call (argument, method); var transformer = new ToStringMethodCallTransformer(); var result = transformer.Transform (expression); var expectedResult = new SqlConvertExpression (typeof (string), Expression.Constant (1)); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result); }
private Expression AddMilliseconds (Expression milliseconds, Expression dateTime) { // Convert milliseconds value to long first (truncating). if (milliseconds.Type != typeof (long)) milliseconds = new SqlConvertExpression (typeof (long), milliseconds); // Add milliseconds in two steps: extract the days and add them as a "day" value, then add the remaining milliseconds as a "milliseconds" value. // This two-step part is required because SQL Server can only add 32-bit INTs using DATEADD, no BIGINTs. The milliseconds in a day (86,400,000) // fit into an INT. The second INT for days can express up to +/- 2^31 (or so) days, which equals about five million years. This is much // more than a SQL DATETIME can hold. var days = Expression.Divide (milliseconds, new SqlLiteralExpression (TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond)); var remainingMilliseconds = Expression.Modulo (milliseconds, new SqlLiteralExpression (TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond)); return AddUnits (remainingMilliseconds, "millisecond", AddUnits (days, "day", dateTime)); }
public Expression VisitSqlConvertExpression (SqlConvertExpression expression) { return VisitChildrenWithGivenSemantics (expression, SqlExpressionContext.SingleValueRequired); }
public void GetSqlTypeName_KeyNotFound_ThrowsException () { var convertExpression = new SqlConvertExpression (typeof (Cook), Expression.Constant ("1")); convertExpression.GetSqlTypeName (); }
public void GetSqlTypeName_NullableValueType () { var convertExpresion = new SqlConvertExpression (typeof (int?), Expression.Constant ("1")); var result = convertExpresion.GetSqlTypeName (); Assert.That (result, Is.EqualTo ("INT")); }
public void SetUp () { _convertExpresion = new SqlConvertExpression (typeof (int), Expression.Constant ("1")); }
private void CheckSqlTypeName (Type type, string expectedSqlTypeName) { var result = new SqlConvertExpression (type, new CustomExpression (type)); Assert.That (result.GetSqlTypeName(), Is.EqualTo (expectedSqlTypeName)); }
public void VisitSqlConvertExpression () { var sqlConvertExpression = new SqlConvertExpression (typeof (string), Expression.Constant ("1")); SqlGeneratingExpressionVisitor.GenerateSql (sqlConvertExpression, _commandBuilder, _stageMock); Assert.That (_commandBuilder.GetCommandText(), Is.EqualTo ("CONVERT(NVARCHAR(MAX), @1)")); }
public void VisitSqlConvertExpression () { var expression = new SqlConvertExpression (typeof (bool), Expression.Constant (true)); var expectedResult = new SqlConvertExpression (typeof (bool), new SqlConvertedBooleanExpression (Expression.Constant (1))); var result = _predicateRequiredVisitor.VisitSqlConvertExpression (expression); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result); }
public void Transform () { var method = typeof (Convert).GetMethod ("ToInt32", new[] { typeof (string) }); var argument = Expression.Constant ("1"); var expression = Expression.Call (method, argument); var transformer = new ConvertMethodCallTransformer(); var result = transformer.Transform (expression); var expectedResult = new SqlConvertExpression (typeof (int), Expression.Constant ("1")); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult, result); }