public void TestWhereDContainsKeyZ()
        {
            var query = from c in _collection.AsQueryable <C>()
                        where c.D.ContainsKey("z")
                        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.D.ContainsKey(\"z\")", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.IsNull(selectQuery.OrderBy);
            Assert.IsNull(selectQuery.Projection);
            Assert.IsNull(selectQuery.Skip);
            Assert.IsNull(selectQuery.Take);

            Assert.AreEqual("{ \"D.z\" : { \"$exists\" : true } }", selectQuery.BuildQuery().ToJson());
            Assert.AreEqual(0, query.ToList().Count());
        }
예제 #2
0
        public void TestWhereEEqualsA()
        {
            var query = from c in _collection.AsQueryable <C>()
                        where c.E == E.A
                        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) => ((Nullable<Int32>)c.E == (Nullable<Int32>)1)", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.IsNull(selectQuery.OrderBy);
            Assert.IsNull(selectQuery.Projection);
            Assert.IsNull(selectQuery.Skip);
            Assert.IsNull(selectQuery.Take);

            Assert.AreEqual("{ \"e\" : \"A\" }", selectQuery.BuildQuery().ToJson());
            Assert.AreEqual(1, Consume(query));
        }
예제 #3
0
        public void TestWhereEEqualsA()
        {
            RequireEnvironment.Check().EnvironmentVariable("MONO"); // Does not pass on Mono 3.2.5. Excluding for now.
            var query = from c in __collection.AsQueryable <C>()
                        where c.E == E.A
                        select c;

            var translatedQuery = MongoQueryTranslator.Translate(query);

            Assert.IsType <SelectQuery>(translatedQuery);
            Assert.Same(__collection, translatedQuery.Collection);
            Assert.Same(typeof(C), translatedQuery.DocumentType);

            var selectQuery = (SelectQuery)translatedQuery;

            Assert.Equal("(C c) => ((Nullable<Int32>)c.E == (Nullable<Int32>)1)", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.Null(selectQuery.OrderBy);
            Assert.Null(selectQuery.Projection);
            Assert.Null(selectQuery.Skip);
            Assert.Null(selectQuery.Take);

            Assert.Equal("{ \"e\" : \"A\" }", selectQuery.BuildQuery().ToJson());
            Assert.Equal(1, Consume(query));
        }
예제 #4
0
        public void TestWhereJContainsKeyX()
        {
            var query = from c in __collection.AsQueryable <C>()
                        where c.J.Contains("x")
                        select c;

            var translatedQuery = MongoQueryTranslator.Translate(query);

            Assert.IsType <SelectQuery>(translatedQuery);
            Assert.Same(__collection, translatedQuery.Collection);
            Assert.Same(typeof(C), translatedQuery.DocumentType);

            var selectQuery = (SelectQuery)translatedQuery;

            Assert.Equal("(C c) => c.J.Contains(\"x\")", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.Null(selectQuery.OrderBy);
            Assert.Null(selectQuery.Projection);
            Assert.Null(selectQuery.Skip);
            Assert.Null(selectQuery.Take);

            var ex = Assert.Throws <NotSupportedException>(() => { selectQuery.BuildQuery(); });

            Assert.Equal("Contains in a LINQ query is only supported for DictionaryRepresentation ArrayOfDocuments or Document, not ArrayOfArrays.", ex.Message);
        }
예제 #5
0
 public void BinaryChecksumAggregateFunction(SqlFragment parent, BinaryChecksumFunction function)
 {
     this.Script.Append("BINARY_CHECKSUM(");
     ExpressionFormatter.FormatExpressionList(function.Arguments, function, this.Script, this);
     this.Script.Append(")");
 }
예제 #6
0
 public void SelectDistinct <T>(SqlFragment parent, SelectDistinct <T> selectDistinct) where T : IStatement
 {
     this.Script.LineAppendLine(TSqlKeyword.SELECT_DISTINCT);
     ExpressionFormatter.FormatExpressionList(selectDistinct.ColumnList, parent, this.Script, this);
 }
예제 #7
0
 public void GroupByClause <T>(SqlFragment parent, GroupByClause <T> groupByClause) where T : IStatement
 {
     this.Script.LineAppendLine(TSqlKeyword.GROUP_BY);
     ExpressionFormatter.FormatExpressionList(groupByClause.ExpressionList, groupByClause, this.Script, this);
 }
예제 #8
0
 public void Select <T>(SqlFragment parent, Select <T> element) where T : IStatement
 {
     this.Script.LineAppendLine(TSqlKeyword.SELECT);
     ExpressionFormatter.FormatExpressionList(element.ExpressionList, parent, this.Script, this);
 }
예제 #9
0
 public void SimpleFunction(SqlFragment parent, SimpleFunction function)
 {
     this.Script.AppendFormat("{0}(", function.FunctionName);
     ExpressionFormatter.FormatExpressionList(function.Arguments, function, this.Script, this);
     this.Script.Append(")");
 }
예제 #10
0
 public void NextValues(SqlFragment parent, NextValues nextValues)
 {
     this.Script.Append("(");
     ExpressionFormatter.FormatExpressionList(nextValues.ExpressionList, parent, this.Script, this);
     this.Script.Append(")");
 }
 public void SingleNotEqualsFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") != 1;
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("bar ne 1", actual);
 }
예제 #12
0
        public void TestOfTypeCWhereCGreaterThan0()
        {
            var query = _collection.AsQueryable <B>().OfType <C>().Where(c => c.c > 0);

            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("(C c) => (LinqToMongo.Inject({ \"_t\" : \"C\" }) && (c.c > 0))", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.AreEqual(typeof(C), selectQuery.OfType);
            Assert.IsNull(selectQuery.OrderBy);
            Assert.IsNull(selectQuery.Projection);
            Assert.IsNull(selectQuery.Skip);
            Assert.IsNull(selectQuery.Take);

            Assert.AreEqual("{ \"_t\" : \"C\", \"c\" : { \"$gt\" : 0 } }", selectQuery.BuildQuery().ToJson());
            Assert.AreEqual(2, Consume(query));
        }
 public void SingleStringEqualsFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") == "quux";
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("bar eq 'quux'", actual);
 }
예제 #14
0
 private void FormatInput()
 {
     FormattedExpression = ExpressionFormatter.Format(RawExpression) + " =";
     FormattedResult     = NumberFormatter.Format(RawResult.ToString());
 }
예제 #15
0
 public override string ToString()
 {
     return(ExpressionFormatter.FormatExpression(this, new Expression[] { }));
 }
 public void EqualWithRangeFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") == 1.to(10);
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("(bar ge 1 and bar le 10)", actual);
 }
 public void LessThanOrEqualFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") <= 1;
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("bar le 1", actual);
 }
 public void GreaterThanFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") > 1;
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("bar gt 1", actual);
 }
예제 #19
0
 public void SetUpdate(SqlFragment parent, SetUpdate setUpdate)
 {
     this.Script.Append("SET");
     ExpressionFormatter.FormatAssignList(setUpdate.AssingList, setUpdate, this.Script, this);
 }
예제 #20
0
        public void TestWhereBGreaterThan0OfTypeCWhereCGreaterThan0()
        {
            var query = _collection.AsQueryable <B>().Where(b => b.b > 0).OfType <C>().Where(c => c.c > 0);

            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("(C c) => (((c.b > 0) && LinqToMongo.Inject({ \"_t\" : \"C\" })) && (c.c > 0))", ExpressionFormatter.ToString(selectQuery.Where));
            Assert.AreEqual(typeof(C), selectQuery.OfType);
            Assert.IsNull(selectQuery.OrderBy);
            Assert.IsNull(selectQuery.Projection);
            Assert.IsNull(selectQuery.Skip);
            Assert.IsNull(selectQuery.Take);

            Assert.AreEqual("{ \"b\" : { \"$gt\" : 0 }, \"_t\" : \"C\", \"c\" : { \"$gt\" : 0 } }", selectQuery.BuildQuery().ToJson());
            Assert.AreEqual(1, Consume(query)); // should match 2 but for that you need to use the hierarchical discriminator
        }
 public void TwoEqualsFormatsAsODataFilter()
 {
     var expression = ObjectReference.FromString("foo.bar") == 1 && ObjectReference.FromString("foo.quux") == 2;
     var actual = new ExpressionFormatter().Format(expression);
     Assert.Equal("(bar eq 1 and quux eq 2)", actual);
 }