Esempio n. 1
0
        public void BatchSaveChanges_ParentAndChild_ChildModified()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);

            using (var ctx = new TestContext())
            {
                var left = ctx.Association_OneToMany_Lefts.Add(new Association_OneToMany_Left()
                {
                    ColumnInt = 1
                });
                var right = ctx.Association_OneToMany_Rights.Add(new Association_OneToMany_Right()
                {
                    ColumnInt = 1
                });

                left.Rights = new List <Association_OneToMany_Right>();
                left.Rights.Add(right);

                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                QueryCacheManager.IsAutoExpireCacheEnabled = true;

                // BEFORE
                var before = ctx.Association_OneToMany_Lefts.Include("Rights").FromCache().ToList();

                ctx.Association_OneToMany_Rights.ToList().ForEach(x => x.ColumnInt++);
                ctx.BatchSaveChanges();

                var after = ctx.Association_OneToMany_Lefts.Include("Rights").FromCache().ToList();

                QueryCacheManager.ExpireAll();
                QueryCacheManager.IsAutoExpireCacheEnabled = false;

                // TEST: The item count are equal
                Assert.AreEqual(1, before.First().ColumnInt);
                Assert.AreEqual(1, before.First().Rights.First().ColumnInt);

                // TEST: The cache count are equal
                Assert.AreEqual(1, after.First().ColumnInt);
                Assert.AreEqual(2, after.First().Rights.First().ColumnInt);
            }
        }
Esempio n. 2
0
        public void BatchSaveChanges_Parent_Disabled()
        {
            TestContext.DeleteAll(x => x.Association_OneToMany_Rights);
            TestContext.DeleteAll(x => x.Association_OneToMany_Lefts);

            using (var ctx = new TestContext())
            {
                var left = ctx.Association_OneToMany_Lefts.Add(new Association_OneToMany_Left()
                {
                    ColumnInt = 1
                });

                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                // BEFORE
                var before = ctx.Association_OneToMany_Lefts.Include("Rights").FromCache().ToList();

                ctx.Association_OneToMany_Lefts.ToList().ForEach(x => x.ColumnInt++);
                ctx.BatchSaveChanges();

                var after = ctx.Association_OneToMany_Lefts.Include("Rights").FromCache().ToList();

                QueryCacheManager.ExpireAll();

                // TEST: The item count are equal
                Assert.AreEqual(1, before.First().ColumnInt);
                Assert.AreEqual(0, before.First().Rights.Count);

                // TEST: The cache count are equal
                Assert.AreEqual(1, after.First().ColumnInt);
                Assert.AreEqual(0, after.First().Rights.Count);
            }
        }