public void AddOrUpdate_WhenListObjectsDontHavePK_ShouldOverwriteList()
        {
            var first = new PrimaryKeyWithNoPKList
            {
                Id = 1
            };

            first.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "1"
            });

            _realm.Write(() => _realm.Add(first));

            var second = new PrimaryKeyWithNoPKList
            {
                Id = 1
            };

            second.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "2"
            });

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

            Assert.That(first.ListValue, Is.EquivalentTo(second.ListValue));

            // Verify that the original list was replaced with the new one and not merged with it.
            Assert.That(first.ListValue.Count, Is.EqualTo(1));

            // Verify that the list's sole element has the correct String value.
            Assert.That(first.ListValue[0].StringValue, Is.EqualTo("2"));

            // Verify that overwriting the list hasn't deleted any elements from the Realm.
            Assert.That(_realm.All <NonPrimaryKeyObject>().Count(), Is.EqualTo(2));
        }
        public void AddOrUpdate_WhenListHasNoPK_ShouldAddListItems()
        {
            var first = new PrimaryKeyWithNoPKList
            {
                Id          = 1,
                StringValue = "first"
            };

            first.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "child"
            });

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

            var second = new PrimaryKeyWithNoPKList
            {
                Id          = 2,
                StringValue = "second"
            };

            second.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "secondChild"
            });

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

            Assert.That(first.ListValue, Is.Not.EqualTo(second.ListValue));
            Assert.That(_realm.All <NonPrimaryKeyObject>().Count(), Is.EqualTo(2));
        }
Exemplo n.º 3
0
        public void AddOrUpdate_WhenListObjectsDontHavePK_ShouldOverwriteList()
        {
            var first = new PrimaryKeyWithNoPKList
            {
                Id = 1
            };

            first.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "1"
            });

            _realm.Write(() => _realm.Add(first));

            var second = new PrimaryKeyWithNoPKList
            {
                Id = 1
            };

            second.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "2"
            });

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

            Assert.That(first.ListValue, Is.EquivalentTo(second.ListValue));

            // Verify that the original list was replaced with the new one and not merged with it.
            Assert.That(first.ListValue.Count, Is.EqualTo(1));

            // Verify that the list's sole element has the correct String value.
            Assert.That(first.ListValue[0].StringValue, Is.EqualTo("2"));

            // Verify that overwriting the list hasn't deleted any elements from the Realm.
            Assert.That(_realm.All<NonPrimaryKeyObject>().Count(), Is.EqualTo(2));
        }
Exemplo n.º 4
0
        public void AddOrUpdate_WhenListHasNoPK_ShouldAddListItems()
        {
            var first = new PrimaryKeyWithNoPKList
            {
                Id = 1,
                StringValue = "first"
            };

            first.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "child"
            });

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

            var second = new PrimaryKeyWithNoPKList
            {
                Id = 2,
                StringValue = "second"
            };

            second.ListValue.Add(new NonPrimaryKeyObject
            {
                StringValue = "secondChild"
            });

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

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