public void TestFindWhereEquivalency()
        {
            IMongoCollection col = db["tests"]["reads"];
            Document         lt  = new Document().Append("j", new Document().Append("$lt", 5));

            string where = "this.j < 5";
            Document   explicitWhere = new Document().Append("$where", new Code(where));
            CodeWScope func          = new CodeWScope("function() { return this.j < 5; }", new Document());
            Document   funcDoc       = new Document().Append("$where", func);

            Assert.AreEqual(4, CountDocs(col.Find(lt)), "Basic find didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(where)), "String where didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
        }
 public void TestFormatting()
 {
     string expected = "290000000A00000072657475726E20313B0017000000026E73000A00000074657374732E746D700000";
     CodeWScope cw = new CodeWScope();
     cw.Value = "return 1;";
     cw.Scope = new Document().Append("ns","tests.tmp");
     BsonCodeWScope bcode = BsonConvert.From(cw);
     MemoryStream buf = new MemoryStream();
     BsonWriter writer = new BsonWriter(buf);
     bcode.Write(writer);
     writer.Flush();
     Byte[] output = buf.ToArray();
     String hexdump = BitConverter.ToString(output);
     hexdump = hexdump.Replace("-","");
     Assert.AreEqual(expected.Length/2,output[0],"Size didn't take into count null terminator");
     Assert.AreEqual(expected,hexdump, "Dump not correct");
 }
        public void TestFindWhereEquivalency()
        {
            IMongoCollection col = DB["finds"];
            Document lt = new Document().Append("j", new Document().Append("$lt", 5));
            string where = "this.j < 5";
            Document explicitWhere = new Document().Append("$where", new Code(where));
            CodeWScope func = new CodeWScope("function() { return this.j < 5; }", new Document());
            Document funcDoc = new Document().Append("$where", func);

            Assert.AreEqual(4, CountDocs(col.Find(lt)), "Basic find didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(where)), "String where didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(explicitWhere)), "Explicit where didn't return 4 docs");
            Assert.AreEqual(4, CountDocs(col.Find(funcDoc)), "Function where didn't return 4 docs");
        }
Exemple #4
0
 public Document Eval(CodeWScope cw)
 {
     Document cmd = new Document().Append("$eval", cw);
     return SendCommand(cmd);
 }
Exemple #5
0
 public static BsonCodeWScope From(CodeWScope val)
 {
     return new BsonCodeWScope(val);
 }
Exemple #6
0
        public Document Eval(CodeWScope cw)
        {
            Document cmd = new Document().Append("$eval", cw);

            return(SendCommand(cmd));
        }