/// <exception cref="System.Exception"></exception> public static Document CreateDocWithAttachment(Database database, string attachmentName , string content) { IDictionary <string, object> properties = new Dictionary <string, object>(); properties.Put("foo", "bar"); Document doc = CreateDocumentWithProperties(database, properties); SavedRevision rev = doc.GetCurrentRevision(); NUnit.Framework.Assert.AreEqual(rev.GetAttachments().Count, 0); NUnit.Framework.Assert.AreEqual(rev.GetAttachmentNames().Count, 0); NUnit.Framework.Assert.IsNull(rev.GetAttachment(attachmentName)); ByteArrayInputStream body = new ByteArrayInputStream(Sharpen.Runtime.GetBytesForString (content)); UnsavedRevision rev2 = doc.CreateRevision(); rev2.SetAttachment(attachmentName, "text/plain; charset=utf-8", body); SavedRevision rev3 = rev2.Save(); NUnit.Framework.Assert.IsNotNull(rev3); NUnit.Framework.Assert.AreEqual(rev3.GetAttachments().Count, 1); NUnit.Framework.Assert.AreEqual(rev3.GetAttachmentNames().Count, 1); Attachment attach = rev3.GetAttachment(attachmentName); NUnit.Framework.Assert.IsNotNull(attach); NUnit.Framework.Assert.AreEqual(doc, attach.GetDocument()); NUnit.Framework.Assert.AreEqual(attachmentName, attach.GetName()); IList <string> attNames = new AList <string>(); attNames.AddItem(attachmentName); NUnit.Framework.Assert.AreEqual(rev3.GetAttachmentNames(), attNames); NUnit.Framework.Assert.AreEqual("text/plain; charset=utf-8", attach.GetContentType ()); NUnit.Framework.Assert.AreEqual(IOUtils.ToString(attach.GetContent(), "UTF-8"), content ); NUnit.Framework.Assert.AreEqual(Sharpen.Runtime.GetBytesForString(content).Length , attach.GetLength()); return(doc); }