public void AddOrUpdate_WhenRelationIsNull_ShouldClearLink() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "has child", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var updatedFirst = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "no child" }; _realm.Write(() => { _realm.Add(updatedFirst, update: true); }); Assert.That(first.OtherObject, Is.Null); Assert.That(updatedFirst.OtherObject, Is.Null); Assert.That(_realm.Find <PrimaryKeyWithPKRelation>(1).OtherObject, Is.Null); }
public void AddOrUpdate_WhenParentExistsChildDoesnt_ShouldAddChild() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent", OtherObject = new PrimaryKeyObject { Id = 2, StringValue = "child2" } }; _realm.Write(() => { _realm.Add(second, update: true); }); var queried = _realm.Find <PrimaryKeyWithPKRelation>(1); Assert.That(queried.OtherObject, Is.Not.Null); Assert.That(queried.StringValue, Is.EqualTo("parent")); Assert.That(queried.OtherObject.StringValue, Is.EqualTo("child2")); var child1 = _realm.Find <PrimaryKeyObject>(1); Assert.That(child1.StringValue, Is.EqualTo("child")); var child2 = _realm.Find <PrimaryKeyObject>(2); Assert.That(child2.StringValue, Is.EqualTo("child2")); }
public void AddOrUpdate_WhenChildHasPK_ShouldUpdateChild() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new PrimaryKeyWithPKRelation { Id = 2, StringValue = "parent2", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child2" } }; _realm.Write(() => { _realm.Add(second, update: true); }); Assert.That(second.OtherObject, Is.EqualTo(first.OtherObject)); Assert.That(_realm.All <PrimaryKeyObject>().Count(), Is.EqualTo(1)); Assert.That(_realm.Find <PrimaryKeyObject>(1).StringValue, Is.EqualTo("child2")); }
public void AddOrUpdate_WhenRelationIsNull_ShouldClearLink() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "has child", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var updatedFirst = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "no child" }; _realm.Write(() => { _realm.Add(updatedFirst, update: true); }); Assert.That(first.OtherObject, Is.Null); Assert.That(updatedFirst.OtherObject, Is.Null); Assert.That(_realm.Find<PrimaryKeyWithPKRelation>(1).OtherObject, Is.Null); }
public void AddOrUpdate_WhenChildHasPK_ShouldUpdateChild() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new PrimaryKeyWithPKRelation { Id = 2, StringValue = "parent2", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child2" } }; _realm.Write(() => { _realm.Add(second, update: true); }); Assert.That(second.OtherObject, Is.EqualTo(first.OtherObject)); Assert.That(_realm.All<PrimaryKeyObject>().Count(), Is.EqualTo(1)); Assert.That(_realm.Find<PrimaryKeyObject>(1).StringValue, Is.EqualTo("child2")); }
public void AddOrUpdate_WhenParentAndChildExist_ShouldUpdateBoth() { var first = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child" } }; _realm.Write(() => { _realm.Add(first, update: true); }); var second = new PrimaryKeyWithPKRelation { Id = 1, StringValue = "parent2", OtherObject = new PrimaryKeyObject { Id = 1, StringValue = "child2" } }; _realm.Write(() => { _realm.Add(second, update: true); }); var queried = _realm.Find<PrimaryKeyWithPKRelation>(1); Assert.That(queried.OtherObject, Is.Not.Null); Assert.That(queried.StringValue, Is.EqualTo("parent2")); Assert.That(queried.OtherObject.StringValue, Is.EqualTo("child2")); var child1 = _realm.Find<PrimaryKeyObject>(1); Assert.That(child1.StringValue, Is.EqualTo("child2")); }