public void AddOrUpdate_WhenParentHasNoPKChildHasPK_ShouldAddParentUpdateChild() { var first = new NonPrimaryKeyWithPKRelation { StringValue = "first parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new NonPrimaryKeyWithPKRelation { StringValue = "second parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "updated child" } }; _realm.Write(() => { _realm.Add(second, update: true); }); Assert.That(_realm.All <NonPrimaryKeyWithPKRelation>().Count(), Is.EqualTo(2)); Assert.That(_realm.All <PrimaryKeyObject>().Count(), Is.EqualTo(1)); Assert.That(_realm.Find <PrimaryKeyObject>(1).StringValue, Is.EqualTo("updated child")); }
public void AddOrUpdate_WhenParentHasNoPKChildHasPK_ShouldAddParentUpdateChild() { var first = new NonPrimaryKeyWithPKRelation { StringValue = "first parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new NonPrimaryKeyWithPKRelation { StringValue = "second parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "updated child" } }; _realm.Write(() => { _realm.Add(second, update: true); }); Assert.That(_realm.All<NonPrimaryKeyWithPKRelation>().Count(), Is.EqualTo(2)); Assert.That(_realm.All<PrimaryKeyObject>().Count(), Is.EqualTo(1)); Assert.That(_realm.Find<PrimaryKeyObject>(1).StringValue, Is.EqualTo("updated child")); }