Пример #1
0
        protected void RunEventTests()
        {
            var realmService    = RealmService.GetInstance <Models.Person>();
            var realmServiceTwo = RealmService.GetInstance <Models.Person>();

            realmService.WriteFinished += (sender, args) =>
            {
                var msg = "Woohoo!";
            };

            realmServiceTwo.WriteFinished += (sender, args) =>
            {
                var msg = "Woohoo!";
            };

            realmService.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });

            realmServiceTwo.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });
        }
Пример #2
0
        protected void RunServiceTests()
        {
            var realmService = RealmService.GetInstance <Models.Person>();

            realmService.Write(() =>
            {
                realmService.Add(new Person {
                    Name = "Greg"
                });
                realmService.Add(new Person {
                    Name = "Jim"
                });
                realmService.Add(new Person {
                    Name = "Bob"
                });
            });

            // OR

            var personsRealm = new PersonsRealmService();

            personsRealm.Write(() =>
            {
                personsRealm.Add(new Person {
                    Name = "Jan"
                });
                personsRealm.Add(new Person {
                    Name = "June"
                });
                personsRealm.Add(new Person {
                    Name = "Jinny"
                });
            });

            var persons = personsRealm.GetAll().ToList();

            personsRealm.Write(() =>
            {
                personsRealm.RemoveAll();
            });
        }
Пример #3
0
        public void RemoveTests()
        {
            // No Primary Key
            var countriesService = RealmService.GetInstance <Models.Country>();

            countriesService.Write(() =>
            {
                countriesService.RemoveAll();
                countriesService.Add(new Country {
                    Name = "Canada"
                });
            });
            var country1 = countriesService.Get(x => x.Name == "Canada");

            Assert.That(country1, Is.Not.Null);
            countriesService.Write(() =>
            {
                countriesService.Remove(countriesService.Get(x => x.Name == "Canada"));
            });
            country1 = countriesService.Get(x => x.Name == "Canada");
            Assert.That(country1, Is.Null);

            // Primary Key, String
            var paintingsService = RealmService.GetInstance <Models.Painting>();

            paintingsService.Write(() =>
            {
                paintingsService.RemoveAll();
                paintingsService.AddOrUpdate(new Painting {
                    Id = "One", Name = "Gregory"
                });
                paintingsService.AddOrUpdate(new Painting {
                    Id = "Two", Name = "Bertha"
                });
            });
            var painting1 = paintingsService.Find("One");
            var painting2 = paintingsService.Find("Two");

            Assert.That(painting1, Is.Not.Null);
            Assert.That(painting2, Is.Not.Null);
            paintingsService.Write(() =>
            {
                paintingsService.Remove("One");
                paintingsService.Remove("Two");
            });
            painting1 = paintingsService.Find("One");
            painting2 = paintingsService.Find("Two");
            Assert.That(painting1, Is.Null);
            Assert.That(painting2, Is.Null);
            paintingsService.Write(() =>
            {
                paintingsService.RemoveAll();
            });

            // Primary Key, AutoIncrement Disabled
            var animalsService = RealmService.GetInstance <Models.Animal>();

            animalsService.Write(() =>
            {
                animalsService.RemoveAll();
                animalsService.Add(new Animal {
                    Id = 3, Name = "Bertha"
                });
            });
            var animal1 = animalsService.Get(x => x.Name == "Bertha");

            Assert.That(animal1, Is.Not.Null);
            animalsService.Write(() =>
            {
                animalsService.Remove(animalsService.Get(x => x.Name == "Bertha"));
            });
            animal1 = animalsService.Get(x => x.Name == "Bertha");
            Assert.That(animal1, Is.Null);
            animalsService.Write(() =>
            {
                animalsService.RemoveAll();
            });

            // Primary Key, AutoIncrement Enabled
            var personsService = RealmService.GetInstance <Models.Person>();

            personsService.Write(() =>
            {
                personsService.RemoveAll();
                personsService.Add(new Person {
                    Name = "Gregory"
                });
            });
            var person1 = personsService.Get(x => x.Name == "Gregory");

            Assert.That(person1, Is.Not.Null);
            personsService.Write(() =>
            {
                personsService.Remove(personsService.Get(x => x.Name == "Gregory"));
            });
            person1 = personsService.Get(x => x.Name == "Gregory");
            Assert.That(person1, Is.Null);
            personsService.Write(() =>
            {
                personsService.RemoveAll();
            });
        }