public void CovertToString()
 {
     Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Readonly), Is.EqualTo("read-only"));
     Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.ReadWrite), Is.EqualTo("read-write"));
     Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), Is.EqualTo("nonstrict-read-write"));
     Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Transactional), Is.EqualTo("transactional"));
 }
Ejemplo n.º 2
0
        public static Configuration CacheEntity(this Configuration cfg, Type type)

        {
            cfg.SetCacheConcurrencyStrategy(type.FullName,
                                            EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), "My.DomainModel");

            //foreach (var collection in ecc.Collections)
            //{
            //    configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
            //        EntityCacheUsageParser.ToString(collection.Value.Strategy), collection.Value.RegionName);
            //}
            return(cfg);
        }
        public void ConfigureCacheOfClass()
        {
            Configuration configure = new Configuration().Configure();

            configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);

            configure.EntityCache <EntityToCache>(ce =>
            {
                ce.Strategy   = EntityCacheUsage.NonStrictReadWrite;
                ce.RegionName = "MyRegion";
            });

            var pc = (RootClass)configure.GetClassMapping(typeof(EntityToCache));

            Assert.That(pc.CacheConcurrencyStrategy,
                        Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite)));
            Assert.That(pc.CacheRegionName, Is.EqualTo("MyRegion"));
        }
Ejemplo n.º 4
0
        public static Configuration EntityCache <TEntity>(this Configuration configuration, Action <IEntityCacheConfigurationProperties <TEntity> > entityCacheConfiguration)
            where TEntity : class
        {
            var ecc = new EntityCacheConfigurationProperties <TEntity>();

            entityCacheConfiguration(ecc);
            if (ecc.Strategy.HasValue)
            {
                configuration.SetCacheConcurrencyStrategy(typeof(TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value),
                                                          ecc.RegionName);
            }
            foreach (var collection in ecc.Collections)
            {
                configuration.SetCollectionCacheConcurrencyStrategy(collection.Key,
                                                                    EntityCacheUsageParser.ToString(collection.Value.Strategy),
                                                                    collection.Value.RegionName);
            }
            return(configuration);
        }
        public void ConfigureCacheOfCollection()
        {
            Configuration configure = new Configuration().Configure();

            configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);

            configure.EntityCache <EntityToCache>(ce =>
            {
                ce.Strategy   = EntityCacheUsage.NonStrictReadWrite;
                ce.RegionName = "MyRegion";
                ce.Collection(e => e.Elements, cc =>
                {
                    cc.RegionName = "MyCollectionRegion";
                    cc.Strategy   =
                        EntityCacheUsage.NonStrictReadWrite;
                });
            });

            Mapping.Collection pc = configure.GetCollectionMapping("NHibernate.Test.CfgTest.Loquacious.EntityToCache.Elements");
            Assert.That(pc.CacheConcurrencyStrategy,
                        Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite)));
            Assert.That(pc.CacheRegionName, Is.EqualTo("MyCollectionRegion"));
        }