예제 #1
0
        /// <summary>Regression test for https://github.com/couchbase/couchbase-lite-android-core/issues/70
        ///     </summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void TestAttachmentDisappearsAfterSave()
        {
            // create a doc with an attachment
            Document             doc     = database.CreateDocument();
            string               content = "This is a test attachment!";
            ByteArrayInputStream body    = new ByteArrayInputStream(Sharpen.Runtime.GetBytesForString
                                                                        (content));
            UnsavedRevision rev = doc.CreateRevision();

            rev.SetAttachment("index.html", "text/plain; charset=utf-8", body);
            rev.Save();
            // make sure the doc's latest revision has the attachment
            IDictionary <string, object> attachments = (IDictionary)doc.GetCurrentRevision().GetProperty
                                                           ("_attachments");

            NUnit.Framework.Assert.IsNotNull(attachments);
            NUnit.Framework.Assert.AreEqual(1, attachments.Count);
            // make sure the rev has the attachment
            attachments = (IDictionary)rev.GetProperty("_attachments");
            NUnit.Framework.Assert.IsNotNull(attachments);
            NUnit.Framework.Assert.AreEqual(1, attachments.Count);
            // create new properties to add
            IDictionary <string, object> properties = new Dictionary <string, object>();

            properties.Put("foo", "bar");
            // make sure the new rev still has the attachment
            UnsavedRevision rev2 = doc.CreateRevision();

            rev2.GetProperties().PutAll(properties);
            rev2.Save();
            attachments = (IDictionary)rev2.GetProperty("_attachments");
            NUnit.Framework.Assert.IsNotNull(attachments);
            NUnit.Framework.Assert.AreEqual(1, attachments.Count);
        }