Пример #1
0
        public void TestCreateRevisions()
        {
            var properties = new Dictionary <String, Object>();

            properties["testName"] = "testCreateRevisions";
            properties["tag"]      = 1337;
            var db = database;

            var doc = CreateDocumentWithProperties(db, properties);

            Assert.IsFalse(doc.Deleted);
            var rev1 = doc.CurrentRevision;

            Assert.IsTrue(rev1.Id.StartsWith("1-"));
            Assert.AreEqual(1, rev1.Sequence);
            Assert.AreEqual(0, rev1.Attachments.Count());

            // Test -createRevisionWithProperties:
            var properties2 = new Dictionary <String, Object>(properties);

            properties2["tag"] = 4567;
            SavedRevision rev2 = null;

            try
            {
                rev2 = rev1.CreateRevision(properties2);
            }
            catch
            {
                Assert.Fail("Couldn't create revision");
            }
            Assert.IsNotNull(rev2, "Put failed");
            Assert.IsTrue(doc.CurrentRevisionId.StartsWith("2-"), "Document revision ID is still " + doc.CurrentRevisionId);
            Assert.AreEqual(rev2.Id, doc.CurrentRevisionId);
            Assert.IsNotNull(rev2.PropertiesAvailable);
            Assert.AreEqual(rev2.UserProperties, properties2);
            Assert.AreEqual(rev2.Document, doc);
            Assert.AreEqual(rev2.GetProperty("_id"), doc.Id);
            Assert.AreEqual(rev2.GetProperty("_rev"), rev2.Id);

            // Test -createRevision:
            var newRev = rev2.CreateRevision();

            Assert.IsNull(newRev.Id);
            Assert.AreEqual(newRev.Parent, rev2);
            Assert.AreEqual(newRev.ParentId, rev2.Id);
            Assert.AreEqual(doc.CurrentRevision, rev2);
            Assert.IsFalse(doc.Deleted);

            var listRevs = new List <SavedRevision>();

            listRevs.Add(rev1);
            listRevs.Add(rev2);
            Assert.AreEqual(newRev.RevisionHistory, listRevs);
            Assert.AreEqual(newRev.Properties, rev2.Properties);
            Assert.AreEqual(newRev.UserProperties, rev2.UserProperties);

            var userProperties = new Dictionary <String, Object>();

            userProperties["because"] = "NoSQL";
            newRev.SetUserProperties(userProperties);
            Assert.AreEqual(newRev.UserProperties, userProperties);

            var expectProperties = new Dictionary <String, Object>();

            expectProperties["because"] = "NoSQL";
            expectProperties["_id"]     = doc.Id;
            expectProperties["_rev"]    = rev2.Id;
            Assert.AreEqual(newRev.Properties, expectProperties);

            var rev3 = newRev.Save();

            Assert.IsNotNull(rev3);
            Assert.AreEqual(rev3.UserProperties, newRev.UserProperties);
        }