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))); }
public static void MyClassInitialize(TestContext testContext) { var frameworkContext = new FrameworkContext( ConfigurationManager.GetSection("rebel.foundation") as IFoundationConfigurationSection); var persistenceConfig = ConfigurationManager.GetSection("hive.persistence") as HiveConfigurationSection; var localConfig = persistenceConfig.AvailableProviders.ReadWriters["rw-nhibernate-01"].GetLocalProviderConfig() as ProviderConfigurationSection; var nhSetup = new NHibernateConfigBuilder("rw-nhibernate-01", localConfig); var config = nhSetup.BuildConfiguration(); // Setup the local provider var dataContextFactory = new DataContextFactory(config.BuildSessionFactory()); var unitOfWorkFactory = new ReadWriteRepositoryUnitOfWorkFactory(dataContextFactory); var reader = new Reader(unitOfWorkFactory); var readWriter = new ReadWriter(unitOfWorkFactory); var uriMatch = new DefaultUriMatch() { MatchType = UriMatchElement.MatchTypes.Wildcard, Uri = "content://*/" }; // Setup hive's provider governor. Normally it takes two uow factories (read and read-write) but we can use the same for both here _mappingGroup = new DefaultPersistenceMappingGroup("rw-nhibernate-01", new[] { unitOfWorkFactory }, new[] { unitOfWorkFactory }, new[] { reader }, new[] { readWriter }, new[] { uriMatch }); }
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))); }
public NHibernateInMemoryRepository(IFrameworkContext fakeFrameworkContext, ISessionFactory sessionFactory = null, ISession sessionForTest = null) { using (DisposableTimer.TraceDuration<NHibernateInMemoryRepository>("Start setup", "End setup")) { if (sessionFactory == null && sessionForTest == null) { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); _sessionFactory = config.BuildSessionFactory(); SessionForTest = _sessionFactory.OpenSession(); // See http://stackoverflow.com/questions/4325800/testing-nhibernate-with-sqlite-no-such-table-schema-is-generated // and also http://nhforge.org/doc/nh/en/index.html#architecture-current-session // regarding contextual sessions and GetCurrentSession() // We pass in our own TextWriter because a bug in VS's testing framework means directly passing in Console.Out causes an ObjectDisposedException new SchemaExport(config).Execute(false, true, false, SessionForTest.Connection, _schemaWriter); } else { _sessionFactory = sessionFactory; SessionForTest = sessionForTest; } _dataContextFactory = new DataContextFactory(fakeFrameworkContext, SessionForTest, true); // Create reader ReadOnlyUnitOfWorkFactory = new ReadOnlyUnitOfWorkFactory(); _hiveReadProvider = new HiveReadProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), ReadOnlyUnitOfWorkFactory, null, _dataContextFactory)); // Create writer ReadWriteUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory(); _writeProvider = new HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "rw-unit-tester", new FakeHiveProviderBootstrapper(), ReadOnlyUnitOfWorkFactory, ReadWriteUnitOfWorkFactory, _dataContextFactory)); //setup nhibernate mappers var manualMapper = new ManualMapper(new NhLookupHelper(_dataContextFactory), _writeProvider); fakeFrameworkContext.TypeMappers.Add(new Lazy<AbstractTypeMapper, TypeMapperMetadata>(() => manualMapper, new TypeMapperMetadata(true))); // Create hive wrappers for the readers and writers var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { _hiveReadProvider }); var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { _writeProvider }); _hiveReadProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _hiveReadProvider }); _hiveReadWriteProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "rw-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, governorRWUowFactory, null), new[] { _writeProvider }); } }
public NHibernateInMemoryRepository(IFrameworkContext fakeFrameworkContext, ISessionFactory sessionFactory = null, ISession sessionForTest = null) { using (DisposableTimer.TraceDuration <NHibernateInMemoryRepository>("Start setup", "End setup")) { if (sessionFactory == null && sessionForTest == null) { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); _sessionFactory = config.BuildSessionFactory(); SessionForTest = _sessionFactory.OpenSession(); // See http://stackoverflow.com/questions/4325800/testing-nhibernate-with-sqlite-no-such-table-schema-is-generated // and also http://nhforge.org/doc/nh/en/index.html#architecture-current-session // regarding contextual sessions and GetCurrentSession() // We pass in our own TextWriter because a bug in VS's testing framework means directly passing in Console.Out causes an ObjectDisposedException new SchemaExport(config).Execute(false, true, false, SessionForTest.Connection, _schemaWriter); } else { _sessionFactory = sessionFactory; SessionForTest = sessionForTest; } _dataContextFactory = new DataContextFactory(fakeFrameworkContext, SessionForTest, true); // Create reader ReadOnlyUnitOfWorkFactory = new ReadOnlyUnitOfWorkFactory(); _hiveReadProvider = new HiveReadProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), ReadOnlyUnitOfWorkFactory, null, _dataContextFactory)); // Create writer ReadWriteUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory(); _writeProvider = new HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "rw-unit-tester", new FakeHiveProviderBootstrapper(), ReadOnlyUnitOfWorkFactory, ReadWriteUnitOfWorkFactory, _dataContextFactory)); //setup nhibernate mappers var manualMapper = new ManualMapper(new NhLookupHelper(_dataContextFactory), _writeProvider); fakeFrameworkContext.TypeMappers.Add(new Lazy <AbstractTypeMapper, TypeMapperMetadata>(() => manualMapper, new TypeMapperMetadata(true))); // Create hive wrappers for the readers and writers var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { _hiveReadProvider }); var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { _writeProvider }); _hiveReadProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(fakeFrameworkContext, "r-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _hiveReadProvider }); _hiveReadWriteProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(fakeFrameworkContext, "rw-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, governorRWUowFactory, null), new[] { _writeProvider }); } }
public void NHibernateBootstrapper_Completed() { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); var boot = new ProviderBootstrapper(config, new ProviderConfigurationSection() { ConnectionStringKey = "data source=:memory:", Driver = SupportedNHDrivers.SqlLite, SessionContext = "thread_static" }, new FakeFrameworkContext()); var status = boot.TryInstall(); Assert.AreEqual(InstallStatusType.Completed, status.StatusType); }
public void NHibernateBootstrapper_Completed() { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); var boot = new ProviderBootstrapper(config, new ProviderConfigurationSection() { ConnectionStringKey = "data source=:memory:", Driver = SupportedNHDrivers.SqlLite, SessionContext = "thread_static" }, new FakeFrameworkContext()); var status = boot.TryInstall(); Assert.AreEqual(InstallStatusType.Completed, status.StatusType); }
public IHiveManager GetHiveManager() { IFrameworkContext frameworkContext = GetFrameworkContext(); var providerMetadata = new ProviderMetadata("p__nhibernate", new Uri("content://"), true, false); var builder = new NHibernateConfigBuilder( ConfigurationManager.ConnectionStrings["DatabaseConnString"].ConnectionString, "unit-tester", SupportedNHDrivers.MsSql2008, "call", false, false); NhConfigurationCacheKey cacheKey; Configuration config = builder.BuildConfiguration(false, out cacheKey); var nhHelper = new NhFactoryHelper(config, null, false, false, frameworkContext); ProviderDependencyHelper dependencyHelper = new DependencyHelper(nhHelper, providerMetadata); var revisionRepositoryFactory = new RevisionRepositoryFactory(providerMetadata, frameworkContext, dependencyHelper); var revisionSchemaSessionFactory = new NullProviderRevisionRepositoryFactory<EntitySchema>(providerMetadata, frameworkContext); var schemaRepositoryFactory = new SchemaRepositoryFactory(providerMetadata, revisionSchemaSessionFactory, frameworkContext, dependencyHelper); var entityRepositoryFactory = new EntityRepositoryFactory(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, dependencyHelper); ProviderSetup singleWriter = GetWriterProvider(providerMetadata, frameworkContext, entityRepositoryFactory); ReadonlyProviderSetup singleReader = GetReaderProvider(providerMetadata, revisionRepositoryFactory, schemaRepositoryFactory, frameworkContext, dependencyHelper, config); Func<AbstractMappingEngine> addTypemapper = () => new ManualMapperv2(new NhLookupHelper(entityRepositoryFactory), providerMetadata); frameworkContext.TypeMappers.Add(new Lazy<AbstractMappingEngine, TypeMapperMetadata>(addTypemapper, new TypeMapperMetadata(true))); IHiveManager hive = new HiveManager(new[] { new ProviderMappingGroup( "test", new WildcardUriMatch("content://"), singleReader, singleWriter, frameworkContext) }, frameworkContext); return hive; }
public void NHibernateBootstrapper_Tried_And_Failed() { var localConfig = new ProviderConfigurationSection() { ConnectionStringKey = "This is an invalid conn string", Driver = SupportedNHDrivers.MsSql2008, SessionContext = "web" }; var builder = new NHibernateConfigBuilder(localConfig.ConnectionStringKey, "test", localConfig.Driver, "thread_static", false); var config = builder.BuildConfiguration(); var boot = new ProviderBootstrapper(config, localConfig, new FakeFrameworkContext()); var status = boot.TryInstall(); Assert.AreEqual(InstallStatusType.TriedAndFailed, status.StatusType); }
public void NHibernateBootstrapper_Tried_And_Failed() { var localConfig = new ProviderConfigurationSection() { ConnectionStringKey = "This is an invalid conn string", Driver = SupportedNHDrivers.MsSql2008, SessionContext = "web" }; var builder = new NHibernateConfigBuilder(localConfig.ConnectionStringKey, "test", localConfig.Driver, "thread_static", false); var config = builder.BuildConfiguration(); var boot = new ProviderBootstrapper(config, localConfig, new FakeFrameworkContext()); var status = boot.TryInstall(); Assert.AreEqual(InstallStatusType.TriedAndFailed, status.StatusType); }
private static HiveReadWriteProvider CreateReadWritter() { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); var sessionFactory = config.BuildSessionFactory(); _sessionForTest = sessionFactory.OpenSession(); var schemaWriter = new StringWriter(new StringBuilder()); new SchemaExport(config).Execute(false, true, false, _sessionForTest.Connection, schemaWriter); var fakeFrameworkContext = 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)); fakeFrameworkContext.TypeMappers.Add( new Lazy<AbstractTypeMapper, TypeMapperMetadata>( () => new ManualMapper(new NhLookupHelper(dataContextFactory), writer), new TypeMapperMetadata(true))); return writer; }
private static HiveReadWriteProvider CreateReadWritter() { var builder = new NHibernateConfigBuilder("data source=:memory:", "unit-tester", SupportedNHDrivers.SqlLite, "thread_static", false); var config = builder.BuildConfiguration(); var sessionFactory = config.BuildSessionFactory(); _sessionForTest = sessionFactory.OpenSession(); var schemaWriter = new StringWriter(new StringBuilder()); new SchemaExport(config).Execute(false, true, false, _sessionForTest.Connection, schemaWriter); var fakeFrameworkContext = 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)); fakeFrameworkContext.TypeMappers.Add( new Lazy <AbstractTypeMapper, TypeMapperMetadata>( () => new ManualMapper(new NhLookupHelper(dataContextFactory), writer), new TypeMapperMetadata(true))); return(writer); }
public static void MyClassInitialize(TestContext testContext) { var frameworkContext = new FrameworkContext( ConfigurationManager.GetSection("umbraco.foundation") as IFoundationConfigurationSection); var persistenceConfig = ConfigurationManager.GetSection("hive.persistence") as HiveConfigurationSection; var localConfig = persistenceConfig.AvailableProviders.ReadWriters["rw-nhibernate-01"].GetLocalProviderConfig() as ProviderConfigurationSection; var nhSetup = new NHibernateConfigBuilder("rw-nhibernate-01", localConfig); var config = nhSetup.BuildConfiguration(); // Setup the local provider var dataContextFactory = new DataContextFactory(config.BuildSessionFactory()); var unitOfWorkFactory = new ReadWriteRepositoryUnitOfWorkFactory(dataContextFactory); var reader = new Reader(unitOfWorkFactory); var readWriter = new ReadWriter(unitOfWorkFactory); var uriMatch = new DefaultUriMatch() {MatchType = UriMatchElement.MatchTypes.Wildcard, Uri = "content://*/"}; // Setup hive's provider governor. Normally it takes two uow factories (read and read-write) but we can use the same for both here _mappingGroup = new DefaultPersistenceMappingGroup("rw-nhibernate-01", new[] { unitOfWorkFactory }, new[] { unitOfWorkFactory }, new[] { reader }, new[] { readWriter }, new[]{uriMatch}); }