示例#1
0
        public void TestJsFilterFunctionWithParameters()
        {
            var c           = new JSFilterCompiler();
            var filterBlock = c.CompileFilter("function(doc,req){return doc.name == req.name;}", "javascript");

            Assert.IsNotNull(filterBlock);
            var filterParams = new Dictionary <string, object> {
                { "name", "jim" }
            };
            var document = new Document(null, "doc1");
            var rev      = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "foo", 666 }
            });
            var savedRev = new SavedRevision(document, rev);

            Assert.IsFalse(filterBlock(savedRev, filterParams));

            rev = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "name", "bob" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, filterParams));

            rev = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "name", "jim" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, filterParams));
        }
示例#2
0
        public void TestJsFilterFunction()
        {
            var c           = new JSFilterCompiler();
            var filterBlock = c.CompileFilter("function(doc,req){return doc.ok;}", "javascript");

            Assert.IsNotNull(filterBlock);

            var document = new Document(null, "doc1");
            var rev      = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "foo", 666 }
            });
            var savedRev = new SavedRevision(document, rev);

            Assert.IsFalse(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", false }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", true }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary <string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", "mais oui" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, null));
        }
        public void TestJsFilterFunctionWithParameters()
        {
            var c = new JSFilterCompiler();
            var filterBlock = c.CompileFilter("function(doc,req){return doc.name == req.name;}", "javascript");
            Assert.IsNotNull(filterBlock);
            var filterParams = new Dictionary<string, object> { { "name", "jim" } };
            var document = new Document(null, "doc1");
            var rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "foo", 666 }
            });
            var savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, filterParams));

            rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "name", "bob" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, filterParams));

            rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "name", "jim" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, filterParams));
        }
        public void TestJsFilterFunction()
        {
            var c = new JSFilterCompiler();
            var filterBlock = c.CompileFilter("function(doc,req){return doc.ok;}", "javascript");
            Assert.IsNotNull(filterBlock);

            var document = new Document(null, "doc1");
            var rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "foo", 666 }
            });
            var savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", false }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsFalse(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", true }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, null));

            rev = new RevisionInternal(new Dictionary<string, object> {
                { "_id", "doc1" },
                { "_rev", "1-aa" },
                { "ok", "mais oui" }
            });
            savedRev = new SavedRevision(document, rev);
            Assert.IsTrue(filterBlock(savedRev, null));
        }