Exemplo n.º 1
0
        public void ClearCacheAllTest()
        {
            var sessionFactory = IoC.Resolve <ISessionFactory>();

            var item1 = new SimpleCacheEntity
            {
                Name = "Query Cache Test #1"
            };
            var item2 = new SimpleEntity
            {
                Name = "Query Cache Test #2"
            };

            Repository.Data.Save(item1);
            Repository.Data.Save(item2);

            var cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType());

            Assert.NotNull(cachedEntity1);
            var cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType());

            Assert.NotNull(cachedEntity2);

            var query       = Repository.Data.Get <SimpleCacheEntity>().Where(x => x.Name.Contains("Query Cache Test"));
            var queryResult = query.All();

            Assert.NotEmpty(queryResult);
            sessionFactory.Statistics.Clear();
            var cachedQueryResult = query.All();

            Assert.NotEmpty(cachedQueryResult);
            Assert.Equal(0, sessionFactory.Statistics.EntityLoadCount);

            Repository.Data.Cache.Clear();

            cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType());
            Assert.Null(cachedEntity1);
            cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType());
            Assert.Null(cachedEntity2);
            sessionFactory.Statistics.Clear();
            var retrievedQueryResult = query.All();

            Assert.NotEmpty(retrievedQueryResult);
            Assert.True(sessionFactory.Statistics.EntityLoadCount > 0);
        }
Exemplo n.º 2
0
        public void ClearCacheForEntityTypeTest()
        {
            var item1 = new SimpleCacheEntity
            {
                Name = "Query Cache Test #1"
            };
            var item2 = new SimpleCacheEntity
            {
                Name = "Query Cache Test #2"
            };
            var item3 = new SimpleEntity
            {
                Name = "Query Cache Test #3"
            };

            Repository.Data.Save(item1);
            Repository.Data.Save(item2);
            Repository.Data.Save(item3);

            var cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType());

            Assert.NotNull(cachedEntity1);
            var cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType());

            Assert.NotNull(cachedEntity2);
            var cachedEntity3 = GetCachedObjectDirectly(item3.Id, item3.GetType());

            Assert.NotNull(cachedEntity3);

            Repository.Data.Cache.Clear(typeof(SimpleCacheEntity));

            cachedEntity1 = GetCachedObjectDirectly(item1.Id, item1.GetType());
            Assert.Null(cachedEntity1);
            cachedEntity2 = GetCachedObjectDirectly(item2.Id, item2.GetType());
            Assert.Null(cachedEntity2);
            cachedEntity3 = GetCachedObjectDirectly(item3.Id, item3.GetType());
            Assert.NotNull(cachedEntity3);
        }
Exemplo n.º 3
0
        // TODO: Use a value generator to handle this automatically
        private void SetPartitionId(SimpleEntity entity, CrossStoreContext context)
        {
            var property = context.Model.GetEntityType(entity.GetType()).GetProperty(SimpleEntity.ShadowPartitionIdName);

            context.Entry(entity).GetService()[property] = "Partition";
        }
Exemplo n.º 4
0
        // TODO: Use a value generator to handle this automatically
        private void SetPartitionId(SimpleEntity entity, CrossStoreContext context)
        {
            var property = context.Model.FindEntityType(entity.GetType()).FindProperty(SimpleEntity.ShadowPartitionIdName);

            context.Entry(entity).GetInfrastructure()[property] = "Partition";
        }
Exemplo n.º 5
0
        // TODO: Use a value generator to handle this automatically
        private void SetPartitionId(SimpleEntity entity, CrossStoreContext context)
        {
            var property = context.Model.GetEntityType(entity.GetType()).GetProperty(SimpleEntity.ShadowPartitionIdName);

            ((IAccessor <InternalEntityEntry>)context.Entry(entity)).Service[property] = "Partition";
        }