示例#1
0
        public XmlStoreHiveTests()
        {
            using (DisposableTimer.TraceDuration<XmlStoreHiveTests>("Start setup", "End setup"))
            {
                // Create reader
                var xmlPath =
                    Path.Combine(
                        Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Substring("file:\\\\".Length + 1)),
                        "App_Data\\rebel.config");

                _fakeFrameworkContext = new FakeFrameworkContext();

                _dataContextFactory = new DataContextFactory(xmlPath);
                _readOnlyUnitOfWorkFactory = new ReadOnlyUnitOfWorkFactory();
                _directHiveReadProvider = 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(), null, _readWriteUnitOfWorkFactory, _dataContextFactory));



                // Create hive wrappers for the readers and writers
                var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { _directHiveReadProvider });

                var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { _writeProvider });

                _hiveReadProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-tester", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _directHiveReadProvider });
                _hiveReadWriteProviderViaGovernor = new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "rw-unit-tester", new FakeHiveProviderBootstrapper(), null, 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 });
            }
        }
        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 CachingProviderTests()
        {
            _fakeFrameworkContext = new FakeFrameworkContext();

            var inMemory = new NHibernateInMemoryRepository(_fakeFrameworkContext);

            var dataContextFactory = new DataContextFactory();
            var readWriteUnitOfWorkFactory = new ReadWriteUnitOfWorkFactory();
            var directReaderProvider = new HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-tester",
                                                                  new FakeHiveProviderBootstrapper(),
                                                                  readWriteUnitOfWorkFactory, readWriteUnitOfWorkFactory,
                                                                  dataContextFactory));
            var directReadWriteProvider = directReaderProvider;

            // Create hive wrappers for the readers and writers
            var governorRUowFactory = new ReadOnlyUnitOfWorkFactoryWrapper(new[] { directReaderProvider, inMemory.HiveReadProvider });
            var governorRWUowFactory = new ReadWriteUnitOfWorkFactoryWrapper(new[] { directReadWriteProvider, inMemory.ReadWriteProvider });

            _readerProviderViaHiveGovernor = _directReaderProvider =
                new Framework.Hive.PersistenceGovernor.HiveReadProvider(new HiveProviderSetup(_fakeFrameworkContext, "r-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, null, null), new[] { _directReaderProvider });
            _readWriteProviderViaHiveGovernor = _directReadWriteProvider =
                new Framework.Hive.PersistenceGovernor.HiveReadWriteProvider(new HiveProviderSetup(_fakeFrameworkContext, "rw-unit-wrapper", new FakeHiveProviderBootstrapper(), governorRUowFactory, governorRWUowFactory, null), new[] { _directReadWriteProvider });
        }