Esempio n. 1
0
        /// <summary>
        /// Test that the public API works as expected in change notifications after a rev tree
        /// insertion.
        /// </summary>
        /// <remarks>
        /// Test that the public API works as expected in change notifications after a rev tree
        /// insertion.  See https://github.com/couchbase/couchbase-lite-android-core/pull/27
        /// </remarks>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        public virtual void TestRevTreeChangeNotifications()
        {
            string DocumentId = "MyDocId";
            // add a document with a single (first) revision
            RevisionInternal             rev           = new RevisionInternal(DocumentId, "1-one", false, database);
            IDictionary <string, object> revProperties = new Dictionary <string, object>();

            revProperties.Put("_id", rev.GetDocId());
            revProperties.Put("_rev", rev.GetRevId());
            revProperties.Put("message", "hi");
            rev.SetProperties(revProperties);
            IList <string> revHistory = Arrays.AsList(rev.GetRevId());

            Database.ChangeListener listener = new _ChangeListener_154(this, DocumentId, rev);
            database.AddChangeListener(listener);
            database.ForceInsert(rev, revHistory, null);
            database.RemoveChangeListener(listener);
            // add two more revisions to the document
            RevisionInternal rev3 = new RevisionInternal(DocumentId, "3-three", false, database
                                                         );
            IDictionary <string, object> rev3Properties = new Dictionary <string, object>();

            rev3Properties.Put("_id", rev3.GetDocId());
            rev3Properties.Put("_rev", rev3.GetRevId());
            rev3Properties.Put("message", "hi again");
            rev3.SetProperties(rev3Properties);
            IList <string> rev3History = Arrays.AsList(rev3.GetRevId(), "2-two", rev.GetRevId(
                                                           ));

            listener = new _ChangeListener_182(this, DocumentId, rev3);
            database.AddChangeListener(listener);
            database.ForceInsert(rev3, rev3History, null);
            database.RemoveChangeListener(listener);
            // add a conflicting revision, with the same history length as the last revision we
            // inserted. Since this new revision's revID has a higher ASCII sort, it should become the
            // new winning revision.
            RevisionInternal conflictRev = new RevisionInternal(DocumentId, "3-winner", false
                                                                , database);
            IDictionary <string, object> conflictProperties = new Dictionary <string, object>();

            conflictProperties.Put("_id", conflictRev.GetDocId());
            conflictProperties.Put("_rev", conflictRev.GetRevId());
            conflictProperties.Put("message", "winner");
            conflictRev.SetProperties(conflictProperties);
            IList <string> conflictRevHistory = Arrays.AsList(conflictRev.GetRevId(), "2-two",
                                                              rev.GetRevId());

            listener = new _ChangeListener_217(this, DocumentId, conflictRev);
            database.AddChangeListener(listener);
            database.ForceInsert(conflictRev, conflictRevHistory, null);
            database.RemoveChangeListener(listener);
        }
Esempio n. 2
0
		/// <summary>
		/// Test that the public API works as expected in change notifications after a rev tree
		/// insertion.
		/// </summary>
		/// <remarks>
		/// Test that the public API works as expected in change notifications after a rev tree
		/// insertion.  See https://github.com/couchbase/couchbase-lite-android-core/pull/27
		/// </remarks>
		/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
		public virtual void TestRevTreeChangeNotifications()
		{
			string DocumentId = "MyDocId";
			// add a document with a single (first) revision
			RevisionInternal rev = new RevisionInternal(DocumentId, "1-one", false, database);
			IDictionary<string, object> revProperties = new Dictionary<string, object>();
			revProperties.Put("_id", rev.GetDocId());
			revProperties.Put("_rev", rev.GetRevId());
			revProperties.Put("message", "hi");
			rev.SetProperties(revProperties);
			IList<string> revHistory = Arrays.AsList(rev.GetRevId());
			Database.ChangeListener listener = new _ChangeListener_154(this, DocumentId, rev);
			database.AddChangeListener(listener);
			database.ForceInsert(rev, revHistory, null);
			database.RemoveChangeListener(listener);
			// add two more revisions to the document
			RevisionInternal rev3 = new RevisionInternal(DocumentId, "3-three", false, database
				);
			IDictionary<string, object> rev3Properties = new Dictionary<string, object>();
			rev3Properties.Put("_id", rev3.GetDocId());
			rev3Properties.Put("_rev", rev3.GetRevId());
			rev3Properties.Put("message", "hi again");
			rev3.SetProperties(rev3Properties);
			IList<string> rev3History = Arrays.AsList(rev3.GetRevId(), "2-two", rev.GetRevId(
				));
			listener = new _ChangeListener_182(this, DocumentId, rev3);
			database.AddChangeListener(listener);
			database.ForceInsert(rev3, rev3History, null);
			database.RemoveChangeListener(listener);
			// add a conflicting revision, with the same history length as the last revision we
			// inserted. Since this new revision's revID has a higher ASCII sort, it should become the
			// new winning revision.
			RevisionInternal conflictRev = new RevisionInternal(DocumentId, "3-winner", false
				, database);
			IDictionary<string, object> conflictProperties = new Dictionary<string, object>();
			conflictProperties.Put("_id", conflictRev.GetDocId());
			conflictProperties.Put("_rev", conflictRev.GetRevId());
			conflictProperties.Put("message", "winner");
			conflictRev.SetProperties(conflictProperties);
			IList<string> conflictRevHistory = Arrays.AsList(conflictRev.GetRevId(), "2-two", 
				rev.GetRevId());
			listener = new _ChangeListener_217(this, DocumentId, conflictRev);
			database.AddChangeListener(listener);
			database.ForceInsert(conflictRev, conflictRevHistory, null);
			database.RemoveChangeListener(listener);
		}