Exemplo n.º 1
0
        public virtual void TestUpdate()
        {
            DeleteBase(NewbieOdb);

            using (var odb = Open(NewbieOdb))
            {
                var marcelo = new Driver("marcelo");
                var car = new Car("car1", 4, "ranger", marcelo);
                odb.Store(car);

                var query = odb.Query<Car>();
                query.Descend("Driver.Name").Constrain((object) "marcelo").Equal();
                var newCar = query.Execute<Car>().GetFirst();

                newCar.Driver = new Driver("dani");
                odb.Store(newCar);
            }

            using (var odb = Open(NewbieOdb))
            {
                var query = odb.Query<Car>();
                query.Descend("Driver.Name").Constrain((object) "dani").Equal();
                AssertEquals(1, query.Execute<Car>().Count);
            }

            DeleteBase(NewbieOdb);
        }
Exemplo n.º 2
0
        public virtual void TestInsert()
        {
            DeleteBase(NewbieOdb);

            // open is called on NewbieTest
            using (var odb = Open(NewbieOdb))
            {
                var marcelo = new Driver("marcelo");
                var car = new Car("car1", 4, "ranger", marcelo);
                var car1 = new Car("car2", 2, "porche");
                var car2 = new Car("car3", 2, "fusca");
                var car3 = new Car("car4", 4, "opala");
                var car4 = new Car("car5", 4, "vectra", marcelo);

                // insert 5 car's
                odb.Store(car);
                odb.Store(car1);
                odb.Store(car2);
                odb.Store(car3);
                odb.Store(car4);

                // find for all car objects
                var query1 = odb.Query<Car>();
                var cars = query1.Execute<Car>();
                AssertEquals("The objects weren't added correctly", 5, cars.Count);

                // find for a specific car object
                var query = odb.Query<Car>();
                query.Descend("Name").Constrain((object) "car1").Equal();
                cars = query.Execute<Car>();
                AssertEquals("The objects couldn't be found correctly", 1, cars.Count);

                // find for a specific composition
                query = odb.Query<Car>();
                query.Descend("Driver.Name").Constrain((object) "marcelo").Equal();
                cars = query.Execute<Car>();
                AssertEquals("The objects couldn't be found correctly", 2, cars.Count);
            }

            DeleteBase(NewbieOdb);
        }