private NHibernateTestContext CreateContext()
        {
            INHibernateConfigurator configurator = CreateNhConfigurator();
            var context = new NHibernateTestContext(configurator, ConnectionInfo, DatabaseEngine);

            Debug.Print(String.Format("Created another UnitOfWorkContext for: {0}", context));
            return(context);
        }
Beispiel #2
0
        /// <summary>
        /// Throw away all <see cref="NHibernateTestContext"/> objects within <see cref="Contexts"/>
        /// and referenced by <see cref="CurrentContext"/>. WARNING: Subsequent calls to  <see
        /// cref="Initialize"/> will now take considerably longer as the persistent framework
        /// will be initialised a fresh.
        /// </summary>
        /// <remarks>
        /// This method should be used vary sparingly. It is highly unlikely that you will need to
        /// call this method between every test.
        /// </remarks>
        public static void DisposeAndRemoveAllUoWTestContexts()
        {
            foreach (NHibernateTestContext context in Contexts)
            {
                context.Dispose();
            }

            CurrentContext = null;
            Contexts.Clear();
        }
        protected internal NHibernateTestContext GetUnitOfWorkTestContext()
        {
            NHibernateTestContext context =
                NHibernateTestContext.Contexts.Find(x => x.DatabaseEngine == DatabaseEngine &&
                                                    x.ConnectionInfo == ConnectionInfo);

            if (context == null)
            {
                context = CreateContext();
                NHibernateTestContext.Contexts.Add(context);
            }
            return(context);
        }
        private void InternalComplete()
        {
            ConnectionInfo = ConnectionInfo ?? new DbConnectionInfo();
            if (String.IsNullOrEmpty(ConnectionInfo.DatabaseName))
            {
                string databaseName = DeriveDatabaseNameFrom(DatabaseEngine,
                                                             MappingInfo.AssembliesWithEmbeddedMapping.
                                                             ElementAt(0));
                ConnectionInfo.DatabaseName = databaseName;
            }
            NHibernateTestContext context = GetUnitOfWorkTestContext();

            if (!Equals(context, NHibernateTestContext.CurrentContext))
            {
                context.InitializeSessionFactory();
                AfterInit(context.SessionFactory);
            }
            NHibernateTestContext.CurrentContext = context;
            Debug.Print(String.Format("CurrentContext is: {0}", NHibernateTestContext.CurrentContext));
        }