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);
        }
Beispiel #2
0
        public void SingleEntityFetchTest()
        {
            var drivers = new Driver[]
            {
                new Driver()
                {
                    Name = "Speed Racer"
                },
                new Driver()
                {
                    Name = "Shaggy"
                },
                new Driver()
                {
                    Name = "Mario"
                },
                new Driver()
                {
                    Name = "Luigi"
                },
            };

            var store = new SQLiteDataStore("test.sqlite");

            store.AddType <Driver>();
            store.CreateStore();
            foreach (var driver in drivers)
            {
                store.Insert(driver);
            }

            var items = store.Fetch <Driver>(2).ToArray();

            Assert.AreEqual(2, items.Length);
        }
Beispiel #3
0
        public void ManyToOneReferenceTest()
        {
            var driver = new Driver()
            {
                Name = "Speed Racer"
            };

            driver.Vehicles.AddRange(
                new Vehicle[]
            {
                new Vehicle()
                {
                    Model = "Super Fast"
                },
                new Vehicle()
                {
                    Model = "Sorta Fast"
                }
            });

            var Order = new Order()
            {
                Number = "1234",
                Driver = driver
            };

            var store = new SQLiteDataStore("test.sqlite");

            store.AddType <Order>();
            store.AddType <Driver>();
            store.AddType <Vehicle>();
            store.CreateStore();
            store.Insert(Order, true);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public void LongIDTest()
        {
            var store = new SQLiteDataStore("test2.db");

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

            store.Insert(new BigID("Foo"));
            var bid = store.Select <BigID>();
        }
Beispiel #6
0
        public void SimpleReferenceTest()
        {
            var store = new SQLiteDataStore("simpleReferenceTest.db");

            store.AddType <Author>();
            store.AddType <Book>();
            store.CreateOrUpdateStore();

            // insert an author
            var dumas = new Author()
            {
                Name = "Alexadre Dumas"
            };

            store.Insert(dumas);

            // insert a couple books.
            // note that we're inserting the foreign key value
            store.Insert(
                new Book()
            {
                AuthorID = dumas.ID,
                Title    = "The Count of Monte Cristo"
            });

            store.Insert(
                new Book()
            {
                AuthorID = dumas.ID,
                Title    = "The Three Musketeers"
            });

            // now get the authors back, telling ORM to fill the references
            var authors = store.Select <Author>(true).ToArray();

            // at this point you will have 1 Author instance, with the Books property hydrated and containing two Book instances
        }
Beispiel #7
0
        public void SimpleReferenceTest2()
        {
            var store = new SQLiteDataStore("simpleReferenceTest.db");

            store.AddType <Location>();
            store.AddType <Position>();
            store.CreateOrUpdateStore();

            var position1 = new Position()
            {
                Description = "Position 1"
            };

            store.Insert(position1);

            store.Insert(
                new Location()
            {
                Description = "Description A",
                positionId  = position1.positionId
            });

            var positions = store.Select <Position>(true).ToArray();
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }