Ejemplo n.º 1
0
        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> ());
        }
Ejemplo n.º 2
0
        public void TestRetrieveErrors()
        {
            // ID does not exists
            Assert.IsNull(storage.Retrieve <Project> (Guid.Empty));
            // ID exists but for a different type;
            StorableImageTest t = new StorableImageTest {
                ID = Guid.NewGuid(),
            };

            storage.Store(t);
            Assert.IsNull(storage.Retrieve <Project> (t.ID));
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        public void TestRetrieveImages()
        {
            Image             img = Utils.LoadImageFromFile();
            StorableImageTest t   = new StorableImageTest {
                Image1 = img,
                Image2 = img,
                ID     = Guid.NewGuid(),
            };

            storage.Store(t);
            var test2 = storage.Retrieve <StorableImageTest> (t.ID);

            Assert.AreEqual(t.Image1.Width, test2.Image1.Width);
            Assert.AreEqual(t.Image1.Height, test2.Image1.Height);
            Assert.AreEqual(t.Image2.Width, test2.Image2.Width);
            Assert.AreEqual(t.Image2.Height, test2.Image2.Height);
        }
Ejemplo n.º 5
0
        public void TestRetrieveStorableByReference()
        {
            StorableImageTest img = new StorableImageTest {
                ID     = Guid.NewGuid(),
                Image1 = Utils.LoadImageFromFile(),
            };
            StorableContainerTest cont = new StorableContainerTest {
                ID    = Guid.NewGuid(),
                Image = img,
            };

            storage.Store(cont);
            Assert.AreEqual(3, db.DocumentCount);
            var cont2 = storage.Retrieve <StorableContainerTest> (cont.ID);

            Assert.IsNotNull(cont2.Image);
            Assert.AreEqual(img.ID, cont2.Image.ID);
        }
Ejemplo n.º 6
0
        void ArrangeForRemoveDuplicates()
        {
            StorableImageTest img = new StorableImageTest {
                ID     = Guid.NewGuid(),
                Image1 = Utils.LoadImageFromFile(),
            };
            StorableContainerTest cont1 = new StorableContainerTest {
                ID    = Guid.NewGuid(),
                Image = img,
            };
            StorableContainerTest cont2 = new StorableContainerTest {
                ID    = Guid.NewGuid(),
                Image = img,
            };

            ((CouchbaseStorage)storage).AddView(typeof(StorableImageTest),
                                                new StorableImageTestView(((CouchbaseStorage)storage)));
            storage.Store(cont1);
            storage.Store(cont2);
        }
Ejemplo n.º 7
0
        public void TestStorableIDUsesRootStorableID()
        {
            StorableImageTest img = new StorableImageTest {
                ID     = Guid.NewGuid(),
                Image1 = Utils.LoadImageFromFile(),
            };
            StorableContainerTest cont = new StorableContainerTest {
                ID    = Guid.NewGuid(),
                Image = img,
            };

            Assert.AreEqual(0, db.DocumentCount);
            string newID = String.Format("{0}&{1}", cont.ID, img.ID);

            storage.Store(cont);
            Assert.AreEqual(3, db.DocumentCount);
            Assert.IsNotNull(db.GetExistingDocument(cont.ID.ToString()));
            Assert.IsNotNull(db.GetExistingDocument(newID));
            cont = storage.Retrieve <StorableContainerTest> (cont.ID);
            Assert.AreEqual(img.ID, cont.Image.ID);
            storage.Delete(cont);
            Assert.AreEqual(1, db.DocumentCount);
        }
Ejemplo n.º 8
0
        public void TestStoreStorableByReference()
        {
            StorableImageTest img = new StorableImageTest {
                ID     = Guid.NewGuid(),
                Image1 = Utils.LoadImageFromFile(),
            };
            StorableContainerTest cont = new StorableContainerTest {
                ID    = Guid.NewGuid(),
                Image = img,
            };

            Assert.AreEqual(0, db.DocumentCount);
            Document             doc     = db.CreateDocument();
            UnsavedRevision      rev     = doc.CreateRevision();
            SerializationContext context = new SerializationContext(db, cont.GetType());
            JObject jo = DocumentsSerializer.SerializeObject(cont, rev, context);

            Assert.AreEqual(img.ID.ToString(), jo ["Image"].Value <String> ());
            Assert.AreEqual(1, db.DocumentCount);
            Assert.IsNotNull(storage.Retrieve <StorableImageTest> (img.ID));
            rev.Save();
            Assert.AreEqual(2, db.DocumentCount);
        }
Ejemplo n.º 9
0
        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);
            }
        }