Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added in Tim Kellogg's tests for ordering by value types.

  • Loading branch information...
commit cafb0b66be27c00fedf7823aaf44a93632841b5d 1 parent 619fe7f
@craiggwilson craiggwilson authored
View
27 MongoDB.DriverUnitTests/Linq/SelectQueryTests.cs
@@ -24,6 +24,7 @@
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;
+using System.Linq.Expressions;
namespace MongoDB.DriverUnitTests.Linq
{
@@ -1342,6 +1343,32 @@ public void TestMinXYWithSelector()
}
[Test]
+ public void TestOrderByValueTypeWithObjectReturnType()
+ {
+ Expression<Func<C, object>> orderByClause = c => c.LX;
+ var query = _collection.AsQueryable<C>().OrderBy(orderByClause);
+
+ RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (Object)c.LX");
+ }
+
+ [Test]
+ public void TestOrderByValueTypeWithIComparableReturnType()
+ {
+ Expression<Func<C, IComparable>> orderByClause = c => c.LX;
+ var query = _collection.AsQueryable<C>().OrderBy(orderByClause);
+
+ RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (IComparable)c.LX");
+ }
+
+ private void RunTestOrderByValueTypeWithMismatchingType(IOrderedQueryable query, string orderByString)
+ {
+ var mongoQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(mongoQuery);
+ var selectQuery = (SelectQuery) mongoQuery;
+ Assert.AreEqual(orderByString, ExpressionFormatter.ToString(selectQuery.OrderBy[0].Key));
+ }
+
+ [Test]
public void TestOrderByAscending()
{
var query = from c in _collection.AsQueryable<C>()
View
42 MongoDB.DriverUnitTestsVB/Linq/SelectQueryTests.vb
@@ -25,6 +25,7 @@ Imports MongoDB.Bson.Serialization.Attributes
Imports MongoDB.Driver
Imports MongoDB.Driver.Builders
Imports MongoDB.Driver.Linq
+Imports System.Linq.Expressions
Namespace MongoDB.DriverUnitTests.Linq
<TestFixture()> _
@@ -1265,6 +1266,29 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.AreEqual(11, result.Y)
End Sub
+ <Test()>
+ Public Sub TestOrderByValueTypeWithObjectReturnType()
+ Dim orderByClause As Expression(Of Func(Of C, Object)) = Function(c) c.LX
+ Dim query = _collection.AsQueryable(Of C)().OrderBy(orderByClause)
+
+ RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (Object)c.LX")
+ End Sub
+
+ <Test()>
+ Public Sub TestOrderByValueTypeWithIComparableReturnType()
+ Dim orderByClause As Expression(Of Func(Of C, IComparable)) = Function(c) c.LX
+ Dim query = _collection.AsQueryable(Of C)().OrderBy(orderByClause)
+
+ RunTestOrderByValueTypeWithMismatchingType(query, "(C c) => (IComparable)c.LX")
+ End Sub
+
+ Sub RunTestOrderByValueTypeWithMismatchingType(ByVal query As IOrderedQueryable, ByVal orderByString As String)
+ Dim mongoQuery = MongoQueryTranslator.Translate(query)
+ Assert.IsInstanceOf(Of SelectQuery)(mongoQuery)
+ Dim selectQuery As SelectQuery = mongoQuery
+ Assert.AreEqual(orderByString, ExpressionFormatter.ToString(selectQuery.OrderBy(0).Key))
+ End Sub
+
<Test()> _
Public Sub TestOrderByAscending()
Dim query = From c In _collection.AsQueryable(Of C)()
@@ -1974,7 +1998,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.IsNull(selectQuery.Take)
Assert.AreEqual("{ ""a"" : { ""$all"" : [2, 3] } }", selectQuery.BuildQuery().ToJson())
- Assert.AreEqual(1, Consume(Query))
+ Assert.AreEqual(1, Consume(query))
End Sub
<Test()> _
@@ -2655,7 +2679,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Where c.DA.Any(Function(x) x.Z = 333)
Select c
- Dim translatedQuery = MongoQueryTranslator.Translate(Query)
+ Dim translatedQuery = MongoQueryTranslator.Translate(query)
Assert.IsInstanceOf(Of SelectQuery)(translatedQuery)
Assert.AreSame(_collection, translatedQuery.Collection)
Assert.AreSame(GetType(C), translatedQuery.DocumentType)
@@ -2668,7 +2692,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.IsNull(selectQuery.Take)
Assert.AreEqual("{ ""da"" : { ""$elemMatch"" : { ""z"" : 333 } } }", selectQuery.BuildQuery().ToJson())
- Assert.AreEqual(1, Consume(Query))
+ Assert.AreEqual(1, Consume(query))
End Sub
@@ -2786,7 +2810,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Where Not (c.DBRef <> New MongoDBRef("db", "c", 1))
Select c
- Dim translatedQuery = MongoQueryTranslator.Translate(Query)
+ Dim translatedQuery = MongoQueryTranslator.Translate(query)
Assert.IsInstanceOf(Of SelectQuery)(translatedQuery)
Assert.AreSame(_collection, translatedQuery.Collection)
Assert.AreSame(GetType(C), translatedQuery.DocumentType)
@@ -2799,7 +2823,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.IsNull(selectQuery.Take)
Assert.AreEqual("{ ""dbref"" : { ""$ref"" : ""c"", ""$id"" : 1, ""$db"" : ""db"" } }", selectQuery.BuildQuery().ToJson())
- Assert.AreEqual(1, Consume(Query))
+ Assert.AreEqual(1, Consume(query))
End Sub
<Test()> _
@@ -2987,7 +3011,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Where Not c.EA.ContainsAny({E.A, E.B})
Select c
- Dim translatedQuery = MongoQueryTranslator.Translate(Query)
+ Dim translatedQuery = MongoQueryTranslator.Translate(query)
Assert.IsInstanceOf(Of SelectQuery)(translatedQuery)
Assert.AreSame(_collection, translatedQuery.Collection)
Assert.AreSame(GetType(C), translatedQuery.DocumentType)
@@ -3000,7 +3024,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.IsNull(selectQuery.Take)
Assert.AreEqual("{ ""ea"" : { ""$nin"" : [1, 2] } }", selectQuery.BuildQuery().ToJson())
- Assert.AreEqual(4, Consume(Query))
+ Assert.AreEqual(4, Consume(query))
End Sub
<Test()> _
@@ -4927,7 +4951,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Where c.S.Length = 3
Select c
- Dim translatedQuery = MongoQueryTranslator.Translate(Query)
+ Dim translatedQuery = MongoQueryTranslator.Translate(query)
Assert.IsInstanceOf(Of SelectQuery)(translatedQuery)
Assert.AreSame(_collection, translatedQuery.Collection)
Assert.AreSame(GetType(C), translatedQuery.DocumentType)
@@ -4940,7 +4964,7 @@ Namespace MongoDB.DriverUnitTests.Linq
Assert.IsNull(selectQuery.Take)
Assert.AreEqual("{ ""s"" : /^.{3}$/s }", selectQuery.BuildQuery().ToJson())
- Assert.AreEqual(1, Consume(Query))
+ Assert.AreEqual(1, Consume(query))
End Sub
<Test()> _

0 comments on commit cafb0b6

Please sign in to comment.
Something went wrong with that request. Please try again.