EQ() public static method

Tests that the value of the named element is equal to some value.
public static EQ ( string name, BsonValue value ) : QueryComplete
name string The name of the element to test.
value BsonValue The value to compare to.
return QueryComplete
        public void TestEquals()
        {
            var query    = Query.EQ("x", 3);
            var expected = "{ \"x\" : 3 }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestOrWithEmptyQuery()
        {
            var emptyQuery = new QueryDocument();

            var query    = Query.Or(emptyQuery);
            var expected = "{ }";

            Assert.AreEqual(expected, query.ToJson());

            query    = Query.Or(emptyQuery, emptyQuery);
            expected = "{ }";
            Assert.AreEqual(expected, query.ToJson());

            query    = Query.Or(emptyQuery, Query.EQ("x", 1));
            expected = "{ \"x\" : 1 }";
            Assert.AreEqual(expected, query.ToJson());

            query    = Query.Or(Query.EQ("x", 1), emptyQuery);
            expected = "{ \"x\" : 1 }";
            Assert.AreEqual(expected, query.ToJson());

            query    = Query.Or(emptyQuery, Query.EQ("x", 1), emptyQuery);
            expected = "{ \"x\" : 1 }";
            Assert.AreEqual(expected, query.ToJson());

            query    = Query.Or(Query.EQ("x", 1), emptyQuery, Query.EQ("y", 2));
            expected = "{ \"$or\" : [{ \"x\" : 1 }, { \"y\" : 2 }] }";
            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestAnd()
        {
            var query = Query.And(
                Query.EQ("a", 1),
                Query.EQ("b", 2)
                );
            var expected = "{ \"a\" : 1, \"b\" : 2 }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestOr()
        {
            var query = Query.Or(
                Query.EQ("a", 1),
                Query.EQ("b", 2)
                );
            var expected = "{ \"$or\" : [{ \"a\" : 1 }, { \"b\" : 2 }] }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestEqualsTwoElements()
        {
            var query = Query.And(
                Query.EQ("x", 3),
                Query.EQ("y", "foo")
                );
            var expected = "{ \"x\" : 3, \"y\" : \"foo\" }";

            Assert.AreEqual(expected, query.ToJson());
        }
Ejemplo n.º 6
0
        public void TestDuplicateEq()
        {
            // now that server supports $and this is actually syntactically valid
            var query = Query.And(
                Query.EQ("value", 6),
                Query.EQ("value", 20)
                );
            var expected = "{ '$and' : [{ 'value' : 6 }, { 'value' : 20 }] }".Replace("'", "\"");
            var json     = query.ToJson();

            Assert.AreEqual(expected, json);
        }
        public void TestOrNullSecond()
        {
            var ex = Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                Query.Or(
                    Query.EQ("x", 1),
                    Query.Null
                    );
            });

            Assert.IsTrue(ex.Message.StartsWith("One of the queries is null."));
        }
        public void TestElementMatch()
        {
            var query = Query.ElemMatch("x",
                                        Query.And(
                                            Query.EQ("a", 1),
                                            Query.GT("b", 1)
                                            )
                                        );
            var expected = "{ \"x\" : { \"$elemMatch\" : { \"a\" : 1, \"b\" : { \"$gt\" : 1 } } } }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestNestedOr()
        {
            var query = Query.And(
                Query.EQ("name", "bob"),
                Query.Or(
                    Query.EQ("a", 1),
                    Query.EQ("b", 2)
                    )
                );
            var expected = "{ \"name\" : \"bob\", \"$or\" : [{ \"a\" : 1 }, { \"b\" : 2 }] }";

            Assert.AreEqual(expected, query.ToJson());
        }
Ejemplo n.º 10
0
        public void TestAndGtLt()
        {
            var query = Query.And(
                Query.NotIn("value", 1, 2, 3),
                Query.EQ("OtherValue", 1),
                Query.GT("value", 6),
                Query.LT("value", 20)
                );

            Assert.AreEqual(
                new BsonDocument
            {
                { "value", new BsonDocument
                  {
                      { "$nin", new BsonArray {
                                1, 2, 3
                            } },
                      { "$gt", 6 },
                      { "$lt", 20 }
                  } },
                { "OtherValue", 1 }
            },
                query.ToBsonDocument());
        }