public void Initialization_CurrentSequence_Assignable () { var sequence = new StreamedSequenceInfo (typeof (object[]), _stringExpression); Assert.That (sequence.ResultItemType, Is.EqualTo (typeof (object))); Assert.That (sequence.ItemExpression.Type, Is.EqualTo (typeof (string))); }
public void Initialization_CurrentSequence_Assignable() { var sequence = new StreamedSequenceInfo(typeof(object[]), _stringExpression); Assert.That(sequence.ResultItemType, Is.EqualTo(typeof(object))); Assert.That(sequence.ItemExpression.Type, Is.EqualTo(typeof(string))); }
public override void VisitSelectClause( [NotNull] SelectClause selectClause, [NotNull] QueryModel queryModel) { Check.NotNull(selectClause, nameof(selectClause)); Check.NotNull(queryModel, nameof(queryModel)); if (_streamedSequenceInfo != null) { return; } var selector = ReplaceClauseReferences( CreateProjectionExpressionTreeVisitor(queryModel.MainFromClause) .VisitExpression(selectClause.Selector), inProjection: true); _expression = Expression.Call( LinqOperatorProvider.Select .MakeGenericMethod(typeof(QuerySourceScope), selector.Type), _expression, Expression.Lambda(selector, QuerySourceScopeParameter)); _streamedSequenceInfo = new StreamedSequenceInfo( typeof(IEnumerable <>).MakeGenericType(selector.Type), selector); }
public override void VisitResultOperator( [NotNull] ResultOperatorBase resultOperator, [NotNull] QueryModel queryModel, int index) { Check.NotNull(resultOperator, nameof(resultOperator)); Check.NotNull(queryModel, nameof(queryModel)); var expression = _queryCompilationContext.ResultOperatorHandler .HandleResultOperator(this, resultOperator, queryModel); if (expression != _expression) { _expression = expression; if (_streamedSequenceInfo != null && resultOperator is SequenceFromSequenceResultOperatorBase) { var sequenceType = _expression.Type.GetSequenceType(); _streamedSequenceInfo = new StreamedSequenceInfo( typeof(IEnumerable <>).MakeGenericType(sequenceType), Expression.Default(sequenceType)); } else { _streamedSequenceInfo = null; } } }
public override void VisitSelectClause( [NotNull] SelectClause selectClause, [NotNull] QueryModel queryModel) { Check.NotNull(selectClause, "selectClause"); Check.NotNull(queryModel, "queryModel"); if (_streamedSequenceInfo != null) { return; } var selector = ReplaceClauseReferences( CreateProjectionExpressionTreeVisitor() .VisitExpression(selectClause.Selector)); _expression = Expression.Call( LinqOperatorProvider.Select .MakeGenericMethod(typeof(QuerySourceScope), selector.Type), _expression, Expression.Lambda(selector, QuerySourceScopeParameter)); _streamedSequenceInfo = (StreamedSequenceInfo)selectClause.GetOutputDataInfo() .AdjustDataType(typeof(IEnumerable <>)); }
// ReSharper disable once UnusedParameter.Local private StreamedValueInfo GetOutputDataInfo([NotNull] StreamedSequenceInfo sequenceInfo) { Assertion.DebugAssert(Func.Type.GetTypeInfo().IsGenericTypeDefinition == false); var aggregatedType = Func.Type.GetTypeInfo().GenericTypeArguments[0]; if (!aggregatedType.GetTypeInfo().IsAssignableFrom(Seed.Type.GetTypeInfo())) { var message = string.Format( "The seed expression and the aggregating function don't have matching types. The seed is of type '{0}', but the function aggregates '{1}'.", Seed.Type, aggregatedType); throw new InvalidOperationException(message); } Assertion.DebugAssert(OptionalResultSelector == null || OptionalResultSelector.Type.GetTypeInfo().IsGenericTypeDefinition == false); var resultTransformedType = OptionalResultSelector != null?OptionalResultSelector.Type.GetTypeInfo().GenericTypeArguments[0] : null; if (resultTransformedType != null && aggregatedType != resultTransformedType) { var message = string.Format( "The aggregating function and the result selector don't have matching types. The function aggregates type '{0}', " + "but the result selector takes '{1}'.", aggregatedType, resultTransformedType); throw new InvalidOperationException(message); } var resultType = GetResultType(); return(new StreamedScalarValueInfo(resultType)); }
public void CheckSequenceItemType_SameType() { var sequenceInfo = new StreamedSequenceInfo(typeof(int[]), Expression.Constant(0)); var expectedItemType = typeof(int); Assert.That(() => _resultOperator.CheckSequenceItemType(sequenceInfo, expectedItemType), Throws.Nothing); }
public void CheckSequenceItemType_ExpectedAssignableFromSequenceItem() { var sequenceInfo = new StreamedSequenceInfo(typeof(string[]), Expression.Constant("t")); var expectedItemType = typeof(object); Assert.That(() => _resultOperator.CheckSequenceItemType(sequenceInfo, expectedItemType), Throws.Nothing); }
public void GetOutputDataInfo_DefaultWhenEmpty () { var studentExpression = Expression.Constant (new Cook ()); var input = new StreamedSequenceInfo (typeof (Cook[]), studentExpression); Assert.That (((StreamedSingleValueInfo) _resultOperatorWithDefaultWhenEmpty.GetOutputDataInfo (input)).ReturnDefaultWhenEmpty, Is.True); Assert.That (((StreamedSingleValueInfo) _resultOperatorNoDefaultWhenEmpty.GetOutputDataInfo (input)).ReturnDefaultWhenEmpty, Is.False); }
public void UpdateDataInfo() { var streamDataInfo = new StreamedSequenceInfo(typeof(Cook[]), Expression.Constant(new Cook())); _handler.UpdateDataInfo(_resultOperator, _statementBuilder, streamDataInfo); Assert.That(_statementBuilder.DataInfo, Is.TypeOf(typeof(StreamedSingleValueInfo))); }
private StreamedValueInfo GetOutputDataInfo([NotNull] StreamedSequenceInfo sequenceInfo) { var expectedItemType = GetExpectedItemType(); CheckSequenceItemType(sequenceInfo, expectedItemType); return(new StreamedScalarValueInfo(Func.Body.Type)); }
public void GetOutputDataInfo_DefaultWhenEmpty() { var studentExpression = Expression.Constant(new Cook()); var input = new StreamedSequenceInfo(typeof(Cook[]), studentExpression); Assert.That(((StreamedSingleValueInfo)_resultOperatorWithDefaultWhenEmpty.GetOutputDataInfo(input)).ReturnDefaultWhenEmpty, Is.True); Assert.That(((StreamedSingleValueInfo)_resultOperatorNoDefaultWhenEmpty.GetOutputDataInfo(input)).ReturnDefaultWhenEmpty, Is.False); }
private static TResult ExecuteResultOperator <TSource, TResult>( IEnumerable <TSource> source, ResultOperatorBase resultOperator, StreamedSequenceInfo streamedSequenceInfo) { var streamedData = resultOperator.ExecuteInMemory( new StreamedSequence(source, streamedSequenceInfo)); return((TResult)streamedData.Value); }
protected AsyncStreamedValueInfo GetOutputDataInfo(StreamedSequenceInfo streamedSequenceInfo) { if (streamedSequenceInfo == null) { throw new ArgumentNullException(nameof(streamedSequenceInfo)); } return(new AsyncStreamedScalarValueInfo(typeof(Task <long>))); }
public void GetOutputDataInfo_CovariantSequence () { var studentExpression = Expression.Constant (0.0f); var input = new StreamedSequenceInfo (typeof (object[]), studentExpression); var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (object))); }
public void MakeClosedGenericExecuteMethod_WithCovariantDataType() { var info = new StreamedSequenceInfo(typeof(IEnumerable <object>), _stringExpression); var executeMethod = typeof(CountResultOperator).GetMethod("ExecuteInMemory", new[] { typeof(StreamedSequence) }); var result = info.MakeClosedGenericExecuteMethod(executeMethod); Assert.That(result.GetGenericArguments(), Is.EqualTo(new[] { typeof(object) })); }
public void GetOutputDataInfo_OutputTypeEqualsItemTypeByDefault () { var studentExpression = Expression.Constant (new Cook ()); var input = new StreamedSequenceInfo (typeof (Cook[]), studentExpression); var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (Cook))); }
public void GetOutputDataInfo_WithoutResultSelector() { var itemExpression = Expression.Constant(0); var input = new StreamedSequenceInfo(typeof(int[]), itemExpression); var result = _resultOperatorWithoutResultSelector.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedScalarValueInfo))); Assert.That(result.DataType, Is.SameAs(typeof(int))); }
public void GetOutputDataInfo_NonMatchingFunc() { _resultOperatorWithResultSelector.Seed = Expression.Constant("0"); var itemExpression = Expression.Constant(0); var input = new StreamedSequenceInfo(typeof(int[]), itemExpression); _resultOperatorWithResultSelector.GetOutputDataInfo(input); }
public void GetOutputDataInfo () { var studentExpression = Expression.Constant (new Cook ()); var input = new StreamedSequenceInfo (typeof (object[]), studentExpression); var result = _resultOperatorNoDefaultWhenEmpty.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSingleValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (object))); }
public void GetOutputDataInfo() { var studentExpression = Expression.Constant(new Cook()); var input = new StreamedSequenceInfo(typeof(Cook[]), studentExpression); var result = _resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedValueInfo))); Assert.That(result.DataType, Is.SameAs(typeof(int))); }
private void CheckOutputDataInfo(Type itemType, Type expectedOutputType) { var itemExpression = Expression.Constant(Activator.CreateInstance(itemType), itemType); var inputInfo = new StreamedSequenceInfo(itemType.MakeArrayType(), itemExpression); var outputInfo = _resultOperator.GetOutputDataInfo(inputInfo); Assert.That(outputInfo, Is.InstanceOf(typeof(StreamedValueInfo))); Assert.That(outputInfo.DataType, Is.SameAs(expectedOutputType)); }
public void CheckSequenceItemType_DifferentTypes() { var sequenceInfo = new StreamedSequenceInfo(typeof(string[]), Expression.Constant("t")); var expectedItemType = typeof(int); Assert.That( () => _resultOperator.CheckSequenceItemType(sequenceInfo, expectedItemType), Throws.ArgumentException.With.Message.EqualTo( "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")); }
public void CheckSequenceItemType_SequenceItemAssignableFromExpected() { var sequenceInfo = new StreamedSequenceInfo(typeof(object[]), Expression.Constant(null, typeof(object))); var expectedItemType = typeof(string); Assert.That( () => _resultOperator.CheckSequenceItemType(sequenceInfo, expectedItemType), Throws.ArgumentException.With.Message.EqualTo( "The input sequence must have items of type 'System.String', but it has items of type 'System.Object'.\r\nParameter name: inputInfo")); }
public void AdjustDataType_GenericTypeDefinition_FromCovariantDataType() { var info = new StreamedSequenceInfo(typeof(IEnumerable <object>), _stringExpression); var result = info.AdjustDataType(typeof(IQueryable <>)); Assert.That(result, Is.Not.SameAs(info)); Assert.That(result, Is.TypeOf(typeof(StreamedSequenceInfo))); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <object>))); Assert.That(((StreamedSequenceInfo)result).ResultItemType, Is.SameAs(typeof(object))); Assert.That(((StreamedSequenceInfo)result).ItemExpression, Is.SameAs(_stringExpression)); }
public void GetOutputDataInfo () { var itemExpression = Expression.Constant (Expression.Constant (new Cook ())); var input = new StreamedSequenceInfo (typeof (object[]), itemExpression); // Works because int is assignable to object - the ItemExpression of type Cook isn't checked here var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedScalarValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (bool))); }
protected AsyncStreamedValueInfo GetOutputDataInfo(StreamedSequenceInfo streamedSequenceInfo) { if (streamedSequenceInfo == null) { throw new ArgumentNullException(nameof(streamedSequenceInfo)); } var resultType = typeof(Task <>).MakeGenericType(streamedSequenceInfo.ResultItemType); return(new AsyncStreamedScalarValueInfo(resultType)); }
protected AsyncStreamedValueInfo GetOutputDataInfo(StreamedSequenceInfo streamedSequenceInfo) { if (streamedSequenceInfo == null) { throw new ArgumentNullException(nameof(streamedSequenceInfo)); } var taskType = typeof(Task <>).MakeGenericType(streamedSequenceInfo.ResultItemType); return(new AsyncStreamedSingleValueInfo(taskType, ReturnDefaultWhenEmpty)); }
public void GetOutputDataInfo() { var itemExpression = Expression.Constant(Expression.Constant(new Cook())); var input = new StreamedSequenceInfo(typeof(object[]), itemExpression); // Works because int is assignable to object - the ItemExpression of type Cook isn't checked here var result = _resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedScalarValueInfo))); Assert.That(result.DataType, Is.SameAs(typeof(bool))); }
public void GetOutputDataInfo_Covariant() { var func = CreateFunc <IComparable, IComparable, string> ((i1, i2) => null); var resultOperator = new AggregateResultOperator(func); var itemExpression = Expression.Constant("test"); var input = new StreamedSequenceInfo(typeof(string[]), itemExpression); var result = resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedScalarValueInfo))); Assert.That(result.DataType, Is.SameAs(typeof(string))); }
public void GetOutputDataInfo() { var cookExpression = Expression.Constant(new Cook()); var input = new StreamedSequenceInfo(typeof(object[]), cookExpression); var result = _resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedSequenceInfo))); Assert.That(result, Is.Not.SameAs(input)); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <object>))); Assert.That(((StreamedSequenceInfo)result).ItemExpression, Is.SameAs(cookExpression)); Assert.That(((StreamedSequenceInfo)result).ResultItemType, Is.SameAs(typeof(object))); }
public void GetOutputDataInfo () { var cookExpression = Expression.Constant (new Cook ()); var input = new StreamedSequenceInfo (typeof (object[]), cookExpression); var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSequenceInfo))); Assert.That (result, Is.Not.SameAs (input)); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<object>))); Assert.That (((StreamedSequenceInfo) result).ItemExpression, Is.SameAs (cookExpression)); Assert.That (((StreamedSequenceInfo) result).ResultItemType, Is.SameAs (typeof (object))); }
public void GetOutputDataInfo_AssignableSource2() { var resultOperator = new UnionResultOperator("i", typeof(object), Expression.Constant(new[] { "string" })); var cookExpression = Expression.Constant(null, typeof(Cook)); var input = new StreamedSequenceInfo(typeof(Cook[]), cookExpression); var result = resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedSequenceInfo))); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <object>))); }
public void GetOutputDataInfo() { var intExpression = Expression.Constant(0); var input = new StreamedSequenceInfo(typeof(int[]), intExpression); var result = _resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedSequenceInfo))); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <IGrouping <int, string> >))); Assert.That(((StreamedSequenceInfo)result).ItemExpression, Is.InstanceOf(typeof(QuerySourceReferenceExpression))); Assert.That(((QuerySourceReferenceExpression)((StreamedSequenceInfo)result).ItemExpression).ReferencedQuerySource, Is.SameAs(_resultOperator)); }
protected void CheckSequenceItemType(StreamedSequenceInfo inputInfo, Type expectedItemType) { if (!expectedItemType.GetTypeInfo().IsAssignableFrom(inputInfo.ResultItemType.GetTypeInfo())) { var message = string.Format( "The input sequence must have items of type '{0}', but it has items of type '{1}'.", expectedItemType, inputInfo.ResultItemType); throw new ArgumentException(message, "inputInfo"); } }
/// <summary> /// Checks the type of the items retrieved by the sequence, throwing an <see cref="ArgumentTypeException"/> if the items don't match the /// expected type. /// </summary> /// <param name="sequenceInfo">The <see cref="StreamedSequenceInfo"/> object describing the sequence.</param> /// <param name="expectedItemType">The expected item type.</param> /// <exception cref="ArgumentTypeException">The items don't match the expected type.</exception> protected void CheckSequenceItemType(StreamedSequenceInfo sequenceInfo, Type expectedItemType) { if (sequenceInfo.ItemExpression.Type != expectedItemType) { var message = string.Format( "The input sequence must have items of type '{0}', but it has items of type '{1}'.", expectedItemType, sequenceInfo.ItemExpression.Type); throw new ArgumentTypeException(message, "inputInfo", typeof(IEnumerable <>).MakeGenericType(expectedItemType), sequenceInfo.ItemExpression.Type); } }
public void GetOutputDataInfo() { var studentExpression = Expression.Constant(new Cook()); var input = new StreamedSequenceInfo(typeof(Cook[]), studentExpression); var result = _resultOperator.GetOutputDataInfo(input); Assert.That(result, Is.InstanceOf(typeof(StreamedSequenceInfo))); Assert.That(result.DataType, Is.SameAs(typeof(IQueryable <Chef>))); Assert.That(((StreamedSequenceInfo)result).ItemExpression, Is.InstanceOf(typeof(UnaryExpression))); Assert.That(((StreamedSequenceInfo)result).ItemExpression.NodeType, Is.EqualTo(ExpressionType.Convert)); Assert.That(((StreamedSequenceInfo)result).ResultItemType, Is.SameAs(typeof(Chef))); Assert.That(((UnaryExpression)((StreamedSequenceInfo)result).ItemExpression).Operand, Is.SameAs(input.ItemExpression)); }
public void GetOutputDataInfo () { var studentExpression = Expression.Constant (new Cook()); var input = new StreamedSequenceInfo (typeof (Cook[]), studentExpression); var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSequenceInfo))); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<Chef>))); Assert.That (((StreamedSequenceInfo) result).ItemExpression, Is.InstanceOf (typeof (UnaryExpression))); Assert.That (((StreamedSequenceInfo) result).ItemExpression.NodeType, Is.EqualTo (ExpressionType.Convert)); Assert.That (((StreamedSequenceInfo) result).ResultItemType, Is.SameAs (typeof (Chef))); Assert.That (((UnaryExpression) ((StreamedSequenceInfo) result).ItemExpression).Operand, Is.SameAs (input.ItemExpression)); }
public void ResolveSelectExpression_SqlSubStatementExpressionWithStreamedSingleValueInfo () { var sqlStatement = SqlStatementModelObjectMother.CreateSqlStatement_Single(); var expression = new SqlSubStatementExpression (sqlStatement); var sqlStatementBuilder = new SqlStatementBuilder (); _resolverMock .Expect (mock => mock.ResolveConstantExpression (((ConstantExpression) sqlStatement.SelectProjection))) .Return (sqlStatement.SelectProjection); _resolverMock.Replay (); var result = _stage.ResolveSelectExpression (expression, sqlStatementBuilder, _mappingResolutionContext); _resolverMock.VerifyAllExpectations (); var expectedDataInfo = new StreamedSequenceInfo (typeof (IEnumerable<>).MakeGenericType (sqlStatement.DataInfo.DataType), sqlStatement.SelectProjection); var expectedSqlStatement = new SqlStatementBuilder (sqlStatement) { DataInfo = expectedDataInfo }.GetSqlStatement (); Assert.That (sqlStatementBuilder.SqlTables.Count, Is.EqualTo (1)); Assert.That (((ResolvedSubStatementTableInfo) ((SqlTable) sqlStatementBuilder.SqlTables[0]).TableInfo).SqlStatement, Is.EqualTo (expectedSqlStatement)); Assert.That (result, Is.SameAs (sqlStatement.SelectProjection)); }
public void SetUp () { _stringExpression = Expression.Constant ("dummy"); _infoWithStringSequence = new StreamedSequenceInfo (typeof (string[]), _stringExpression); }
public void AdjustDataType_GenericTypeDefinition_FromCovariantDataType () { var info = new StreamedSequenceInfo (typeof (IEnumerable<object>), _stringExpression); var result = info.AdjustDataType (typeof (IQueryable<>)); Assert.That (result, Is.Not.SameAs (info)); Assert.That (result, Is.TypeOf (typeof (StreamedSequenceInfo))); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<object>))); Assert.That (((StreamedSequenceInfo) result).ResultItemType, Is.SameAs (typeof (object))); Assert.That (((StreamedSequenceInfo) result).ItemExpression, Is.SameAs (_stringExpression)); }
public void ResolveTableInfo_GroupReferenceTableInfo () { var sqlTable = SqlStatementModelObjectMother.CreateSqlTable (typeof (Cook)); var groupingSelect = new SqlGroupingSelectExpression ( Expression.MakeMemberAccess (new SqlTableReferenceExpression (sqlTable), typeof (Cook).GetProperty ("Name")), Expression.MakeMemberAccess (new SqlTableReferenceExpression (sqlTable), typeof (Cook).GetProperty ("ID"))); var dataInfo = new StreamedSequenceInfo ( typeof (IEnumerable<>).MakeGenericType (groupingSelect.Type), Expression.Constant (null, groupingSelect.Type)); var whereCondition = Expression.Constant (false); var groupByExpression = groupingSelect.KeyExpression; var groupingSubStatement = new SqlStatementBuilder { DataInfo = dataInfo, SelectProjection = groupingSelect, SqlTables = { sqlTable }, WhereCondition = whereCondition, GroupByExpression = groupByExpression }.GetSqlStatement(); var groupSource = SqlStatementModelObjectMother.CreateSqlTable (new ResolvedSubStatementTableInfo ("q0", groupingSubStatement)); var tableInfo = new UnresolvedGroupReferenceTableInfo (groupSource); var expectedKeyViaElement = Expression.MakeMemberAccess (new SqlTableReferenceExpression (sqlTable), typeof (Cook).GetProperty ("Name")); var expectedKeyViaGroupSource = Expression.MakeMemberAccess (new SqlTableReferenceExpression (groupSource), groupSource.ItemType.GetProperty ("Key")); var expectedResultWhereCondition = Expression.OrElse ( Expression.AndAlso (new SqlIsNullExpression (expectedKeyViaElement), new SqlIsNullExpression (expectedKeyViaGroupSource)), Expression.AndAlso ( Expression.AndAlso (new SqlIsNotNullExpression (expectedKeyViaElement), new SqlIsNotNullExpression (expectedKeyViaGroupSource)), Expression.Equal (expectedKeyViaElement, expectedKeyViaGroupSource))); var fakeWhereCondition = Expression.Constant (false); _stageMock .Expect (mock => mock.ResolveWhereExpression (Arg<Expression>.Is.Anything, Arg.Is (_mappingResolutionContext))) .WhenCalled (mi => SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResultWhereCondition, (Expression) mi.Arguments[0])) .Return (fakeWhereCondition); _stageMock.Replay(); var result = ResolvingTableInfoVisitor.ResolveTableInfo (tableInfo, _resolverMock, _generator, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); Assert.That (result, Is.TypeOf (typeof (ResolvedJoinedGroupingTableInfo))); var castResult = ((ResolvedJoinedGroupingTableInfo) result); var resultGroupingSelector = castResult.AssociatedGroupingSelectExpression; Assert.That (resultGroupingSelector, Is.SameAs (groupingSelect)); Assert.That (castResult.GroupSourceTableAlias, Is.EqualTo ("q0")); var resultSqlStatement = castResult.SqlStatement; Assert.That (resultSqlStatement.SqlTables, Is.EqualTo (groupingSubStatement.SqlTables)); Assert.That (resultSqlStatement.Orderings, Is.Empty); Assert.That (resultSqlStatement.GroupByExpression, Is.Null); SqlExpressionTreeComparer.CheckAreEqualTrees ( Expression.AndAlso (groupingSubStatement.WhereCondition, fakeWhereCondition), resultSqlStatement.WhereCondition); var expectedResultSelectProjection = Expression.MakeMemberAccess (new SqlTableReferenceExpression (resultSqlStatement.SqlTables[0]), typeof (Cook).GetProperty ("ID")); SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResultSelectProjection, resultSqlStatement.SelectProjection); Assert.That (resultSqlStatement.DataInfo, Is.TypeOf (typeof (StreamedSequenceInfo))); Assert.That (resultSqlStatement.DataInfo.DataType, Is.SameAs (typeof (IQueryable<int>))); var expectedItemExpression = resultSqlStatement.SelectProjection; SqlExpressionTreeComparer.CheckAreEqualTrees (expectedItemExpression, ((StreamedSequenceInfo) resultSqlStatement.DataInfo).ItemExpression); }
public void CheckSequenceItemType_DifferentTypes () { var sequenceInfo = new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("t")); var expectedItemType = typeof (int); Assert.That ( () => _resultOperator.CheckSequenceItemType (sequenceInfo, expectedItemType), Throws.ArgumentException.With.Message.EqualTo ( "The input sequence must have items of type 'System.Int32', but it has items of type 'System.String'.\r\nParameter name: inputInfo")); }
private void CheckOutputDataInfo (Type itemType, Type expectedOutputType) { var itemExpression = Expression.Constant (Activator.CreateInstance (itemType), itemType); var inputInfo = new StreamedSequenceInfo (itemType.MakeArrayType(), itemExpression); var outputInfo = _resultOperator.GetOutputDataInfo (inputInfo); Assert.That (outputInfo, Is.InstanceOf (typeof (StreamedValueInfo))); Assert.That (outputInfo.DataType, Is.SameAs (expectedOutputType)); }
public void GetOutputDataInfo_InvalidInputItemType () { var input = new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("")); _resultOperator.GetOutputDataInfo (input); }
public void GetOutputDataInfo_WithDifferentAssignableSeedType () { var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); var seed = Expression.Constant ("string"); var func = Expression.Lambda ( Expression.Constant (null, typeof (object)), Expression.Parameter (typeof (object), "acc")); var resultOperator = new AggregateFromSeedResultOperator (seed, func, null); var result = resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedScalarValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (object))); }
public void GetOutputDataInfo_WithoutResultSelector () { var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); var result = _resultOperatorWithoutResultSelector.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedScalarValueInfo))); Assert.That (result.DataType, Is.SameAs (typeof (int))); }
private SqlStatement ConvertValueStatementToSequenceStatement () { var newDataInfo = new StreamedSequenceInfo (typeof (IEnumerable<>).MakeGenericType (SqlStatement.DataInfo.DataType), SqlStatement.SelectProjection); var adjustedStatementBuilder = new SqlStatementBuilder (SqlStatement) { DataInfo = newDataInfo }; if (SqlStatement.DataInfo is StreamedSingleValueInfo && SqlStatement.SqlTables.Count!=0) { // A sub-statement might use a different TopExpression than 1 (or none at all) in order to provoke a SQL error when more than one item is // returned. When we convert the statement to a sequence statement, however, we must ensure that the exact "only 1 value is returned" // semantics is ensured because we can't provoke a SQL error (but instead would return strange result sets). adjustedStatementBuilder.TopExpression = new SqlLiteralExpression (1); } return adjustedStatementBuilder.GetSqlStatement(); }
public void CheckSequenceItemType_SameType () { var sequenceInfo = new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0)); var expectedItemType = typeof (int); Assert.That (() => _resultOperator.CheckSequenceItemType (sequenceInfo, expectedItemType), Throws.Nothing); }
public void CheckSequenceItemType_ExpectedAssignableFromSequenceItem () { var sequenceInfo = new StreamedSequenceInfo (typeof (string[]), Expression.Constant ("t")); var expectedItemType = typeof (object); Assert.That (() => _resultOperator.CheckSequenceItemType (sequenceInfo, expectedItemType), Throws.Nothing); }
public void CheckSequenceItemType_SequenceItemAssignableFromExpected () { var sequenceInfo = new StreamedSequenceInfo (typeof (object[]), Expression.Constant (null, typeof (object))); var expectedItemType = typeof (string); Assert.That ( () => _resultOperator.CheckSequenceItemType (sequenceInfo, expectedItemType), Throws.ArgumentException.With.Message.EqualTo ( "The input sequence must have items of type 'System.String', but it has items of type 'System.Object'.\r\nParameter name: inputInfo")); }
protected StreamedSequenceInfo GetOutputDataInfo (StreamedSequenceInfo inputSequenceInfo) { ArgumentUtility.CheckNotNull ("inputSequenceInfo", inputSequenceInfo); return new StreamedSequenceInfo (typeof (IQueryable<>).MakeGenericType (inputSequenceInfo.ResultItemType), inputSequenceInfo.ItemExpression); }
public void GetOutputDataInfo_AssignableSource2 () { var resultOperator = new ConcatResultOperator ("i", typeof (object), Expression.Constant (new[] { "string" })); var cookExpression = Expression.Constant (null, typeof (Cook)); var input = new StreamedSequenceInfo (typeof (Cook[]), cookExpression); var result = resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSequenceInfo))); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<object>))); }
public void UpdateDataInfo () { var streamDataInfo = new StreamedSequenceInfo (typeof (Cook[]), Expression.Constant (new Cook())); _handler.UpdateDataInfo (_resultOperator, _statementBuilder, streamDataInfo); Assert.That (_statementBuilder.DataInfo, Is.TypeOf (typeof (StreamedSingleValueInfo))); }
public void GetOutputDataInfo () { var intExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), intExpression); var result = _resultOperator.GetOutputDataInfo (input); Assert.That (result, Is.InstanceOf (typeof (StreamedSequenceInfo))); Assert.That (result.DataType, Is.SameAs (typeof (IQueryable<int>))); Assert.That (((StreamedSequenceInfo) result).ItemExpression, Is.InstanceOf (typeof (QuerySourceReferenceExpression))); Assert.That ( ((QuerySourceReferenceExpression) ((StreamedSequenceInfo) result).ItemExpression).ReferencedQuerySource, Is.SameAs (_resultOperator)); }
public void VisitSqlStatement_EverthingIsCopiedIfSelectionProjectionHasChanged () { var selectProjection = Expression.Constant("select"); var whereCondition = Expression.Constant(true); var topExpression = Expression.Constant("top"); var dataInfo = new StreamedSequenceInfo(typeof(Cook[]), Expression.Constant(new Cook())); var builder = new SqlStatementBuilder () { SelectProjection = selectProjection, WhereCondition = whereCondition, TopExpression = topExpression, IsDistinctQuery = true, DataInfo = dataInfo }; var sqlTable = new SqlTable (new ResolvedSimpleTableInfo (typeof (Cook), "CookTable", "c"), JoinSemantics.Inner); builder.SqlTables.Add (sqlTable); var ordering = new Ordering (Expression.Constant ("order"),OrderingDirection.Asc); builder.Orderings.Add (ordering); var sqlStatement = builder.GetSqlStatement(); var fakeResult = Expression.Constant ("fake"); _stageMock .Expect (mock => mock.ApplyContext (sqlStatement.SelectProjection, SqlExpressionContext.ValueRequired, _mappingResolutionContext)) .Return (fakeResult); _stageMock.Replay (); var result = SqlContextSelectionAdjuster.ApplyContext (sqlStatement, SqlExpressionContext.ValueRequired, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); Assert.That (result.SelectProjection, Is.SameAs (fakeResult)); Assert.That (result.DataInfo, Is.SameAs (dataInfo)); Assert.That (result.WhereCondition, Is.SameAs (whereCondition)); Assert.That (result.TopExpression, Is.SameAs (topExpression)); Assert.That (result.SqlTables[0], Is.SameAs (sqlTable)); Assert.That (result.Orderings[0], Is.SameAs (ordering)); Assert.That (result.IsDistinctQuery, Is.True); }
public void GetOutputDataInfo_NonMatchingFunc () { _resultOperatorWithResultSelector.Seed = Expression.Constant ("0"); var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); _resultOperatorWithResultSelector.GetOutputDataInfo (input); }
public void MakeClosedGenericExecuteMethod_WithCovariantDataType () { var info = new StreamedSequenceInfo (typeof (IEnumerable<object>), _stringExpression); var executeMethod = typeof (CountResultOperator).GetMethod ("ExecuteInMemory", new[] { typeof (StreamedSequence) }); var result = info.MakeClosedGenericExecuteMethod (executeMethod); Assert.That (result.GetGenericArguments (), Is.EqualTo (new[] { typeof (object) })); }
public void GetOutputDataInfo_NonMatchingResultSelector () { var resultSelector = Expression.Lambda ( typeof (Func<string, int>), Expression.Constant (0), Expression.Parameter (typeof (string), "i")); _resultOperatorWithResultSelector.OptionalResultSelector = resultSelector; var itemExpression = Expression.Constant (0); var input = new StreamedSequenceInfo (typeof (int[]), itemExpression); _resultOperatorWithResultSelector.GetOutputDataInfo (input); }
public void RecalculateDataInfo (Expression previousSelectProjection) { if (SelectProjection.Type != previousSelectProjection.Type) // TODO: Consider removing this check and the parameter { var sequenceInfo = DataInfo as StreamedSequenceInfo; if (sequenceInfo != null) DataInfo = new StreamedSequenceInfo (typeof (IQueryable<>).MakeGenericType (SelectProjection.Type), SelectProjection); var singleValueInfo = DataInfo as StreamedSingleValueInfo; if (singleValueInfo != null) DataInfo = new StreamedSingleValueInfo (SelectProjection.Type, singleValueInfo.ReturnDefaultWhenEmpty); // For scalar queries, the DataInfo never needs to be recalculated. } }