Example #1
0
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        public virtual void TestViewCollationRaw()
        {
            IList <object> list1 = new AList <object>();

            list1.AddItem("a");
            IList <object> list2 = new AList <object>();

            list2.AddItem("b");
            IList <object> list3 = new AList <object>();

            list3.AddItem("b");
            list3.AddItem("c");
            IList <object> list4 = new AList <object>();

            list4.AddItem("b");
            list4.AddItem("c");
            list4.AddItem("a");
            IList <object> list5 = new AList <object>();

            list5.AddItem("b");
            list5.AddItem("d");
            IList <object> list6 = new AList <object>();

            list6.AddItem("b");
            list6.AddItem("d");
            list6.AddItem("e");
            // Based on CouchDB's "view_collation.js" test
            IList <object> testKeys = new AList <object>();

            testKeys.AddItem(0);
            testKeys.AddItem(2.5);
            testKeys.AddItem(10);
            testKeys.AddItem(false);
            testKeys.AddItem(null);
            testKeys.AddItem(true);
            testKeys.AddItem(list1);
            testKeys.AddItem(list2);
            testKeys.AddItem(list3);
            testKeys.AddItem(list4);
            testKeys.AddItem(list5);
            testKeys.AddItem(list6);
            testKeys.AddItem(" ");
            testKeys.AddItem("A");
            testKeys.AddItem("B");
            testKeys.AddItem("_");
            testKeys.AddItem("a");
            testKeys.AddItem("aa");
            testKeys.AddItem("b");
            testKeys.AddItem("ba");
            testKeys.AddItem("bb");
            testKeys.AddItem("~");
            int i = 0;

            foreach (object key in testKeys)
            {
                IDictionary <string, object> docProperties = new Dictionary <string, object>();
                docProperties.Put("_id", Sharpen.Extensions.ToString(i++));
                docProperties["name"] = key;
                PutDoc(database, docProperties);
            }
            View view = database.GetView("default/names");

            view.SetMapReduce(new _Mapper_1041(), null, "1.0");
            view.SetCollation(View.TDViewCollation.TDViewCollationRaw);
            QueryOptions     options = new QueryOptions();
            IList <QueryRow> rows    = view.QueryWithOptions(options);

            i = 0;
            foreach (QueryRow row in rows)
            {
                NUnit.Framework.Assert.AreEqual(testKeys[i++], row.Key);
            }
            database.Close();
        }