NotIn() public static method

Tests that the value of the named element is not equal to any of a list of values (see $nin).
public static NotIn ( string name ) : QueryConditionList
name string The name of the element to test.
return QueryConditionList
        public void TestNinParams()
        {
            var query    = Query.NotIn("j", 2, 4, null, 6); // null will be skipped due to functional construction semantics
            var expected = "{ \"j\" : { \"$nin\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestNinIEnumerableBsonValue()
        {
            var enumerable = new List <BsonValue> {
                2, 4, null, 6
            };                                                      // null will be skipped due to functional construction semantics
            var query    = Query.NotIn("j", enumerable);
            var expected = "{ \"j\" : { \"$nin\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
        public void TestNinBsonArray()
        {
            var array = new BsonArray {
                2, 4, null, 6
            };                                           // null will be skipped due to functional construction semantics
            var query    = Query.NotIn("j", array);
            var expected = "{ \"j\" : { \"$nin\" : [2, 4, 6] } }";

            Assert.AreEqual(expected, query.ToJson());
        }
Ejemplo n.º 4
0
        public void TestQueryNin()
        {
            var query1 = Query.NotIn("name", _bsonValue);
            var query2 = Query.NotIn("name", _bsonArray);
            var query3 = Query.NotIn("name", _bsonValueArray);
            var query4 = Query.NotIn("name", _bsonValueList);
            var query5 = Query.NotIn("name", _ienumerableBsonValue);

            var expectedSingle   = "{ 'name' : { '$nin' : [1] } }".Replace("'", "\"");
            var expectedMultiple = "{ 'name' : { '$nin' : [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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 6
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());
        }