public void TestUpdateSetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable <M2OClassA>(); conn.DropTable <M2OClassB>(); conn.CreateTable <M2OClassA>(); conn.CreateTable <M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); Assert.AreEqual(0, objectA.OneClassBKey); objectA.OneClassB = objectB; Assert.AreEqual(0, objectA.OneClassBKey); conn.UpdateWithChildren(objectA); Assert.AreEqual(objectB.Id, objectA.OneClassBKey); var newObjectA = conn.Get <M2OClassA>(objectA.Id); Assert.AreEqual(objectB.Id, newObjectA.OneClassBKey); }
public void TestGetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable <M2OClassA>(); conn.DropTable <M2OClassB>(); conn.CreateTable <M2OClassA>(); conn.CreateTable <M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); // Fetch (yet empty) the relationship conn.GetChildren(objectA); Assert.Null(objectA.OneClassB); // Set the relationship using IDs objectA.OneClassBKey = objectB.Id; Assert.Null(objectA.OneClassB); // Fetch the relationship conn.GetChildren(objectA); Assert.NotNull(objectA.OneClassB); Assert.AreEqual(objectB.Id, objectA.OneClassB.Id); Assert.AreEqual(objectB.Foo, objectA.OneClassB.Foo); }
public void TestUpdateUnsetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable <M2OClassA>(); conn.DropTable <M2OClassB>(); conn.CreateTable <M2OClassA>(); conn.CreateTable <M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); Assert.AreEqual(0, objectA.OneClassBKey); objectA.OneClassB = objectB; Assert.AreEqual(0, objectA.OneClassBKey); conn.UpdateWithChildren(objectA); // Until here, the test is exactly the same as TestUpdateSetManyToOne objectA.OneClassB = null; // Unset the relationship Assert.AreEqual(objectB.Id, objectA.OneClassBKey, "Foreign key shouldn't have been refreshed yet"); conn.UpdateWithChildren(objectA); Assert.AreEqual(0, objectA.OneClassBKey); Assert.Null(objectA.OneClassB); }
public void TestGetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable<M2OClassA>(); conn.DropTable<M2OClassB>(); conn.CreateTable<M2OClassA>(); conn.CreateTable<M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); // Fetch (yet empty) the relationship conn.GetChildren(objectA); Assert.Null(objectA.OneClassB); // Set the relationship using IDs objectA.OneClassBKey = objectB.Id; Assert.Null(objectA.OneClassB); // Fetch the relationship conn.GetChildren(objectA); Assert.NotNull(objectA.OneClassB); Assert.AreEqual(objectB.Id, objectA.OneClassB.Id); Assert.AreEqual(objectB.Foo, objectA.OneClassB.Foo); }
public void TestUpdateSetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable<M2OClassA>(); conn.DropTable<M2OClassB>(); conn.CreateTable<M2OClassA>(); conn.CreateTable<M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); Assert.AreEqual(0, objectA.OneClassBKey); objectA.OneClassB = objectB; Assert.AreEqual(0, objectA.OneClassBKey); conn.UpdateWithChildren(objectA); Assert.AreEqual(objectB.Id, objectA.OneClassBKey); var newObjectA = conn.Get<M2OClassA>(objectA.Id); Assert.AreEqual(objectB.Id, newObjectA.OneClassBKey); }
public void TestUpdateUnsetManyToOne() { var conn = Utils.CreateConnection(); conn.DropTable<M2OClassA>(); conn.DropTable<M2OClassB>(); conn.CreateTable<M2OClassA>(); conn.CreateTable<M2OClassB>(); // Use standard SQLite-Net API to create a new relationship var objectB = new M2OClassB { Foo = string.Format("Foo String {0}", new Random().Next(100)) }; conn.Insert(objectB); var objectA = new M2OClassA(); conn.Insert(objectA); Assert.Null(objectA.OneClassB); Assert.AreEqual(0, objectA.OneClassBKey); objectA.OneClassB = objectB; Assert.AreEqual(0, objectA.OneClassBKey); conn.UpdateWithChildren(objectA); // Until here, the test is exactly the same as TestUpdateSetManyToOne objectA.OneClassB = null; // Unset the relationship Assert.AreEqual(objectB.Id, objectA.OneClassBKey, "Foreign key shouldn't have been refreshed yet"); conn.UpdateWithChildren(objectA); Assert.AreEqual(0, objectA.OneClassBKey); Assert.Null(objectA.OneClassB); }