Example #1
0
        public void TestIdentityColumns(bool batchMode)
        {
            _app = new IdentityTestsEntityApp();
            Startup.ActivateApp(_app);
            //if(Startup.ServerType == Data.Driver.DbServerType.SQLite)
            DeleteAllData();
            // We create session this way to set the batch mode flag
            var            ctx     = new OperationContext(_app);
            IEntitySession session = new EntitySession(ctx,
                                                       options: batchMode ? EntitySessionOptions.None : EntitySessionOptions.DisableBatchMode);
            var john = session.NewEntity <IPerson>();

            john.Name = "John S";
            //john.Name = "Джон Ш"; //Russian
            var car1 = session.NewEntity <ICar>();

            car1.Model   = "Beatle";
            car1.Owner   = john;
            car1.CoOwner = null;
            var car2 = session.NewEntity <ICar>();

            car2.Model = "Explorer";
            car2.Owner = john;
            Assert.IsTrue(car1.Id < 0, "Car ID is expected to be <0 before saving.");
            session.SaveChanges();
            //Check that Identity values immediately changed to actual positive values loaded from database
            Assert.IsTrue(john.Id > 0, "Invalid person ID - expected positive value.");
            Assert.IsTrue(car1.Id > 0, "Invalid car1 ID - expected positive value.");
            Assert.IsTrue(car2.Id > 0, "Invalid car2 ID - expected positive value.");

            //Start new session, load all and check that IDs and relationships are correct
            session = _app.OpenSession();
            john    = session.EntitySet <IPerson>().Where(p => p.Name == "John S").Single();
            var cars = session.GetEntities <ICar>().ToList();

            car1 = cars[0];
            car2 = cars[1];
            Assert.IsTrue(john.Id > 0 && car1.Id > 0 && car2.Id > 0, "IDs expected to become > 0 after saving.");
            Assert.IsTrue(car1.Owner == john, "Owner expected to be John");
            Assert.IsTrue(car2.Owner == john, "Owner expected to be John");

            // Testing list.Contains with long (bigint) values, used to fail for SQL Server
            var longArray = new long[] { long.MaxValue - 10, long.MaxValue - 9, long.MaxValue - 8 };
            // we just test that this does not blow up
            var someCars = session.EntitySet <ICar>().Where(c => longArray.Contains(c.Id)).ToList();
            var sql      = session.GetLastCommand().CommandText;

            Assert.AreEqual(0, someCars.Count);
        }//method
Example #2
0
        public void RunTest(bool batchMode)
        {
            _app = new IdentityRefTestEntityApp();
            Startup.ActivateApp(_app);
            //if(Startup.ServerType == Data.Driver.DbServerType.SQLite)
            DeleteAllData();
            // We create session this way to set the batch mode flag
            var            ctx     = new OperationContext(_app);
            IEntitySession session = new EntitySession(ctx,
                                                       options: batchMode ? EntitySessionOptions.None : EntitySessionOptions.DisableBatchMode);

            var john   = session.NewUser("john");
            var post1  = john.NewPost("john post 1", 1);
            var post2  = john.NewPost("john post 2", 2);
            var post3  = john.NewPost("john post 3", 3);
            var ben    = session.NewUser("ben");
            var post1b = ben.NewPost("ben post 1", 1);
            var post2b = ben.NewPost("ben post 2", 2);
            var post3b = ben.NewPost("ben post 3", 3);

            session.SaveChanges();
            //Check that Identity values immediately changed to actual positive values loaded from database
            Assert.IsTrue(post1.OrderId > 0, "Invalid OrderID - expected positive value.");
            Assert.IsTrue(post2.OrderId > 0, "Invalid OrderID - expected positive value.");
            Assert.IsTrue(post3.OrderId > 0, "Invalid OrderID - expected positive value.");

            //Start new session, load all and check that IDs and relationships are correct
            session = _app.OpenSession();
            var posts = session.EntitySet <IUserPost>().ToList();

            foreach (var post in posts)
            {
                Assert.IsTrue(post.OrderId > 0);
            }
        }//method
Example #3
0
        public void TestIdentityColumns(bool batchMode)
        {
            _app = new IdentityTestsEntityApp();
            Startup.ActivateApp(_app);
            //if(Startup.ServerType == Data.Driver.DbServerType.SQLite)
            DeleteAllData();
            // We create session this way to set the batch mode flag
            var            ctx     = new OperationContext(_app);
            IEntitySession session = new EntitySession(ctx,
                                                       options: batchMode ? EntitySessionOptions.None : EntitySessionOptions.DisableBatchMode);
            var john = session.NewEntity <IPerson>();

            john.Name = "John S";
            var car1 = session.NewEntity <ICar>();

            car1.Model   = "Beatle";
            car1.Owner   = john;
            car1.CoOwner = null;
            var car2 = session.NewEntity <ICar>();

            car2.Model = "Explorer";
            car2.Owner = john;
            Assert.IsTrue(car1.Id < 0, "Car ID is expected to be <0 before saving.");
            session.SaveChanges();
            //Check that Identity values immediately changed to actual positive values loaded from database
            Assert.IsTrue(john.Id > 0, "Invalid person ID - expected positive value.");
            Assert.IsTrue(car1.Id > 0, "Invalid car1 ID - expected positive value.");
            Assert.IsTrue(car2.Id > 0, "Invalid car2 ID - expected positive value.");

            //Start new session, load all and check that IDs and relationships are correct
            session = _app.OpenSession();
            john    = session.EntitySet <IPerson>().Where(p => p.Name == "John S").Single();
            var cars = session.GetEntities <ICar>().ToList();

            car1 = cars[0];
            car2 = cars[1];
            Assert.IsTrue(john.Id > 0 && car1.Id > 0 && car2.Id > 0, "IDs expected to become > 0 after saving.");
            Assert.IsTrue(car1.Owner == john, "Owner expected to be John");
            Assert.IsTrue(car2.Owner == john, "Owner expected to be John");
        }//method