상속: RealmObject
예제 #1
0
 public void TimsIterableDogsThrowExceptions()
 {
     var tim = realm.All<Owner>().First(p => p.Name == "Tim");
     Assert.That(() => tim.Dogs.CopyTo(null, 0), Throws.TypeOf<ArgumentNullException>());
     var copiedDogs = new Dog[2];
     Assert.That(() => tim.Dogs.CopyTo(copiedDogs, -1), Throws.TypeOf<ArgumentOutOfRangeException>());
     Assert.That(() => tim.Dogs.CopyTo(copiedDogs, 1), Throws.TypeOf<ArgumentException>()); // insuffiient room
 }
예제 #2
0
        public void TestAddingStandAloneObjectToToManyRelationship()
        {
            var owner = realm.All<Owner>().First();
            var dog = new Dog { Name = "Astro" };

            using (var trans = realm.BeginWrite())
            {
                owner.Dogs.Add(dog);
                trans.Commit();
            }

            var dogAgain = realm.All<Dog>().Single(d => d.Name == "Astro");
            Assert.That(dogAgain, Is.Not.Null);
            Assert.That(dog.IsManaged);
        }
예제 #3
0
        public void SearchComparingObjects()
        {
            var rex = new Dog
            {
                Name = "Rex"
            };

            var peter = new Owner
            {
                Name = "Peter",
                TopDog = rex
            };

            var george = new Owner
            {
                Name = "George",
                TopDog = rex
            };

            var sharo = new Dog
            {
                Name = "Sharo"
            };

            var ivan = new Owner
            {
                Name = "Ivan",
                TopDog = sharo
            };

            _realm.Write(() =>
            {
                _realm.Add(peter);
                _realm.Add(george);
                _realm.Add(ivan);
            });

            var rexOwners = _realm.All<Owner>().Where(o => o.TopDog == rex);
            Assert.That(rexOwners.Count(), Is.EqualTo(2));

            var sharoOwners = _realm.All<Owner>().Where(o => o.TopDog != rex);
            Assert.That(sharoOwners.Count(), Is.EqualTo(1));
            Assert.That(sharoOwners.Single().Name, Is.EqualTo("Ivan"));
        }