Ejemplo n.º 1
0
        //    [ExpectedException(typeof(InvalidOperationException))]
        public void DoubleOpenDbComplexPath()
        {
            try
            {
                var db = new DbInstance(@"My Database\My Schema");
                db.Initialize();
                db.Initialize();

                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 2
0
        void TestDeleteBugfix()
        {
            var db = new DbInstance("test.fix1");

            //mapping done before init
            db.Map <TemplateModel>().Automap(i => i.Id, false).WithIndex <int>("Type", i => i.Type);

            db.Initialize();

            //testing this in a method
            db.Table <TemplateModel>().Save(new TemplateModel {
                Id = 66, Name = "test", Type = 3
            });
            db.Table <TemplateModel>().Save(new TemplateModel {
                Id = 67, Name = "test2", Type = 3
            });
            //The Type is 3 for both records
            //The first indexQuery returns 2 records, OK!
            var indexQuery = db.Table <TemplateModel>().IndexQueryByKey <int>("Type", 3).ToList();

            db.Table <TemplateModel>().DeleteByKey <int>(67);

            //allItems returns 1 record, OK!
            var allItems = db.Table <TemplateModel>().LoadAll().ToList();

            //indexQuery2 returns 0 records, wrong!
            var indexQuery2 = db.Table <TemplateModel>().IndexQueryByKey <int>("Type", 3).ToList();

            Assert.AreEqual(1, indexQuery2.Count());
        }
Ejemplo n.º 3
0
        DbInstance Prepare()
        {
            var db = new DbInstance("MyDatabase2");

            db.Map <IData, InterfaceBasedData>().Automap(i => i.Id, true);
            db.Initialize();
            return(db);
        }
Ejemplo n.º 4
0
        DbInstance Prepare()
        {
            var db = new DbInstance("MyDatabase3");

            db.Map <AData, PrototypeBasedData>().Automap(i => i.Id, true);
            db.Initialize();
            return(db);
        }
Ejemplo n.º 5
0
        DbInstance Prepare()
        {
            var db = new DbInstance("MyDatabase");

            db.Map <MyData>().Automap(i => i.Id, true);
            db.Initialize();
            return(db);
        }
Ejemplo n.º 6
0
        public void Indexing2()
        {
            var db = new DbInstance(@"MyDatabase2\Indexing");

            db.Map <IData, InterfaceBasedData>().Automap(i => i.Id, true)
            .WithIndex("LastName", i => i.Name, StringComparer.CurrentCulture)
            .WithIndex("LastNameText", i => i.Name, StringComparer.CurrentCultureIgnoreCase);
            db.Initialize();

            var table = db.Table <IData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new InterfaceBasedData {
                            Name = "Test" + i
                        });
                    }
                }

                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new InterfaceBasedData {
                            Name = "TeST" + i
                        });
                    }
                }
            });

            var list1count = table.IndexQuery <string>("LastName").Key("Test5").Count();
            var list2count = table.IndexQuery <string>("LastNameText").Key("TEst5").Count();

            Assert.AreEqual(list1count, 100);
            Assert.AreEqual(list2count, 200);

            var list3count = table.IndexQuery <string>("LastName").GreaterThan("Test5").Count();
            var list4count = table.IndexQuery <string>("LastName").LessThan("Test6").Count();
            var list5count = table.IndexQuery <string>("LastName").LessThan("Test6").GreaterThan("Test5").Count();

            Assert.AreEqual(900, list3count);
            Assert.AreEqual(1200, list4count);
            Assert.AreEqual(100, list5count);

            var list6count = table.IndexQuery <string>("LastName").GreaterThan("Test5", true).Count();
            var list7count = table.IndexQuery <string>("LastName").LessThan("Test6", true).Count();
            var list8count = table.IndexQuery <string>("LastName").LessThan("Test6", true).GreaterThan("Test5", true).Count();

            Assert.AreEqual(1000, list6count);
            Assert.AreEqual(1300, list7count);
            Assert.AreEqual(300, list8count);
        }
Ejemplo n.º 7
0
        public void TestPackageLocation()
        {
            using (var db = new DbInstance("TestPackage", Windows.ApplicationModel.Package.Current.InstalledLocation))
            {
                db.Map <MyData>().Automap(i => i.Id, true);
                db.Initialize();

                db.Save(new MyData());
            }
        }
Ejemplo n.º 8
0
        public void TestGordon()
        {
            var db = new DbInstance("gordon.db");

            db.Map <Person>().Automap(i => i.PersonID, true).WithIndex("Surname", i => i.Surname);
            db.Initialize();

            var table = db.Table <Person>();

            table.Purge();

            Person newPerson1 = new Person {
                Forename = "Joe", Surname = "Bloggs"
            };
            Person newPerson2 = new Person {
                Forename = "James", Surname = "Smith"
            };
            Person newPerson3 = new Person {
                Forename = "David", Surname = "Peterson"
            };
            Person newPerson4 = new Person {
                Forename = "Steve", Surname = "Gordon"
            };
            Person newPerson5 = new Person {
                Forename = "David", Surname = "Gordon"
            };
            Person newPerson6 = new Person {
                Forename = "Colin", Surname = "Gordon"
            };
            Person newPerson7 = new Person {
                Forename = "Michael", Surname = "Gordon"
            };

            var newPeople = new[]
            {
                newPerson1,
                newPerson2,
                newPerson3,
                newPerson4,
                newPerson5,
                newPerson6,
                newPerson7
            };

            table.Save(newPeople);

            var index = table.IndexQuery <string>("Surname");
            // HIJKLMNOPQRS

            var queryindex = index.GreaterThan("H", true).LessThan("T", true).ToLazyList();

            Assert.AreEqual(2, queryindex.Count);
        }
Ejemplo n.º 9
0
        //    [ExpectedException(typeof(InvalidOperationException))]
        public void MapDbWrong()
        {
            try
            {
                var db = new DbInstance(@"My Database\My Schema");

                db.Initialize();

                db.Map <MyData>().Automap(i => i.Id);

                Assert.Fail("InvalidOperationException expected");
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 10
0
        public void OpenDbComplexPath2()
        {
            try
            {
                var db = new DbInstance(@"d:\test.db");
                db.Initialize();
            }
#if SILVERLIGHT
            catch (System.IO.IsolatedStorage.IsolatedStorageException)
            {
                // SL without ElevatedPriviliges does not allow absolute path access
            }
#endif
            finally
            {
            }
        }
Ejemplo n.º 11
0
        public void TestPackageLocation()
        {
            try
            {
                using (var db = new DbInstance("TestPackage", Windows.ApplicationModel.Package.Current.InstalledLocation))
                {
                    db.Map <MyData>().Automap(i => i.Id, true);
                    db.Initialize();

                    db.Save(new MyData());
                }
                Assert.Fail("Must fail");
            }
            catch (IOException)
            {
            }
        }
Ejemplo n.º 12
0
        public void TestPKKey <T>(Expression <Func <MyDataKeys, T> > pkGetter, Action <MyDataKeys, T> pkSetter, T key)
        {
            var db = new DbInstance("DbKeys");

            db.Map <MyDataKeys>().Key(pkGetter);
            db.Initialize();
            var getter = pkGetter.Compile();
            var obj1   = new MyDataKeys();

            pkSetter(obj1, key);
            db.Save(obj1);

            var obj2 = db.LoadByKey <MyDataKeys>(key);

            Assert.AreEqual(getter(obj1), getter(obj2));

            db.Purge();
        }
Ejemplo n.º 13
0
        public void Indexing3()
        {
            var db = new DbInstance(@"MyDatabase3\Indexing");

            db.Map <AData, PrototypeBasedData>().Automap(i => i.Id, true)
            .WithIndex("LastName", i => i.Name, StringComparer.CurrentCulture)
            .WithIndex("LastNameText", i => i.Name, StringComparer.CurrentCultureIgnoreCase);
            db.Initialize();

            var table = db.Table <AData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new PrototypeBasedData {
                            Name = "Test" + i
                        });
                    }
                }

                for (var s = 0; s < 100; s++)
                {
                    for (var i = 0; i < 10; i++)
                    {
                        table.Save(new PrototypeBasedData {
                            Name = "TeST" + i
                        });
                    }
                }
            });

            var list1count = table.IndexQueryByKey("LastName", "Test5").Count();
            var list2count = table.IndexQueryByKey("LastNameText", "TEst5").Count();

            Assert.AreEqual(list1count, 100);
            Assert.AreEqual(list2count, 200);
        }
Ejemplo n.º 14
0
        public void OpenDb()
        {
            var db = new DbInstance("My Database");

            db.Initialize();
        }
Ejemplo n.º 15
0
        public void OpenDbComplexPath()
        {
            var db = new DbInstance(@"My Database\My Schema");

            db.Initialize();
        }
Ejemplo n.º 16
0
        public void OpenDbComplexPath2()
        {
            var db = new DbInstance(@"My Database\My Schema", Windows.Storage.ApplicationData.Current.TemporaryFolder);

            db.Initialize();
        }
Ejemplo n.º 17
0
        public void IndexingDetails()
        {
            var db = new DbInstance(@"My Database\Indexing2");

            db.Map <MyData>().Automap(i => i.Id, true).WithIndex("Test", i => i.IntField);
            db.Initialize();

            var table = db.Table <MyData>();

            table.Purge();

            db.BulkWrite(() =>
            {
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 1
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 3
                });
                table.Save(new MyData {
                    IntField = 4
                });
                table.Save(new MyData {
                    IntField = 5
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 6
                });
                table.Save(new MyData {
                    IntField = 7
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 8
                });
                table.Save(new MyData {
                    IntField = 9
                });
            });

            var list1 = table.LoadAll();

            var index = table.IndexQuery <int>("Test");

            Assert.AreEqual(index.Key(1).Count(), list1.Count(i => i.IntField == 1));
            Assert.AreEqual(index.Key(8).Count(), list1.Count(i => i.IntField == 8));

            Assert.AreEqual(index.GreaterThan(6, true).LessThan(8).Count(), list1.Count(i => i.IntField >= 6 && i.IntField < 8));

            IdSequenceEqual(index.GreaterThan(6).LessThan(8).ToList(), list1.Where(i => i.IntField > 6 && i.IntField < 8));
            IdSequenceEqual(index.LessThan(8).ToList(), list1.Where(i => i.IntField < 8));
            IdSequenceEqual(index.GreaterThan(6, true).ToList(), list1.Where(i => i.IntField >= 6));
            IdSequenceEqual(index.GreaterThan(7, true).LessThan(7).ToList(), list1.Where(i => i.IntField >= 7 && i.IntField < 7));
            IdSequenceEqual(index.GreaterThan(7).LessThan(7, true).ToList(), list1.Where(i => i.IntField > 7 && i.IntField <= 7));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Asynchronously initializes database instance
 /// </summary>
 /// <param name="db">Database instance to initialize</param>
 /// <returns>Awaitable Task of initialize operation</returns>
 public static Task InitializeAsync(this DbInstance db)
 {
     return(TaskEx.Run(() => db.Initialize()));
 }