public void TestOneToOneCascadeWithInverseDoubleForeignKeyReversed() { var conn = Utils.CreateConnection(); conn.DropTable <PassportWithForeignKeyDouble>(); conn.DropTable <PersonWithForeignKey>(); conn.CreateTable <PassportWithForeignKeyDouble>(); conn.CreateTable <PersonWithForeignKey>(); var person = new PersonWithForeignKey { Name = "John", Surname = "Smith" }; conn.Insert(person); var passport = new PassportWithForeignKeyDouble { PassportNumber = "JS12345678", Owner = person }; conn.Insert(passport); conn.UpdateWithChildren(passport); var obtainedPassport = conn.GetWithChildren <PassportWithForeignKeyDouble>(passport.Id, recursive: true); Assert.NotNull(obtainedPassport); Assert.NotNull(obtainedPassport.Owner); Assert.NotNull(obtainedPassport.Owner.Passport, "Circular reference should've been solved"); Assert.AreEqual(obtainedPassport.Id, obtainedPassport.Owner.Passport.Id); Assert.AreEqual(obtainedPassport.Owner.Identifier, obtainedPassport.Owner.Passport.Owner.Identifier); Assert.AreEqual(passport.Id, obtainedPassport.Id); Assert.AreEqual(person.Identifier, obtainedPassport.Owner.Identifier); }
public async void TestOneToOneCascadeWithInverseDoubleForeignKeyReversed() { var conn = Utils.CreateAsyncConnection(); await conn.DropTableAsync<PassportWithForeignKeyDouble>(); await conn.DropTableAsync<PersonWithForeignKey>(); await conn.CreateTableAsync<PassportWithForeignKeyDouble>(); await conn.CreateTableAsync<PersonWithForeignKey>(); var person = new PersonWithForeignKey { Name = "John", Surname = "Smith" }; await conn.InsertAsync(person); var passport = new PassportWithForeignKeyDouble { PassportNumber = "JS12345678", Owner = person }; await conn.InsertAsync(passport); await conn.UpdateWithChildrenAsync(passport); var obtainedPassport = await conn.GetWithChildrenAsync<PassportWithForeignKeyDouble>(passport.Id, recursive: true); Assert.NotNull(obtainedPassport); Assert.NotNull(obtainedPassport.Owner); Assert.NotNull(obtainedPassport.Owner.Passport, "Circular reference should've been solved"); Assert.AreEqual(obtainedPassport.Id, obtainedPassport.Owner.Passport.Id); Assert.AreEqual(obtainedPassport.Owner.Identifier, obtainedPassport.Owner.Passport.Owner.Identifier); Assert.AreEqual(passport.Id, obtainedPassport.Id); Assert.AreEqual(person.Identifier, obtainedPassport.Owner.Identifier); }