Permalink
Browse files

There are 5 unit tests that are failing when run against servers olde…

…r than 2.0 due to server changes that have not been backported to 1.8.5. These 5 unit tests are now skipped when the server is older than 2.0.
  • Loading branch information...
rstam
rstam committed Apr 16, 2012
1 parent 98d73c9 commit 8a5086ddb599a249aa31764fcbb4b08d4da3e7bf
Showing with 108 additions and 93 deletions.
  1. +23 −20 DriverUnitTests/Linq/SelectOfTypeHierarchicalTests.cs
  2. +85 −73 DriverUnitTests/Linq/SelectQueryTests.cs
@@ -252,26 +252,29 @@ public void TestWhereBIsD()
[Test]
public void TestWhereBTypeEqualsB()
{
- var query =
- from b in _collection.AsQueryable<B>()
- where b.GetType() == typeof(B)
- select b;
-
- var translatedQuery = MongoQueryTranslator.Translate(query);
- Assert.IsInstanceOf<SelectQuery>(translatedQuery);
- Assert.AreSame(_collection, translatedQuery.Collection);
- Assert.AreSame(typeof(B), translatedQuery.DocumentType);
-
- var selectQuery = (SelectQuery)translatedQuery;
- Assert.AreEqual("(B b) => (b.GetType() == typeof(B))", ExpressionFormatter.ToString(selectQuery.Where));
- Assert.AreEqual(null, selectQuery.OfType); // OfType ignored because <T> was the same as <TDocument>
- Assert.IsNull(selectQuery.OrderBy);
- Assert.IsNull(selectQuery.Projection);
- Assert.IsNull(selectQuery.Skip);
- Assert.IsNull(selectQuery.Take);
-
- Assert.AreEqual("{ \"_t.0\" : { \"$exists\" : false }, \"_t\" : \"B\" }", selectQuery.BuildQuery().ToJson());
- Assert.AreEqual(1, Consume(query));
+ if (_server.BuildInfo.Version >= new Version(2, 0))
+ {
+ var query =
+ from b in _collection.AsQueryable<B>()
+ where b.GetType() == typeof(B)
+ select b;
+
+ var translatedQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(translatedQuery);
+ Assert.AreSame(_collection, translatedQuery.Collection);
+ Assert.AreSame(typeof(B), translatedQuery.DocumentType);
+
+ var selectQuery = (SelectQuery)translatedQuery;
+ Assert.AreEqual("(B b) => (b.GetType() == typeof(B))", ExpressionFormatter.ToString(selectQuery.Where));
+ Assert.AreEqual(null, selectQuery.OfType); // OfType ignored because <T> was the same as <TDocument>
+ Assert.IsNull(selectQuery.OrderBy);
+ Assert.IsNull(selectQuery.Projection);
+ Assert.IsNull(selectQuery.Skip);
+ Assert.IsNull(selectQuery.Take);
+
+ Assert.AreEqual("{ \"_t.0\" : { \"$exists\" : false }, \"_t\" : \"B\" }", selectQuery.BuildQuery().ToJson());
+ Assert.AreEqual(1, Consume(query));
+ }
}
[Test]
@@ -5567,25 +5567,28 @@ public void TestWhereSystemProfileInfoTimeStampGreatherThanJan12012()
[Test]
public void TestWhereTripleAnd()
{
- // the query is a bit odd in order to force the built query to be promoted to $and form
- var query = from c in _collection.AsQueryable<C>()
- where c.X >= 0 && c.X >= 1 && c.Y == 11
- select c;
-
- var translatedQuery = MongoQueryTranslator.Translate(query);
- Assert.IsInstanceOf<SelectQuery>(translatedQuery);
- Assert.AreSame(_collection, translatedQuery.Collection);
- Assert.AreSame(typeof(C), translatedQuery.DocumentType);
-
- var selectQuery = (SelectQuery)translatedQuery;
- Assert.AreEqual("(C c) => (((c.X >= 0) && (c.X >= 1)) && (c.Y == 11))", ExpressionFormatter.ToString(selectQuery.Where));
- Assert.IsNull(selectQuery.OrderBy);
- Assert.IsNull(selectQuery.Projection);
- Assert.IsNull(selectQuery.Skip);
- Assert.IsNull(selectQuery.Take);
-
- Assert.AreEqual("{ \"$and\" : [{ \"x\" : { \"$gte\" : 0 } }, { \"x\" : { \"$gte\" : 1 } }, { \"y\" : 11 }] }", selectQuery.BuildQuery().ToJson());
- Assert.AreEqual(2, Consume(query));
+ if (_server.BuildInfo.Version >= new Version(2, 0))
+ {
+ // the query is a bit odd in order to force the built query to be promoted to $and form
+ var query = from c in _collection.AsQueryable<C>()
+ where c.X >= 0 && c.X >= 1 && c.Y == 11
+ select c;
+
+ var translatedQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(translatedQuery);
+ Assert.AreSame(_collection, translatedQuery.Collection);
+ Assert.AreSame(typeof(C), translatedQuery.DocumentType);
+
+ var selectQuery = (SelectQuery)translatedQuery;
+ Assert.AreEqual("(C c) => (((c.X >= 0) && (c.X >= 1)) && (c.Y == 11))", ExpressionFormatter.ToString(selectQuery.Where));
+ Assert.IsNull(selectQuery.OrderBy);
+ Assert.IsNull(selectQuery.Projection);
+ Assert.IsNull(selectQuery.Skip);
+ Assert.IsNull(selectQuery.Take);
+
+ Assert.AreEqual("{ \"$and\" : [{ \"x\" : { \"$gte\" : 0 } }, { \"x\" : { \"$gte\" : 1 } }, { \"y\" : 11 }] }", selectQuery.BuildQuery().ToJson());
+ Assert.AreEqual(2, Consume(query));
+ }
}
[Test]
@@ -6265,70 +6268,79 @@ public void TestWhereXLessThanOrEquals1Reversed()
[Test]
public void TestWhereXModOneEquals0AndXModTwoEquals0()
{
- var query = from c in _collection.AsQueryable<C>()
- where (c.X % 1 == 0) && (c.X % 2 == 0)
- select c;
-
- var translatedQuery = MongoQueryTranslator.Translate(query);
- Assert.IsInstanceOf<SelectQuery>(translatedQuery);
- Assert.AreSame(_collection, translatedQuery.Collection);
- Assert.AreSame(typeof(C), translatedQuery.DocumentType);
-
- var selectQuery = (SelectQuery)translatedQuery;
- Assert.AreEqual("(C c) => (((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
- Assert.IsNull(selectQuery.OrderBy);
- Assert.IsNull(selectQuery.Projection);
- Assert.IsNull(selectQuery.Skip);
- Assert.IsNull(selectQuery.Take);
-
- Assert.AreEqual("{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }", selectQuery.BuildQuery().ToJson());
- Assert.AreEqual(2, Consume(query));
+ if (_server.BuildInfo.Version >= new Version(2, 0))
+ {
+ var query = from c in _collection.AsQueryable<C>()
+ where (c.X % 1 == 0) && (c.X % 2 == 0)
+ select c;
+
+ var translatedQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(translatedQuery);
+ Assert.AreSame(_collection, translatedQuery.Collection);
+ Assert.AreSame(typeof(C), translatedQuery.DocumentType);
+
+ var selectQuery = (SelectQuery)translatedQuery;
+ Assert.AreEqual("(C c) => (((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
+ Assert.IsNull(selectQuery.OrderBy);
+ Assert.IsNull(selectQuery.Projection);
+ Assert.IsNull(selectQuery.Skip);
+ Assert.IsNull(selectQuery.Take);
+
+ Assert.AreEqual("{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }", selectQuery.BuildQuery().ToJson());
+ Assert.AreEqual(2, Consume(query));
+ }
}
[Test]
public void TestWhereXModOneEquals0AndXModTwoEquals0Not()
{
- var query = from c in _collection.AsQueryable<C>()
- where !((c.X % 1 == 0) && (c.X % 2 == 0))
- select c;
-
- var translatedQuery = MongoQueryTranslator.Translate(query);
- Assert.IsInstanceOf<SelectQuery>(translatedQuery);
- Assert.AreSame(_collection, translatedQuery.Collection);
- Assert.AreSame(typeof(C), translatedQuery.DocumentType);
-
- var selectQuery = (SelectQuery)translatedQuery;
- Assert.AreEqual("(C c) => !(((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
- Assert.IsNull(selectQuery.OrderBy);
- Assert.IsNull(selectQuery.Projection);
- Assert.IsNull(selectQuery.Skip);
- Assert.IsNull(selectQuery.Take);
-
- Assert.AreEqual("{ \"$nor\" : [{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }] }", selectQuery.BuildQuery().ToJson());
- Assert.AreEqual(3, Consume(query));
+ if (_server.BuildInfo.Version >= new Version(2, 0))
+ {
+ var query = from c in _collection.AsQueryable<C>()
+ where !((c.X % 1 == 0) && (c.X % 2 == 0))
+ select c;
+
+ var translatedQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(translatedQuery);
+ Assert.AreSame(_collection, translatedQuery.Collection);
+ Assert.AreSame(typeof(C), translatedQuery.DocumentType);
+
+ var selectQuery = (SelectQuery)translatedQuery;
+ Assert.AreEqual("(C c) => !(((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
+ Assert.IsNull(selectQuery.OrderBy);
+ Assert.IsNull(selectQuery.Projection);
+ Assert.IsNull(selectQuery.Skip);
+ Assert.IsNull(selectQuery.Take);
+
+ Assert.AreEqual("{ \"$nor\" : [{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }] }", selectQuery.BuildQuery().ToJson());
+ Assert.AreEqual(3, Consume(query));
+ }
}
[Test]
public void TestWhereXModOneEquals0AndXModTwoEquals0NotNot()
{
- var query = from c in _collection.AsQueryable<C>()
- where !!((c.X % 1 == 0) && (c.X % 2 == 0))
- select c;
-
- var translatedQuery = MongoQueryTranslator.Translate(query);
- Assert.IsInstanceOf<SelectQuery>(translatedQuery);
- Assert.AreSame(_collection, translatedQuery.Collection);
- Assert.AreSame(typeof(C), translatedQuery.DocumentType);
-
- var selectQuery = (SelectQuery)translatedQuery;
- Assert.AreEqual("(C c) => !!(((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
- Assert.IsNull(selectQuery.OrderBy);
- Assert.IsNull(selectQuery.Projection);
- Assert.IsNull(selectQuery.Skip);
- Assert.IsNull(selectQuery.Take);
-
- Assert.AreEqual("{ \"$or\" : [{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }] }", selectQuery.BuildQuery().ToJson());
- Assert.AreEqual(2, Consume(query));
+ if (_server.BuildInfo.Version >= new Version(2, 0))
+ {
+ var query = from c in _collection.AsQueryable<C>()
+ where !!((c.X % 1 == 0) && (c.X % 2 == 0))
+ select c;
+
+ var translatedQuery = MongoQueryTranslator.Translate(query);
+ Assert.IsInstanceOf<SelectQuery>(translatedQuery);
+ Assert.AreSame(_collection, translatedQuery.Collection);
+ Assert.AreSame(typeof(C), translatedQuery.DocumentType);
+
+ var selectQuery = (SelectQuery)translatedQuery;
+ Assert.AreEqual("(C c) => !!(((c.X % 1) == 0) && ((c.X % 2) == 0))", ExpressionFormatter.ToString(selectQuery.Where));
+ Assert.IsNull(selectQuery.OrderBy);
+ Assert.IsNull(selectQuery.Projection);
+ Assert.IsNull(selectQuery.Skip);
+ Assert.IsNull(selectQuery.Take);
+
+ Assert.AreEqual("{ \"$or\" : [{ \"$and\" : [{ \"x\" : { \"$mod\" : [1, 0] } }, { \"x\" : { \"$mod\" : [2, 0] } }] }] }", selectQuery.BuildQuery().ToJson());
+ Assert.AreEqual(2, Consume(query));
+ }
}
[Test]

0 comments on commit 8a5086d

Please sign in to comment.