public void TestStoreImagesList() { Image img = Utils.LoadImageFromFile(); StorableImageTest t = new StorableImageTest { Images = new List <Image> { img, img, img }, ID = Guid.NewGuid(), }; Document doc = db.CreateDocument(); UnsavedRevision rev = doc.CreateRevision(); SerializationContext context = new SerializationContext(db, t.GetType()); JObject jo = DocumentsSerializer.SerializeObject(t, rev, context); int i = 0; foreach (string name in rev.AttachmentNames) { i++; Assert.AreEqual("Images_" + i, name); } Assert.AreEqual(3, i); Assert.AreEqual("attachment::Images_1", jo ["Images"] [0].Value <string> ()); Assert.AreEqual("attachment::Images_2", jo ["Images"] [1].Value <string> ()); Assert.AreEqual("attachment::Images_3", jo ["Images"] [2].Value <string> ()); }
public void TestDocType() { StorableImageTest t = new StorableImageTest { ID = Guid.NewGuid(), }; Document doc = db.CreateDocument(); SerializationContext context = new SerializationContext(db, t.GetType()); JObject jo = DocumentsSerializer.SerializeObject(t, doc.CreateRevision(), context); Assert.AreEqual(t.ID, jo.Value <Guid> ("ID")); Assert.AreEqual("StorableImageTest", jo.Value <string> ("DocType")); }
public void TestStoreImages() { Image img = Utils.LoadImageFromFile(); StorableImageTest t = new StorableImageTest { Image1 = img, Image2 = img, ID = Guid.NewGuid(), }; Document doc = db.CreateDocument(); UnsavedRevision rev = doc.CreateRevision(); SerializationContext context = new SerializationContext(db, t.GetType()); JObject jo = DocumentsSerializer.SerializeObject(t, rev, context); Assert.IsNotNull(jo ["ID"]); Assert.AreEqual("attachment::Image1_1", jo ["Image1"].Value <string> ()); Assert.AreEqual("attachment::Image2_1", jo ["Image2"].Value <string> ()); int i = 0; foreach (string name in rev.AttachmentNames) { i++; Assert.AreEqual(string.Format("Image{0}_1", i), name); } }