public void TestGetAllFilter() { var conn = Utils.CreateConnection(); conn.DropTable <O2OClassC>(); conn.DropTable <O2OClassD>(); conn.CreateTable <O2OClassC>(); conn.CreateTable <O2OClassD>(); var c1 = new O2OClassC { Bar = "Bar 1" }; var c2 = new O2OClassC { Bar = "Foo 2" }; var c3 = new O2OClassC { Bar = "Bar 3" }; var cObjects = new [] { c1, c2, c3 }; conn.InsertAll(cObjects); var d1 = new O2OClassD { Foo = "Foo 1" }; var d2 = new O2OClassD { Foo = "Foo 2" }; var d3 = new O2OClassD { Foo = "Foo 3" }; var bObjects = new [] { d1, d2, d3 }; conn.InsertAll(bObjects); c1.ElementD = d1; c2.ElementD = d2; c3.ElementD = d3; conn.UpdateWithChildren(c1); conn.UpdateWithChildren(c2); conn.UpdateWithChildren(c3); var expectedCObjects = cObjects.Where(c => c.Bar.Contains("Bar")).ToArray(); var cElements = conn.GetAllWithChildren <O2OClassC>(c => c.Bar.Contains("Bar")) .OrderBy(a => a.ClassId).ToArray(); Assert.AreEqual(expectedCObjects.Length, cElements.Length); for (int i = 0; i < expectedCObjects.Length; i++) { Assert.AreEqual(expectedCObjects[i].ClassId, cElements[i].ClassId); Assert.AreEqual(expectedCObjects[i].ElementD.Id, cElements[i].ElementD.Id); Assert.AreEqual(expectedCObjects[i].ElementD.Foo, cElements[i].ElementD.Foo); } }
public void TestGetOneToOneInverseForeignKey() { var conn = Utils.CreateConnection(); conn.DropTable <O2OClassC>(); conn.DropTable <O2OClassD>(); conn.CreateTable <O2OClassC>(); conn.CreateTable <O2OClassD>(); // Use standard SQLite-Net API to create a new relationship var objectC = new O2OClassC { Bar = string.Format("Bar String {0}", new Random().Next(100)) }; conn.Insert(objectC); Assert.Null(objectC.ElementD); // Fetch (yet empty) the relationship conn.GetChildren(objectC); Assert.Null(objectC.ElementD); var objectD = new O2OClassD { ObjectCKey = objectC.ClassId, Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectD); Assert.Null(objectC.ElementD); // Fetch the relationship conn.GetChildren(objectC); Assert.NotNull(objectC.ElementD); Assert.AreEqual(objectC.ClassId, objectC.ElementD.ObjectCKey); Assert.AreEqual(objectD.Foo, objectC.ElementD.Foo); }