Ejemplo n.º 1
0
        public void MultiTableDelete()
        {
            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);
                    ExtendedBike.Load(10).MarkForDelete();
                    tran.Commit();
                }

                try
                {
                    using (SoodaTransaction tran = new SoodaTransaction())
                    {
                        tran.RegisterDataSource(testDataSource);
                        ExtendedBike b = ExtendedBike.Load(10);
                    }
                    Assert.Fail("Object not deleted!");
                }
                catch (SoodaObjectNotFoundException)
                {
                    Assert.IsTrue(true);
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadTest6()
        {
            Console.WriteLine("Test6a");
            try
            {
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    ExtendedBike ebk = (ExtendedBike)Vehicle.Load(10);

                    Console.WriteLine(ebk.ExtendedBikeInfo);
                }
            }
            finally
            {
                Console.WriteLine("Test6b");
            }
        }
Ejemplo n.º 3
0
        public void LongTest()
        {
            // run multiple Sooda transactions in a single SQL transaction
            // this is achieved by a hacked SqlDataSource which ignores
            // Close(), Commit() requests

            using (TestSqlDataSource testDataSource = new TestSqlDataSource("default"))
            {
                testDataSource.Open();

                int ebKey;
                int bikeKey;
                int gvKey;

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);

                    Vehicle v = new Bike();
                    Assert.AreEqual(v.Type, 2);
                    ((Bike)v).TwoWheels = 1;

                    ExtendedBike eb = new ExtendedBike();
                    Assert.AreEqual(eb.Type, 7);
                    eb.TwoWheels        = 1;
                    eb.ExtendedBikeInfo = "some info here";
                    ebKey   = eb.Id;
                    bikeKey = v.Id;

                    Contact.Mary.Bikes.Add((Bike)v);
                    Contact.Mary.Bikes.Add(eb);

                    Contact.Mary.Vehicles.Add(v);
                    Contact.Mary.Vehicles.Add(eb);

                    v     = new Bike();
                    gvKey = v.Id;
                    Contact.Mary.Vehicles.Add(v);

                    tran.Commit();
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(Vehicle.GetRef(gvKey)));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(Contact.Mary.Vehicles.Contains(v2));

                    Contact.Mary.Vehicles.Remove(v1);
                    Contact.Mary.Vehicles.Remove(v2);

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    Contact.Mary.Bikes.Remove((Bike)v1);

                    try
                    {
                        Vehicle v3 = ExtendedBike.GetRef(bikeKey);
                        Assert.Fail("Vehicle v3 = ExtendedBike.GetRef(bikeKey); should fail here.");
                    }
                    catch (SoodaObjectNotFoundException)
                    {
                        Console.WriteLine("Got exception as expected");
                    }

                    tran.Commit();
                }
                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(testDataSource);

                    Vehicle v1 = Vehicle.GetRef(ebKey);
                    Assert.IsTrue(v1 is ExtendedBike);

                    Vehicle v2 = Vehicle.GetRef(bikeKey);
                    Assert.IsTrue(v2.GetType() == typeof(Bike));

                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v1));
                    Assert.IsTrue(!Contact.Mary.Vehicles.Contains(v2));

                    Assert.IsTrue(!Contact.Mary.Bikes.Contains((Bike)v1));
                    Assert.IsTrue(Contact.Mary.Bikes.Contains((Bike)v2));

                    tran.Commit();
                }
            }
        }