Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="providerMetadata"></param>
 /// <param name="frameworkContext"></param>
 /// <param name="dependencyHelper"></param>
 public RevisionRepositoryFactory(
     ProviderMetadata providerMetadata,
     IFrameworkContext frameworkContext,
     ProviderDependencyHelper dependencyHelper)
     : base(providerMetadata, frameworkContext, dependencyHelper)
 {
 }
        //public EntityRepositoryFactory(ProviderMetadata providerMetadata,
        //    ProviderRevisionSessionFactory<TypedEntity> revisionRepositoryFactory,
        //    ProviderSchemaSessionFactory schemaRepositoryFactory,
        //    IFrameworkContext frameworkContext, global::NHibernate.Cfg.Configuration nhConfig)
        //    : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext)
        //{
        //    Helper = new NhFactoryHelper(nhConfig, null, false, false, frameworkContext);
        //}

        public EntityRepositoryFactory(ProviderMetadata providerMetadata,
                                       AbstractRevisionRepositoryFactory <TypedEntity> revisionRepositoryFactory,
                                       AbstractSchemaRepositoryFactory schemaRepositoryFactory,
                                       IFrameworkContext frameworkContext, ProviderDependencyHelper dependencyHelper)
            : base(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, dependencyHelper)
        {
        }
        public NhibernateTestSetupHelper(string dataSource, SupportedNHDrivers supportedNhDrivers, string sessionContext, bool executeSchema, FakeFrameworkContext frameworkContext = null, bool useNhProf = false, bool outputMappings = false, bool leaveSessionOpenOnRepositoryDispose = true, bool useSingleSessionForTest = true)
        {
            _useNhProfiler = useNhProf;
            var builder = new NHibernateConfigBuilder(dataSource, "unit-tester", supportedNhDrivers, sessionContext, outputMappings, _useNhProfiler);
            NhConfigurationCacheKey cacheKey;

            Config         = builder.BuildConfiguration(false, out cacheKey, "on_close");
            SessionFactory = SessionFactoryCache.GetOrAdd(cacheKey, key => Config.BuildSessionFactory());
            SessionForTest = SessionFactory.OpenSession();
            var schemaWriter = new StringWriter(new StringBuilder());

            if (executeSchema)
            {
                new SchemaExport(Config).Execute(false, true, false, SessionForTest.Connection, schemaWriter);
            }

            FakeFrameworkContext = frameworkContext ?? new FakeFrameworkContext();

            //var dataContextFactory = new DataContextFactory(fakeFrameworkContext, SessionForTest, true);

            //var readWriteRepositoryUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory();
            //var writer = new HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), null, readWriteRepositoryUnitOfWorkFactory, dataContextFactory));

            var providerMetadata = new ProviderMetadata("r-unit-tester", new Uri("tester://"), true, false);
            //var schemaRepositoryFactory = new NullProviderSchemaRepositoryFactory(providerMetadata, fakeFrameworkContext);
            //var revisionRepositoryFactory = new NullProviderRevisionRepositoryFactory<TypedEntity>(providerMetadata, fakeFrameworkContext);

            var revisionSchemaSessionFactory = new NullProviderRevisionRepositoryFactory <EntitySchema>(providerMetadata,
                                                                                                        FakeFrameworkContext);

            ProviderDependencyHelper helper = null;

            if (!useSingleSessionForTest)
            {
                helper = new DependencyHelper(new NhFactoryHelper(Config, null, leaveSessionOpenOnRepositoryDispose, false, FakeFrameworkContext), providerMetadata);
            }
            else
            {
                helper = new DependencyHelper(new NhFactoryHelper(null, SessionForTest, leaveSessionOpenOnRepositoryDispose, false, FakeFrameworkContext), providerMetadata);
            }

            var revisionRepositoryFactory = new RevisionRepositoryFactory(providerMetadata, FakeFrameworkContext, helper);

            var schemaRepositoryFactory = new SchemaRepositoryFactory(providerMetadata, revisionSchemaSessionFactory,
                                                                      FakeFrameworkContext, helper);

            var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory,
                                                                      schemaRepositoryFactory, FakeFrameworkContext,
                                                                      helper);

            var readUnitFactory = new ReadonlyProviderUnitFactory(entityRepositoryFactory);
            var unitFactory     = new ProviderUnitFactory(entityRepositoryFactory);

            ProviderSetup         = new ProviderSetup(unitFactory, providerMetadata, FakeFrameworkContext, null, 0);
            ReadonlyProviderSetup = new ReadonlyProviderSetup(readUnitFactory, providerMetadata, FakeFrameworkContext, null, 0);

            Func <AbstractMappingEngine> addTypemapper = () => new ManualMapperv2(new NhLookupHelper(entityRepositoryFactory), providerMetadata);

            FakeFrameworkContext.TypeMappers.Add(new Lazy <AbstractMappingEngine, TypeMapperMetadata>(addTypemapper, new TypeMapperMetadata(true)));
        }