public void ClearEFGlobalCacheBeforeEachTest()
        {
            new EFCacheServiceProvider().ClearAllCachedEntries();

            using (var context = new SampleContext())
            {
                var user = new User
                {
                    Name = string.Format("User {0}", _rnd.Next())
                };
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
        public void TestInsertingDataToOtherTablesShouldNotInvalidateTheCacheDependencyAutomatically()
        {
            using (var context = new SampleContext())
            {
                var isActive = true;
                var name = "Product1";

                var databaseLog = new StringBuilder();
                context.Database.Log = commandLine =>
                {
                    databaseLog.AppendLine(commandLine);
                    Trace.Write(commandLine);
                };

                Trace.WriteLine("1st query, reading from db (it dependes on/includes the Tags table)");
                var debugInfo1 = new EFCacheDebugInfo();
                var list1 = context.Products.Include(x => x.Tags)
                    .OrderBy(product => product.ProductNumber)
                    .Where(product => product.IsActive == isActive && product.ProductName == name)
                    .Cacheable(debugInfo1)
                    .ToList();
                var sqlCommands = databaseLog.ToString().Trim();
                Assert.AreEqual(false, string.IsNullOrWhiteSpace(sqlCommands));
                Assert.AreEqual(false, debugInfo1.IsCacheHit);
                Assert.IsTrue(list1.Any());


                Trace.WriteLine("same query, reading from 2nd level cache.");
                databaseLog.Clear();
                var debugInfo2 = new EFCacheDebugInfo();
                var list2 = context.Products.Include(x => x.Tags)
                    .OrderBy(product => product.ProductNumber)
                    .Where(product => product.IsActive == isActive && product.ProductName == name)
                    .Cacheable(debugInfo2)
                    .ToList();
                sqlCommands = databaseLog.ToString().Trim();
                Assert.AreEqual(true, string.IsNullOrWhiteSpace(sqlCommands));
                Assert.AreEqual(true, debugInfo2.IsCacheHit);
                Assert.IsTrue(list2.Any());


                Trace.WriteLine(
                    "inserting data into a *non-related* table, shouldn't invalidate the cache on SaveChanges.");
                var rnd = new Random();
                var user = new User
                {
                    Name = "User " + rnd.Next()
                };
                context.Users.Add(user);
                context.SaveChanges();


                Trace.WriteLine("same query after insert, reading from 2nd level cache.");
                databaseLog.Clear();
                var debugInfo3 = new EFCacheDebugInfo();
                var list3 = context.Products.Include(x => x.Tags)
                    .OrderBy(product => product.ProductNumber)
                    .Where(product => product.IsActive == isActive && product.ProductName == name)
                    .Cacheable(debugInfo3)
                    .ToList();
                sqlCommands = databaseLog.ToString().Trim();
                Assert.AreEqual(true, string.IsNullOrWhiteSpace(sqlCommands));
                Assert.AreEqual(true, debugInfo3.IsCacheHit);
                Assert.IsTrue(list3.Any());
            }
        }