-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RMLNQ-28 Implement AsQueryableResultOperator to add AsQueryable to th…
…e QueryModel.
- Loading branch information
1 parent
f078bf9
commit c477aea
Showing
7 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) rubicon IT GmbH, www.rubicon.eu | ||
// | ||
// See the NOTICE file distributed with this work for additional information | ||
// regarding copyright ownership. rubicon licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may not use this | ||
// file except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Remotion.Linq.Clauses.StreamedData; | ||
using Remotion.Utilities; | ||
|
||
namespace Remotion.Linq.Clauses.ResultOperators | ||
{ | ||
/// <summary> | ||
/// Represents the transformation of a sequence to a query data source. | ||
/// This is a result operator, operating on the whole result set of a query. | ||
/// </summary> | ||
/// <example> | ||
/// In C#, the "AsQueryable" call in the following example corresponds to a <see cref="AsQueryableResultOperator"/>. | ||
/// <code> | ||
/// var query = (from s in Students | ||
/// select s).AsQueryable(); | ||
/// </code> | ||
/// </example> | ||
public sealed class AsQueryableResultOperator : SequenceTypePreservingResultOperatorBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AsQueryableResultOperator"/>. | ||
/// </summary> | ||
public AsQueryableResultOperator () | ||
{ | ||
} | ||
|
||
public override ResultOperatorBase Clone (CloneContext cloneContext) | ||
{ | ||
return new AsQueryableResultOperator(); | ||
} | ||
|
||
public override StreamedSequence ExecuteInMemory<T> (StreamedSequence input) | ||
{ | ||
var sequence = input.GetTypedSequence<T>(); | ||
return new StreamedSequence (sequence.AsQueryable(), GetOutputDataInfo (input.DataInfo)); | ||
} | ||
|
||
public override void TransformExpressions (Func<Expression, Expression> transformation) | ||
{ | ||
//nothing to do here | ||
} | ||
|
||
public override string ToString () | ||
{ | ||
return "AsQueryable()"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
UnitTests/Clauses/ResultOperators/AsQueryableResultOperatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) rubicon IT GmbH, www.rubicon.eu | ||
// | ||
// See the NOTICE file distributed with this work for additional information | ||
// regarding copyright ownership. rubicon licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may not use this | ||
// file except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
using System; | ||
using System.Collections; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using NUnit.Framework; | ||
using Remotion.Linq.Clauses; | ||
using Remotion.Linq.Clauses.ResultOperators; | ||
using Remotion.Linq.Clauses.StreamedData; | ||
|
||
namespace Remotion.Linq.UnitTests.Clauses.ResultOperators | ||
{ | ||
[TestFixture] | ||
public class AsQueryableResultOperatorTest | ||
{ | ||
private AsQueryableResultOperator _resultOperator; | ||
|
||
[SetUp] | ||
public void SetUp () | ||
{ | ||
_resultOperator = new AsQueryableResultOperator(); | ||
} | ||
|
||
[Test] | ||
public void Clone () | ||
{ | ||
var clonedClauseMapping = new QuerySourceMapping(); | ||
var cloneContext = new CloneContext (clonedClauseMapping); | ||
var clone = _resultOperator.Clone (cloneContext); | ||
|
||
Assert.That (clone, Is.InstanceOf (typeof (AsQueryableResultOperator))); | ||
} | ||
|
||
[Test] | ||
public void ExecuteInMemory () | ||
{ | ||
IEnumerable items = new[] { 1, 2, 3, 0, 2 }; | ||
var input = new StreamedSequence (items, new StreamedSequenceInfo (typeof (int[]), Expression.Constant (0))); | ||
var result = _resultOperator.ExecuteInMemory<int> (input); | ||
|
||
Assert.That (result.GetTypedSequence<int>().ToArray(), Is.EqualTo (new[] { 1, 2, 3, 0, 2 })); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters