Dictionary <string, Person> Test2Init() { Console.WriteLine("Generating stuff..."); var r = new Random(); var result = new Dictionary <string, Person>(); using (var db = new MyDbInstance("test.db.3")) { db.Purge(); var people = db.Table <Person>(); for (var i = 0; i < t2Count; i++) { var p = new Person { Id = "T" + i, FirstName = "A" + r.Next(1000), LastName = "B" + r.Next(1000) }; result.Add(p.Id, p); } people.Save(result.Values); } return(result); }
public void Test3() { using (var db = new MyDbInstance("test.db.4")) { db.Purge(); var people = db.Table<Person>(); people.Save(new[] { new Person { Id = "A" }, new Person { Id = "B" }}); people.DeleteByKey("A"); people.Save(new Person { Id = "A" }); } }
public void Test3() { using (var db = new MyDbInstance("test.db.4")) { db.Purge(); var people = db.Table <Person>(); people.Save(new[] { new Person { Id = "A" }, new Person { Id = "B" } }); people.DeleteByKey("A"); people.Save(new Person { Id = "A" }); } }
Dictionary<string, Person> Test2Init() { Console.WriteLine("Generating stuff..."); var r = new Random(); var result = new Dictionary<string, Person>(); using (var db = new MyDbInstance("test.db.3")) { db.Purge(); var people = db.Table<Person>(); for (var i = 0; i < t2Count; i++) { var p = new Person { Id = "T" + i, FirstName = "A" + r.Next(1000), LastName = "B" + r.Next(1000) }; result.Add(p.Id, p); } people.Save(result.Values); } return result; }
void Test2Modify(Dictionary <string, Person> dic) { Console.WriteLine("Deleting stuff..."); Person p; var r = new Random(); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table <Person>(); var keys = new List <string>(); for (var i = 0; i < 1000; i++) { var x = "T" + r.Next(t2Count); if (dic.TryGetValue(x, out p)) { keys.Add(p.Id); dic.Remove(p.Id); } } people.DeleteByKeys(keys); } Console.WriteLine("Modifying stuff..."); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table <Person>(); var updates = new List <Person>(); for (var i = 0; i < 1000; i++) { var x = "T" + r.Next(t2Count); if (dic.TryGetValue(x, out p)) { p.FirstName = "A" + r.Next(1000); p.LastName = "B" + r.Next(1000); updates.Add(p); } } people.Save(updates); } Console.WriteLine("Comparing stuff..."); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table <Person>().LoadAll().OrderBy(i => i.Id).ToArray(); var dicPeople = dic.Values.OrderBy(i => i.Id).ToArray(); if (!people.Select(i => i.Id).SequenceEqual(dicPeople.Select(i => i.Id))) { throw new InvalidOperationException("Id mismatch"); } if (!people.Select(i => i.FirstName).SequenceEqual(dicPeople.Select(i => i.FirstName))) { throw new InvalidOperationException("FirstName mismatch"); } if (!people.Select(i => i.LastName).SequenceEqual(dicPeople.Select(i => i.LastName))) { throw new InvalidOperationException("LastName mismatch"); } } }
void Test2Modify(Dictionary<string, Person> dic) { Console.WriteLine("Deleting stuff..."); Person p; var r = new Random(); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table<Person>(); var keys = new List<string>(); for (var i = 0; i < 1000; i++) { var x = "T" + r.Next(t2Count); if (dic.TryGetValue(x, out p)) { keys.Add(p.Id); dic.Remove(p.Id); } } people.DeleteByKeys(keys); } Console.WriteLine("Modifying stuff..."); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table<Person>(); var updates = new List<Person>(); for (var i = 0; i < 1000; i++) { var x = "T" + r.Next(t2Count); if (dic.TryGetValue(x, out p)) { p.FirstName = "A" + r.Next(1000); p.LastName = "B" + r.Next(1000); updates.Add(p); } } people.Save(updates); } Console.WriteLine("Comparing stuff..."); using (var db = new MyDbInstance("test.db.3")) { var people = db.Table<Person>().LoadAll().OrderBy(i => i.Id).ToArray(); var dicPeople = dic.Values.OrderBy(i => i.Id).ToArray(); if (!people.Select(i => i.Id).SequenceEqual(dicPeople.Select(i => i.Id))) throw new InvalidOperationException("Id mismatch"); if (!people.Select(i => i.FirstName).SequenceEqual(dicPeople.Select(i => i.FirstName))) throw new InvalidOperationException("FirstName mismatch"); if (!people.Select(i => i.LastName).SequenceEqual(dicPeople.Select(i => i.LastName))) throw new InvalidOperationException("LastName mismatch"); } }