In() public static method

Tests that the value of the named element is equal to one of a list of values (see $in).
public static In ( string name ) : QueryConditionList
name string The name of the element to test.
return QueryConditionList
コード例 #1
0
        public void TestInParams()
        {
            var query    = Query.In("j", 2, 4, null, 6); // null will be skipped due to functional construction semantics
            var expected = "{ \"j\" : { \"$in\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
コード例 #2
0
        public void TestInIEnumerableBsonValue()
        {
            var enumerable = new List <BsonValue> {
                2, 4, null, 6
            };                                                      // null will be skipped due to functional construction semantics
            var query    = Query.In("j", enumerable);
            var expected = "{ \"j\" : { \"$in\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
コード例 #3
0
        public void TestInBsonArray()
        {
            var array = new BsonArray {
                2, 4, null, 6
            };                                           // null will be skipped due to functional construction semantics
            var query    = Query.In("j", array);
            var expected = "{ \"j\" : { \"$in\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
コード例 #4
0
        public void TestQueryIn()
        {
            var query1 = Query.In("name", _bsonValue);
            var query2 = Query.In("name", _bsonArray);
            var query3 = Query.In("name", _bsonValueArray);
            var query4 = Query.In("name", _bsonValueList);
            var query5 = Query.In("name", _ienumerableBsonValue);

            var expectedSingle   = "{ 'name' : { '$in' : [1] } }".Replace("'", "\"");
            var expectedMultiple = "{ 'name' : { '$in' : [1, 2, 3] } }".Replace("'", "\"");

            Assert.AreEqual(expectedSingle, query1.ToJson());
            Assert.AreEqual(expectedMultiple, query2.ToJson());
            Assert.AreEqual(expectedMultiple, query3.ToJson());
            Assert.AreEqual(expectedMultiple, query4.ToJson());
            Assert.AreEqual(expectedMultiple, query5.ToJson());
        }
コード例 #5
0
        public void TestAndInNotIn()
        {
            var query = Query.And(
                Query.In("value", 1, 2, 3, 4),
                Query.NotIn("value", 11, 12, 13, 14)
                );

            Assert.AreEqual(
                new BsonDocument
            {
                { "value", new BsonDocument
                  {
                      { "$in", new BsonArray {
                                1, 2, 3, 4
                            } },
                      { "$nin", new BsonArray {
                                11, 12, 13, 14
                            } }
                  } }
            },
                query.ToBsonDocument());
        }