예제 #1
0
        public void Test_Add_Update_Delete()
        {
            ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
            string filePath             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test_Add_Update_Delete." + Guid.NewGuid().ToString() + ".json");
            JsonListFileStorage <PersistenceObject> storage = new JsonListFileStorage <PersistenceObject>(filePath, locker);

            var site = new Site("Site1");

            var obj = new PersistenceObject(site, "persistence1")
            {
                Body = Guid.NewGuid().ToString()
            };

            //test add
            storage.Add(obj);

            //test GetList
            Assert.AreEqual(1, storage.GetList(site).Count());

            //test Get
            var gotObj1 = storage.Get(new PersistenceObject(site, "persistence1"));

            Assert.AreEqual(obj, gotObj1);
            Assert.AreEqual(obj.Body, gotObj1.Body);

            //test Update
            gotObj1.Body = gotObj1.Body + DateTime.Now.ToString();
            storage.Update(gotObj1, obj);
            var gotObj2 = storage.Get(new PersistenceObject(site, "persistence1"));

            Assert.AreNotEqual(obj.Body, gotObj2.Body);
            Assert.AreEqual(gotObj1.Body, gotObj2.Body);

            storage.Remove(new PersistenceObject(site, "persistence1"));
            var gotObj3 = storage.Get(new PersistenceObject(site, "persistence1"));

            Assert.IsNull(gotObj3);
        }
예제 #2
0
        public void Test_Add_Update_Delete()
        {
            ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test_Add_Update_Delete." + Guid.NewGuid().ToString() + ".json");
            JsonListFileStorage<PersistenceObject> storage = new JsonListFileStorage<PersistenceObject>(filePath, locker);

            var site = new Site("Site1");

            var obj = new PersistenceObject(site, "persistence1") { Body = Guid.NewGuid().ToString() };
            //test add
            storage.Add(obj);

            //test GetList
            Assert.AreEqual(1, storage.GetList(site).Count());

            //test Get
            var gotObj1 = storage.Get(new PersistenceObject(site, "persistence1"));
            Assert.AreEqual(obj, gotObj1);
            Assert.AreEqual(obj.Body, gotObj1.Body);

            //test Update
            gotObj1.Body = gotObj1.Body + DateTime.Now.ToString();
            storage.Update(gotObj1, obj);
            var gotObj2 = storage.Get(new PersistenceObject(site, "persistence1"));
            Assert.AreNotEqual(obj.Body, gotObj2.Body);
            Assert.AreEqual(gotObj1.Body, gotObj2.Body);

            storage.Remove(new PersistenceObject(site, "persistence1"));
            var gotObj3 = storage.Get(new PersistenceObject(site, "persistence1"));
            Assert.IsNull(gotObj3);
        }