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()); }
DbInstance Prepare() { var db = new DbInstance("MyDatabase3"); db.Map <AData, PrototypeBasedData>().Automap(i => i.Id, true); db.Initialize(); return(db); }
DbInstance Prepare() { var db = new DbInstance("MyDatabase2"); db.Map <IData, InterfaceBasedData>().Automap(i => i.Id, true); db.Initialize(); return(db); }
DbInstance Prepare() { var db = new DbInstance("MyDatabase"); db.Map <MyData>().Automap(i => i.Id, true); db.Initialize(); return(db); }
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); }
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()); } }
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); }
// [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) { } }
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) { } }
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(); }
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); }
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)); }