public void SimpleCRUDTest()
        {
            var store = new SQLiteDataStore("test.db");

            store.AddType <TestItem>();
            store.CreateStore();

            var itemA = new TestItem("ItemA");
            var itemB = new TestItem("ItemB");
            var itemC = new TestItem("ItemC");

            // INSERT
            store.Insert(itemA);
            store.Insert(itemB);
            store.Insert(itemC);

            // COUNT
            var count = store.Count <TestItem>();

            Assert.AreEqual(3, count);

            // SELECT
            var item = store.Select <TestItem>("Name", itemB.Name).FirstOrDefault();

            Assert.IsTrue(item.Equals(itemB));

            item = store.Select <TestItem>(3);
            Assert.IsTrue(item.Equals(itemC));

            // FETCH

            // UPDATE
            itemC.Name    = "NewItem";
            itemC.Address = "Changed Address";
            itemC.TS      = new TimeSpan(8, 23, 30);
            store.Update(itemC);

            item = store.Select <TestItem>("Name", "ItemC").FirstOrDefault();
            Assert.IsNull(item);
            item = store.Select <TestItem>("Name", itemC.Name).FirstOrDefault();
            Assert.IsTrue(item.Equals(itemC));

            // CONTAINS
            var exists = store.Contains(itemA);

            Assert.IsTrue(exists);

            // DELETE
            store.Delete(itemA, false);
            item = store.Select <TestItem>("Name", itemA.Name).FirstOrDefault();
            Assert.IsNull(item);

            // CONTAINS
            exists = store.Contains(itemA);
            Assert.IsFalse(exists);

            // COUNT
            count = store.Count <TestItem>();
            Assert.AreEqual(2, count);
        }
Ejemplo n.º 2
0
        public void Run()
        {
            var store = new SQLiteDataStore(Path.Combine(Application.StartupPath, "northwind.db"));

            // get all orders, with the associated (reference) customer for each
            var orders = store.Select <Orders>(true).ToArray();

            var oldOrder = orders.Last();

            // create a new order for the same customer as the last in the list
            var newOrder = new Orders()
            {
                OrderID     = oldOrder.OrderID + 1, // this database does not use auto-incrementing keys
                CustomerID  = oldOrder.CustomerID,
                ShipName    = "ATTN: John Steinbeck",
                ShipAddress = "7 Rue de M",
                ShipCity    = "Paris",
                ShipCountry = "France",
                ShippedDate = new DateTime(1955, 6, 1)
            };

            // insert that order
            store.Insert(newOrder);

            // select that order back out by PK
            var order = store.Select <Orders>(o => o.ShipName.Contains("Steinbeck")).First();

            // now delete that order by PK value
            store.Delete <Orders>(order.OrderID);
        }
Ejemplo n.º 3
0
        public void SimpleGuidIDEntityTest()
        {
            var store = new SQLiteDataStore("test.db");

            store.AddType <GuidItem>();
            store.CreateStore();

            var item = new GuidItem();

            store.Insert(item);

            var existing = store.Select <GuidItem>(item.ID);

            Assert.IsNotNull(existing);
            Assert.AreEqual(item.ID, existing.ID);

            store.Delete <GuidItem>(item.ID);
            existing = store.Select <GuidItem>(item.ID);
            Assert.IsNull(existing);
        }
Ejemplo n.º 4
0
        public void SimpleCRUDTest()
        {
            var path  = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "test.db");
            var store = new SQLiteDataStore(path);

            store.AddType <TestItem>();

            TestItem itemA;
            TestItem itemB;
            TestItem itemC;

            if (store.StoreExists)
            {
                store.DeleteStore();
            }

            store.CreateStore();

            itemA = new TestItem("ItemA");
            itemB = new TestItem("ItemB");
            itemC = new TestItem("ItemC");

            // INSERT
            store.Insert(itemA);
            store.Insert(itemB);
            store.Insert(itemC);

            // COUNT
            var count = store.Count <TestItem>();

            //Assert.AreEqual(3, count);
            if (count != 3)
            {
                Debugger.Break();
            }


            // SELECT
            var item = store.Select <TestItem>("Name", itemB.Name).FirstOrDefault();

            //Assert.IsTrue(item.Equals(itemB));

            item = store.Select <TestItem>(3);
            //Assert.IsTrue(item.Equals(itemC));

            // FETCH

            // UPDATE
            itemC.Name    = "NewItem";
            itemC.Address = "Changed Address";
            itemC.TS      = new TimeSpan(8, 23, 30);
            store.Update(itemC);

            item = store.Select <TestItem>("Name", "ItemC").FirstOrDefault();
            //Assert.IsNull(item);
            item = store.Select <TestItem>("Name", itemC.Name).FirstOrDefault();
            //Assert.IsTrue(item.Equals(itemC));

            // CONTAINS
            var exists = store.Contains(itemA);

            //Assert.IsTrue(exists);

            // DELETE
            store.Delete(itemA);
            item = store.Select <TestItem>("Name", itemA.Name).FirstOrDefault();
            //Assert.IsNull(item);

            // CONTAINS
            exists = store.Contains(itemA);
            //Assert.IsFalse(exists);

            // COUNT
            count = store.Count <TestItem>();
            //Assert.AreEqual(2, count);
        }