Exemplo n.º 1
0
        private QueryOptions GetQueryOptions()
        {
            QueryOptions queryOptions = new QueryOptions();

            queryOptions.SetStartKey(GetStartKey());
            queryOptions.SetEndKey(GetEndKey());
            queryOptions.SetStartKey(GetStartKey());
            queryOptions.SetKeys(GetKeys());
            queryOptions.SetSkip(GetSkip());
            queryOptions.SetLimit(GetLimit());
            queryOptions.SetReduce(!IsMapOnly());
            queryOptions.SetReduceSpecified(true);
            queryOptions.SetGroupLevel(GetGroupLevel());
            queryOptions.SetDescending(IsDescending());
            queryOptions.SetIncludeDocs(ShouldPrefetch());
            queryOptions.SetUpdateSeq(true);
            queryOptions.SetInclusiveEnd(true);
            queryOptions.SetStale(GetIndexUpdateMode());
            queryOptions.SetAllDocsMode(GetAllDocsMode());
            return(queryOptions);
        }
Exemplo n.º 2
0
		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestAllDocsQuery()
		{
			IList<RevisionInternal> docs = PutDocs(database);
			IList<QueryRow> expectedRow = new AList<QueryRow>();
			foreach (RevisionInternal rev in docs)
			{
				IDictionary<string, object> value = new Dictionary<string, object>();
				value.Put("rev", rev.GetRevId());
				value.Put("_conflicts", new AList<string>());
				QueryRow queryRow = new QueryRow(rev.GetDocId(), 0, rev.GetDocId(), value, null);
				queryRow.SetDatabase(database);
				expectedRow.AddItem(queryRow);
			}
			QueryOptions options = new QueryOptions();
			IDictionary<string, object> allDocs = database.GetAllDocs(options);
			IList<QueryRow> expectedRows = new AList<QueryRow>();
			expectedRows.AddItem(expectedRow[2]);
			expectedRows.AddItem(expectedRow[0]);
			expectedRows.AddItem(expectedRow[3]);
			expectedRows.AddItem(expectedRow[1]);
			expectedRows.AddItem(expectedRow[4]);
			IDictionary<string, object> expectedQueryResult = CreateExpectedQueryResult(expectedRows
				, 0);
			NUnit.Framework.Assert.AreEqual(expectedQueryResult, allDocs);
			// Start/end key query:
			options = new QueryOptions();
			options.SetStartKey("2");
			options.SetEndKey("44444");
			allDocs = database.GetAllDocs(options);
			expectedRows = new AList<QueryRow>();
			expectedRows.AddItem(expectedRow[0]);
			expectedRows.AddItem(expectedRow[3]);
			expectedRows.AddItem(expectedRow[1]);
			expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
			NUnit.Framework.Assert.AreEqual(expectedQueryResult, allDocs);
			// Start/end query without inclusive end:
			options.SetInclusiveEnd(false);
			allDocs = database.GetAllDocs(options);
			expectedRows = new AList<QueryRow>();
			expectedRows.AddItem(expectedRow[0]);
			expectedRows.AddItem(expectedRow[3]);
			expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
			NUnit.Framework.Assert.AreEqual(expectedQueryResult, allDocs);
			// Get all documents: with default QueryOptions
			options = new QueryOptions();
			allDocs = database.GetAllDocs(options);
			expectedRows = new AList<QueryRow>();
			expectedRows.AddItem(expectedRow[2]);
			expectedRows.AddItem(expectedRow[0]);
			expectedRows.AddItem(expectedRow[3]);
			expectedRows.AddItem(expectedRow[1]);
			expectedRows.AddItem(expectedRow[4]);
			expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
			NUnit.Framework.Assert.AreEqual(expectedQueryResult, allDocs);
			// Get specific documents:
			options = new QueryOptions();
			IList<object> docIds = new AList<object>();
			QueryRow expected2 = expectedRow[2];
			docIds.AddItem(expected2.GetDocument().GetId());
			options.SetKeys(docIds);
			allDocs = database.GetAllDocs(options);
			expectedRows = new AList<QueryRow>();
			expectedRows.AddItem(expected2);
			expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
			NUnit.Framework.Assert.AreEqual(expectedQueryResult, allDocs);
		}
Exemplo n.º 3
0
		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestViewQuery()
		{
			PutDocs(database);
			View view = CreateView(database);
			view.UpdateIndex();
			// Query all rows:
			QueryOptions options = new QueryOptions();
			IList<QueryRow> rows = view.QueryWithOptions(options);
			IList<object> expectedRows = new AList<object>();
			IDictionary<string, object> dict5 = new Dictionary<string, object>();
			dict5.Put("id", "55555");
			dict5.Put("key", "five");
			expectedRows.AddItem(dict5);
			IDictionary<string, object> dict4 = new Dictionary<string, object>();
			dict4.Put("id", "44444");
			dict4.Put("key", "four");
			expectedRows.AddItem(dict4);
			IDictionary<string, object> dict1 = new Dictionary<string, object>();
			dict1.Put("id", "11111");
			dict1.Put("key", "one");
			expectedRows.AddItem(dict1);
			IDictionary<string, object> dict3 = new Dictionary<string, object>();
			dict3.Put("id", "33333");
			dict3.Put("key", "three");
			expectedRows.AddItem(dict3);
			IDictionary<string, object> dict2 = new Dictionary<string, object>();
			dict2.Put("id", "22222");
			dict2.Put("key", "two");
			expectedRows.AddItem(dict2);
			NUnit.Framework.Assert.AreEqual(5, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict5.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict5.Get("value"), rows[0].GetValue());
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[1].GetValue());
			NUnit.Framework.Assert.AreEqual(dict1.Get("key"), rows[2].GetKey());
			NUnit.Framework.Assert.AreEqual(dict1.Get("value"), rows[2].GetValue());
			NUnit.Framework.Assert.AreEqual(dict3.Get("key"), rows[3].GetKey());
			NUnit.Framework.Assert.AreEqual(dict3.Get("value"), rows[3].GetValue());
			NUnit.Framework.Assert.AreEqual(dict2.Get("key"), rows[4].GetKey());
			NUnit.Framework.Assert.AreEqual(dict2.Get("value"), rows[4].GetValue());
			// Start/end key query:
			options = new QueryOptions();
			options.SetStartKey("a");
			options.SetEndKey("one");
			rows = view.QueryWithOptions(options);
			expectedRows = new AList<object>();
			expectedRows.AddItem(dict5);
			expectedRows.AddItem(dict4);
			expectedRows.AddItem(dict1);
			NUnit.Framework.Assert.AreEqual(3, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict5.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict5.Get("value"), rows[0].GetValue());
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[1].GetValue());
			NUnit.Framework.Assert.AreEqual(dict1.Get("key"), rows[2].GetKey());
			NUnit.Framework.Assert.AreEqual(dict1.Get("value"), rows[2].GetValue());
			// Start/end query without inclusive end:
			options.SetInclusiveEnd(false);
			rows = view.QueryWithOptions(options);
			expectedRows = new AList<object>();
			expectedRows.AddItem(dict5);
			expectedRows.AddItem(dict4);
			NUnit.Framework.Assert.AreEqual(2, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict5.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict5.Get("value"), rows[0].GetValue());
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[1].GetValue());
			// Reversed:
			options.SetDescending(true);
			options.SetStartKey("o");
			options.SetEndKey("five");
			options.SetInclusiveEnd(true);
			rows = view.QueryWithOptions(options);
			expectedRows = new AList<object>();
			expectedRows.AddItem(dict4);
			expectedRows.AddItem(dict5);
			NUnit.Framework.Assert.AreEqual(2, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[0].GetValue());
			NUnit.Framework.Assert.AreEqual(dict5.Get("key"), rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(dict5.Get("value"), rows[1].GetValue());
			// Reversed, no inclusive end:
			options.SetInclusiveEnd(false);
			rows = view.QueryWithOptions(options);
			expectedRows = new AList<object>();
			expectedRows.AddItem(dict4);
			NUnit.Framework.Assert.AreEqual(1, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[0].GetValue());
			// Specific keys:
			options = new QueryOptions();
			IList<object> keys = new AList<object>();
			keys.AddItem("two");
			keys.AddItem("four");
			options.SetKeys(keys);
			rows = view.QueryWithOptions(options);
			expectedRows = new AList<object>();
			expectedRows.AddItem(dict4);
			expectedRows.AddItem(dict2);
			NUnit.Framework.Assert.AreEqual(2, rows.Count);
			NUnit.Framework.Assert.AreEqual(dict4.Get("key"), rows[0].GetKey());
			NUnit.Framework.Assert.AreEqual(dict4.Get("value"), rows[0].GetValue());
			NUnit.Framework.Assert.AreEqual(dict2.Get("key"), rows[1].GetKey());
			NUnit.Framework.Assert.AreEqual(dict2.Get("value"), rows[1].GetValue());
		}
Exemplo n.º 4
0
        public void TestAllDocsQuery()
        {
            var docs        = PutDocs(database);
            var expectedRow = new List <QueryRow>();

            foreach (RevisionInternal rev in docs)
            {
                var value = new Dictionary <string, object>();
                value.Put("rev", rev.GetRevId());
                value.Put("_conflicts", new List <string>());

                var queryRow = new QueryRow(rev.GetDocId(), 0, rev.GetDocId(), value, null);
                queryRow.Database = database;
                expectedRow.AddItem(queryRow);
            }

            var options      = new QueryOptions();
            var allDocs      = database.GetAllDocs(options);
            var expectedRows = new List <QueryRow>();

            expectedRows.AddItem(expectedRow[2]);
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedRows.AddItem(expectedRow[4]);

            var expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);

            //CollectionAssert.AreEqual(expectedQueryResult, allDocs);
            AssertPropertiesAreEqual(expectedQueryResult, allDocs);

            // Start/end key query:
            options = new QueryOptions();
            options.SetStartKey("2");
            options.SetEndKey("44444");
            allDocs      = database.GetAllDocs(options);
            expectedRows = new List <QueryRow>();
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Start/end query without inclusive end:
            options.SetInclusiveEnd(false);
            allDocs      = database.GetAllDocs(options);
            expectedRows = new List <QueryRow>();
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Get all documents: with default QueryOptions
            options      = new QueryOptions();
            allDocs      = database.GetAllDocs(options);
            expectedRows = new List <QueryRow>();
            expectedRows.AddItem(expectedRow[2]);
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedRows.AddItem(expectedRow[4]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Get specific documents:
            options = new QueryOptions();
            IList <object> docIds    = new List <object>();
            QueryRow       expected2 = expectedRow[2];

            docIds.AddItem(expected2.Document.Id);
            options.SetKeys(docIds);
            allDocs      = database.GetAllDocs(options);
            expectedRows = new List <QueryRow>();
            expectedRows.AddItem(expected2);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));
        }
Exemplo n.º 5
0
        public void TestViewQuery()
        {
            PutDocs(database);
            var view = CreateView(database);

            view.UpdateIndex();

            // Query all rows:
            QueryOptions     options = new QueryOptions();
            IList <QueryRow> rows    = view.QueryWithOptions(options).ToList();

            var expectedRows = new List <object>();

            var dict5 = new Dictionary <string, object>();

            dict5["id"]  = "55555";
            dict5["key"] = "five";
            expectedRows.AddItem(dict5);

            var dict4 = new Dictionary <string, object>();

            dict4["id"]  = "44444";
            dict4["key"] = "four";
            expectedRows.AddItem(dict4);

            var dict1 = new Dictionary <string, object>();

            dict1["id"]  = "11111";
            dict1["key"] = "one";
            expectedRows.AddItem(dict1);

            var dict3 = new Dictionary <string, object>();

            dict3["id"]  = "33333";
            dict3["key"] = "three";
            expectedRows.AddItem(dict3);

            var dict2 = new Dictionary <string, object>();

            dict2["id"]  = "22222";
            dict2["key"] = "two";
            expectedRows.AddItem(dict2);
            Assert.AreEqual(5, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);
            Assert.AreEqual(dict1["key"], rows[2].Key);
            Assert.AreEqual(dict3["key"], rows[3].Key);
            Assert.AreEqual(dict2["key"], rows[4].Key);

            // Start/end key query:
            options = new QueryOptions();
            options.SetStartKey("a");
            options.SetEndKey("one");

            rows         = view.QueryWithOptions(options).ToList();
            expectedRows = new List <object>();
            expectedRows.AddItem(dict5);
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict1);
            Assert.AreEqual(3, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);
            Assert.AreEqual(dict1["key"], rows[2].Key);

            // Start/end query without inclusive end:
            options.SetInclusiveEnd(false);
            rows         = view.QueryWithOptions(options).ToList();
            expectedRows = new List <object>();
            expectedRows.AddItem(dict5);
            expectedRows.AddItem(dict4);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);

            // Reversed:
            options.SetDescending(true);
            options.SetStartKey("o");
            options.SetEndKey("five");
            options.SetInclusiveEnd(true);
            rows         = view.QueryWithOptions(options).ToList();
            expectedRows = new List <object>();
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict5);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);
            Assert.AreEqual(dict5["key"], rows[1].Key);

            // Reversed, no inclusive end:
            options.SetInclusiveEnd(false);
            rows         = view.QueryWithOptions(options).ToList();
            expectedRows = new List <object>();
            expectedRows.AddItem(dict4);
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);

            // Specific keys:
            options = new QueryOptions();
            var keys = new List <object>();

            keys.AddItem("two");
            keys.AddItem("four");
            options.SetKeys(keys);
            rows         = view.QueryWithOptions(options).ToList();
            expectedRows = new List <object>();
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict2);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);
            Assert.AreEqual(dict2["key"], rows[1].Key);
        }
Exemplo n.º 6
0
        public void TestAllDocsQuery()
        {
            var docs = PutDocs(database);
            var expectedRow = new AList<QueryRow>();
            foreach (RevisionInternal rev in docs)
            {
                var value = new Dictionary<string, object>();
                value.Put("rev", rev.GetRevId());
                value.Put("_conflicts", new AList<string>());

                var queryRow = new QueryRow(rev.GetDocId(), 0, rev.GetDocId(), value, null);
                queryRow.Database = database;
                expectedRow.AddItem(queryRow);
            }

            var options = new QueryOptions();
            var allDocs = database.GetAllDocs(options);
            var expectedRows = new AList<QueryRow>();
            expectedRows.AddItem(expectedRow[2]);
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedRows.AddItem(expectedRow[4]);

            var expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            //CollectionAssert.AreEqual(expectedQueryResult, allDocs);
            AssertPropertiesAreEqual(expectedQueryResult, allDocs);

            // Start/end key query:
            options = new QueryOptions();
            options.SetStartKey("2");
            options.SetEndKey("44444");
            allDocs = database.GetAllDocs(options);
            expectedRows = new AList<QueryRow>();
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Start/end query without inclusive end:
            options.SetInclusiveEnd(false);
            allDocs = database.GetAllDocs(options);
            expectedRows = new AList<QueryRow>();
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Get all documents: with default QueryOptions
            options = new QueryOptions();
            allDocs = database.GetAllDocs(options);
            expectedRows = new AList<QueryRow>();
            expectedRows.AddItem(expectedRow[2]);
            expectedRows.AddItem(expectedRow[0]);
            expectedRows.AddItem(expectedRow[3]);
            expectedRows.AddItem(expectedRow[1]);
            expectedRows.AddItem(expectedRow[4]);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));

            // Get specific documents:
            options = new QueryOptions();
            IList<object> docIds = new AList<object>();
            QueryRow expected2 = expectedRow[2];
            docIds.AddItem(expected2.Document.Id);
            options.SetKeys(docIds);
            allDocs = database.GetAllDocs(options);
            expectedRows = new AList<QueryRow>();
            expectedRows.AddItem(expected2);
            expectedQueryResult = CreateExpectedQueryResult(expectedRows, 0);
            Assert.AreEqual(expectedQueryResult.Select(kvp => kvp.Key).OrderBy(k => k), allDocs.Select(kvp => kvp.Key).OrderBy(k => k));
        }
Exemplo n.º 7
0
        public void TestViewQuery()
        {
            PutDocs(database);
            var view = CreateView(database);
            view.UpdateIndex();

            // Query all rows:
            QueryOptions options = new QueryOptions();
            IList<QueryRow> rows = view.QueryWithOptions(options).ToList();

            var expectedRows = new AList<object>();

            var dict5 = new Dictionary<string, object>();
            dict5["id"] = "55555";
            dict5["key"] = "five";
            expectedRows.AddItem(dict5);

            var dict4 = new Dictionary<string, object>();
            dict4["id"] = "44444";
            dict4["key"] = "four";
            expectedRows.AddItem(dict4);

            var dict1 = new Dictionary<string, object>();
            dict1["id"] = "11111";
            dict1["key"] = "one";
            expectedRows.AddItem(dict1);

            var dict3 = new Dictionary<string, object>();
            dict3["id"] = "33333";
            dict3["key"] = "three";
            expectedRows.AddItem(dict3);

            var dict2 = new Dictionary<string, object>();
            dict2["id"] = "22222";
            dict2["key"] = "two";
            expectedRows.AddItem(dict2);
            Assert.AreEqual(5, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);
            Assert.AreEqual(dict1["key"], rows[2].Key);
            Assert.AreEqual(dict3["key"], rows[3].Key);
            Assert.AreEqual(dict2["key"], rows[4].Key);

            // Start/end key query:
            options = new QueryOptions();
            options.SetStartKey("a");
            options.SetEndKey("one");

            rows = view.QueryWithOptions(options).ToList();
            expectedRows = new AList<object>();
            expectedRows.AddItem(dict5);
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict1);
            Assert.AreEqual(3, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);
            Assert.AreEqual(dict1["key"], rows[2].Key);

            // Start/end query without inclusive end:
            options.SetInclusiveEnd(false);
            rows = view.QueryWithOptions(options).ToList();
            expectedRows = new AList<object>();
            expectedRows.AddItem(dict5);
            expectedRows.AddItem(dict4);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict5["key"], rows[0].Key);
            Assert.AreEqual(dict4["key"], rows[1].Key);

            // Reversed:
            options.SetDescending(true);
            options.SetStartKey("o");
            options.SetEndKey("five");
            options.SetInclusiveEnd(true);
            rows = view.QueryWithOptions(options).ToList();
            expectedRows = new AList<object>();
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict5);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);
            Assert.AreEqual(dict5["key"], rows[1].Key);

            // Reversed, no inclusive end:
            options.SetInclusiveEnd(false);
            rows = view.QueryWithOptions(options).ToList();
            expectedRows = new AList<object>();
            expectedRows.AddItem(dict4);
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);

            // Specific keys:
            options = new QueryOptions();
            var keys = new AList<object>();
            keys.AddItem("two");
            keys.AddItem("four");
            options.SetKeys(keys);
            rows = view.QueryWithOptions(options).ToList();
            expectedRows = new AList<object>();
            expectedRows.AddItem(dict4);
            expectedRows.AddItem(dict2);
            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(dict4["key"], rows[0].Key);
            Assert.AreEqual(dict2["key"], rows[1].Key);
        }
Exemplo n.º 8
0
		private QueryOptions GetQueryOptions()
		{
			QueryOptions queryOptions = new QueryOptions();
			queryOptions.SetStartKey(GetStartKey());
			queryOptions.SetEndKey(GetEndKey());
			queryOptions.SetStartKey(GetStartKey());
			queryOptions.SetKeys(GetKeys());
			queryOptions.SetSkip(GetSkip());
			queryOptions.SetLimit(GetLimit());
			queryOptions.SetReduce(!IsMapOnly());
			queryOptions.SetReduceSpecified(true);
			queryOptions.SetGroupLevel(GetGroupLevel());
			queryOptions.SetDescending(IsDescending());
			queryOptions.SetIncludeDocs(ShouldPrefetch());
			queryOptions.SetUpdateSeq(true);
			queryOptions.SetInclusiveEnd(true);
			queryOptions.SetStale(GetIndexUpdateMode());
			queryOptions.SetAllDocsMode(GetAllDocsMode());
			return queryOptions;
		}
 /// <summary>
 /// https://github.com/couchbase/couchbase-lite-android/issues/139
 /// test based on https://github.com/couchbase/couchbase-lite-ios/blob/master/Source/CBL_View_Tests.m#L358
 /// </summary>
 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public virtual void TestViewQueryStartKeyDocID()
 {
     PutDocs(database);
     IList<RevisionInternal> result = new AList<RevisionInternal>();
     IDictionary<string, object> dict = new Dictionary<string, object>();
     dict.Put("_id", "11112");
     dict.Put("key", "one");
     result.AddItem(PutDoc(database, dict));
     View view = CreateView(database);
     view.UpdateIndex();
     QueryOptions options = new QueryOptions();
     options.SetStartKey("one");
     options.SetStartKeyDocId("11112");
     options.SetEndKey("three");
     IList<QueryRow> rows = view.QueryWithOptions(options);
     NUnit.Framework.Assert.AreEqual(2, rows.Count);
     NUnit.Framework.Assert.AreEqual("11112", rows[0].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("one", rows[0].GetKey());
     NUnit.Framework.Assert.AreEqual("33333", rows[1].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("three", rows[1].GetKey());
     options = new QueryOptions();
     options.SetEndKey("one");
     options.SetEndKeyDocId("11111");
     rows = view.QueryWithOptions(options);
     Log.D(Tag, "rows: " + rows);
     NUnit.Framework.Assert.AreEqual(3, rows.Count);
     NUnit.Framework.Assert.AreEqual("55555", rows[0].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("five", rows[0].GetKey());
     NUnit.Framework.Assert.AreEqual("44444", rows[1].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("four", rows[1].GetKey());
     NUnit.Framework.Assert.AreEqual("11111", rows[2].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("one", rows[2].GetKey());
     options.SetStartKey("one");
     options.SetStartKeyDocId("11111");
     rows = view.QueryWithOptions(options);
     NUnit.Framework.Assert.AreEqual(1, rows.Count);
     NUnit.Framework.Assert.AreEqual("11111", rows[0].GetDocumentId());
     NUnit.Framework.Assert.AreEqual("one", rows[0].GetKey());
 }
Exemplo n.º 10
0
        public void TestViewQueryStartKeyDocID()
        {
            PutDocs(database);

            var result = new List<RevisionInternal>();

            var dict = new Dictionary<string, object>() 
            {
                {"_id", "11112"},
                {"key", "one"}
            };
            result.Add(PutDoc(database, dict));
            var view = CreateView(database);
            view.UpdateIndex();

            var options = new QueryOptions();
            options.SetStartKey("one");
            options.SetStartKeyDocId("11112");
            options.SetEndKey("three");
            var rows = view.QueryWithOptions(options).ToList<QueryRow>();

            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual("11112", rows[0].DocumentId);
            Assert.AreEqual("one", rows[0].Key);
            Assert.AreEqual("33333", rows[1].DocumentId);
            Assert.AreEqual("three", rows[1].Key);

            options = new QueryOptions();
            options.SetEndKey("one");
            options.SetEndKeyDocId("11111");
            rows = view.QueryWithOptions(options).ToList<QueryRow>();

            Assert.AreEqual(3, rows.Count);
            Assert.AreEqual("55555", rows[0].DocumentId);
            Assert.AreEqual("five", rows[0].Key);
            Assert.AreEqual("44444", rows[1].DocumentId);
            Assert.AreEqual("four", rows[1].Key);
            Assert.AreEqual("11111", rows[2].DocumentId);
            Assert.AreEqual("one", rows[2].Key);

            options.SetStartKey("one");
            options.SetStartKeyDocId("11111");
            rows = view.QueryWithOptions(options).ToList<QueryRow>();

            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual("11111", rows[0].DocumentId);
            Assert.AreEqual("one", rows[0].Key);
        }