Ejemplo n.º 1
0
        public override bool Equals(object @object)
        {
            if (@object == this)
            {
                return(true);
            }
            if (!(@object is Couchbase.Lite.QueryRow))
            {
                return(false);
            }
            Couchbase.Lite.QueryRow other = (Couchbase.Lite.QueryRow)@object;
            bool documentPropertiesEqual  = Utils.IsEqual(documentProperties, other.GetDocumentProperties
                                                              ());

            if (database == other.database && Utils.IsEqual(key, other.GetKey()) && Utils.IsEqual
                    (sourceDocumentId, other.GetSourceDocumentId()) && documentPropertiesEqual)
            {
                // If values were emitted, compare them. Otherwise we have nothing to go on so check
                // if _anything_ about the doc has changed (i.e. the sequences are different.)
                if (value != null || other.GetValue() != null)
                {
                    return(value.Equals(other.GetValue()));
                }
                else
                {
                    return(sequence == other.sequence);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        public virtual void TestViewLinkedDocs()
        {
            PutLinkedDocs(database);
            View view = database.GetView("linked");

            view.SetMapReduce(new _Mapper_1079(), null, "1");
            view.UpdateIndex();
            QueryOptions options = new QueryOptions();

            options.SetIncludeDocs(true);
            // required for linked documents
            IList <QueryRow> rows = view.QueryWithOptions(options);

            NUnit.Framework.Assert.IsNotNull(rows);
            NUnit.Framework.Assert.AreEqual(5, rows.Count);
            object[][] expected = new object[][] { new object[] { "22222", "hello", 0, null,
                                                                  "22222" }, new object[] { "22222", "hello", 1, "11111", "11111" }, new object[]
                                                   { "33333", "world", 0, null, "33333" }, new object[] { "33333", "world", 1, "22222"
                                                                                                          , "22222" }, new object[] { "33333", "world", 2, "11111", "11111" } };
            for (int i = 0; i < rows.Count; i++)
            {
                QueryRow row = rows[i];
                IDictionary <string, object> rowAsJson = row.AsJSONDictionary();
                Log.D(Tag, string.Empty + rowAsJson);
                IList <object> key = (IList <object>)rowAsJson["key"];
                IDictionary <string, object> doc = (IDictionary <string, object>)rowAsJson.Get("doc"
                                                                                               );
                string id = (string)rowAsJson["id"];
                NUnit.Framework.Assert.AreEqual(expected[i][0], id);
                NUnit.Framework.Assert.AreEqual(2, key.Count);
                NUnit.Framework.Assert.AreEqual(expected[i][1], key[0]);
                NUnit.Framework.Assert.AreEqual(expected[i][2], key[1]);
                if (expected[i][3] == null)
                {
                    NUnit.Framework.Assert.IsNull(row.GetValue());
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual(expected[i][3], ((IDictionary <string, object>)row
                                                                     .GetValue())["_id"]);
                }
                NUnit.Framework.Assert.AreEqual(expected[i][4], doc["_id"]);
            }
        }