public void AddOrUpdate_WhenChildHasNoPK_ShouldAddChild()
        {
            var first = new PrimaryKeyWithNonPKRelation
            {
                Id          = 1,
                StringValue = "parent",
                OtherObject = new NonPrimaryKeyObject
                {
                    StringValue = "child"
                }
            };

            _realm.Write(() =>
            {
                _realm.Add(first, update: true);
            });

            var second = new PrimaryKeyWithNonPKRelation
            {
                Id          = 2,
                StringValue = "parent2",
                OtherObject = new NonPrimaryKeyObject
                {
                    StringValue = "child"
                }
            };

            _realm.Write(() =>
            {
                _realm.Add(second, update: true);
            });

            Assert.That(second.OtherObject, Is.Not.EqualTo(first.OtherObject));
            Assert.That(_realm.All <NonPrimaryKeyObject>().Count(), Is.EqualTo(2));
        }
Пример #2
0
        public void AddOrUpdate_WhenChildHasNoPK_ShouldAddChild()
        {
            var first = new PrimaryKeyWithNonPKRelation
            {
                Id = 1,
                StringValue = "parent",
                OtherObject = new NonPrimaryKeyObject
                {
                    StringValue = "child"
                }
            };

            _realm.Write(() =>
            {
                _realm.Add(first, update: true);
            });

            var second = new PrimaryKeyWithNonPKRelation
            {
                Id = 2,
                StringValue = "parent2",
                OtherObject = new NonPrimaryKeyObject
                {
                    StringValue = "child"
                }
            };

            _realm.Write(() =>
            {
                _realm.Add(second, update: true);
            });

            Assert.That(second.OtherObject, Is.Not.EqualTo(first.OtherObject));
            Assert.That(_realm.All<NonPrimaryKeyObject>().Count(), Is.EqualTo(2));
        }