Ejemplo n.º 1
0
        public void Set_WhenObjectIsManaged_ShouldWork()
        {
            var container   = new ContainerObject();
            var objectToSet = new IntPropertyObject
            {
                Int = 42
            };

            _realm.Write(() =>
            {
                _realm.Add(container);
                container.Items.Add(new IntPropertyObject
                {
                    Int = -1
                });

                _realm.Add(objectToSet);
            });

            _realm.Write(() => container.Items[0] = objectToSet);

            Assert.That(container.Items.Count, Is.EqualTo(1));
            Assert.That(container.Items[0], Is.EqualTo(objectToSet));
            Assert.That(container.Items[0].Int, Is.EqualTo(42));
        }
Ejemplo n.º 2
0
        public void ThreadSafeReference_WhenObjectIsDeleted_ShouldFail()
        {
            var obj = new IntPropertyObject();

            _realm.Write(() => _realm.Add(obj));
            _realm.Write(() => _realm.Remove(obj));

            Assert.That(() => ThreadSafeReference.Create(obj), Throws.InstanceOf <RealmException>().And.Message.Contains("invalidated object"));
        }
Ejemplo n.º 3
0
        private ThreadSafeReference.Object <IntPropertyObject> SetupObjectReference()
        {
            var obj = new IntPropertyObject {
                Int = 12
            };

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

            return(ThreadSafeReference.Create(obj));
        }
Ejemplo n.º 4
0
        public void Insert_WhenIndexIsEqualToCount_ShouldWork()
        {
            var container = new ContainerObject();

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

            var toInsert1 = new IntPropertyObject();

            _realm.Write(() => container.Items.Insert(0, toInsert1));
            Assert.That(container.Items.Count, Is.EqualTo(1));
            Assert.That(container.Items[0], Is.EqualTo(toInsert1));

            var toInsert2 = new IntPropertyObject();

            _realm.Write(() => container.Items.Insert(1, toInsert2));
            Assert.That(container.Items.Count, Is.EqualTo(2));
            Assert.That(container.Items[1], Is.EqualTo(toInsert2));
        }
Ejemplo n.º 5
0
        public void ObjectReference_ResolveDeletedObject_ShouldReturnNull()
        {
            TestHelpers.RunAsyncTest(async() =>
            {
                var obj = new IntPropertyObject {
                    Int = 12
                };
                _realm.Write(() => _realm.Add(obj));

                var objReference = ThreadSafeReference.Create(obj);

                _realm.Write(() => _realm.Remove(obj));

                await Task.Run(() =>
                {
                    using var otherRealm = GetRealm(_realm.Config);
                    var otherObj         = otherRealm.ResolveReference(objReference);
                    Assert.That(otherObj, Is.Null);
                });
            });
        }
Ejemplo n.º 6
0
        public void ThreadSafeReference_WhenAnObjectIsUnmanaged_ShouldFail()
        {
            var obj = new IntPropertyObject();

            Assert.That(() => ThreadSafeReference.Create(obj), Throws.InstanceOf <RealmException>().And.Message.Contains("unmanaged object"));
        }