protected internal UnitOfWorkTestContext GetUnitOfWorkTestContext() { Predicate <UnitOfWorkTestContext> criteria; if (_container == null) { criteria = ctx => ctx.ContainerConfigPath == StringOrEmpty(_containerConfigPath) && ctx.DatabaseEngine == _root.DatabaseEngine && ctx.DatabaseName == _root.DatabaseName; } else { criteria = ctx => ctx.Container == _container && ctx.DatabaseEngine == _root.DatabaseEngine && ctx.DatabaseName == _root.DatabaseName; } var context = Contexts.Find(criteria); if (context == null) { var dbStrategy = UnitOfWorkTestContextDbStrategy.For(_root.DatabaseEngine, _root.DatabaseName, _root.NHibernateConfigurationProperties); context = (_container != null) ? UnitOfWorkTestContext.FluentFor(_container, dbStrategy, _root.MappingInfo, _root.ConfigAction, _root.Conventions) : UnitOfWorkTestContext.FluentFor(_containerConfigPath, dbStrategy, _root.MappingInfo, _root.ConfigAction, _root.Conventions); Contexts.Add(context); if (IsDebugEnabled) { log.Debug("Create another UnitOfWorkContext for: [{0}]", context); } } return(context); }
/// <summary> /// Throw away all <see cref="UnitOfWorkTestContext"/> objects within <see cref="Contexts"/> /// and referenced by <see cref="CurrentContext"/>. WARNING: Subsequent calls to <see cref="InitializeNHibernateAndIoC(string,DatabaseEngine,string,NFramework.Data.NHibernateEx.ForTesting.MappingInfo,System.Action{NHibernate.Cfg.Configuration})"/> /// and all its overloads 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. /// <para> /// Calling this method will dispose of <see cref="UnitOfWorkTestContext"/> objects within /// <see cref="Contexts"/>. Each context maintains a reference to a <see cref="WindsorContainer"/>. /// If this container object is referenced by <see cref="IoC"/>. /// <see cref="IoC.Container"/> then any subsequent calls to <see cref="IoC"/>. /// <see cref="IoC.Resolve(Type)"/> and any of the overloads will throw. /// </para> /// </remarks> public static void DisposeAndRemoveAllUoWTestContexts() { if (IsDebugEnabled) { log.Debug("Dispose and remove all unit of work testing context is starting..."); } foreach (var context in Contexts) { var context1 = context; With.TryAction(() => { if (context1 != null) { context1.Dispose(); context1 = null; } }, ex => { if (log.IsWarnEnabled) { log.Warn(ex); } }); } CurrentContext.DisposeUnitOfWork(); CurrentContext = null; IsRunningInTestMode = false; Contexts.Clear(); if (log.IsInfoEnabled) { log.Info("All testing context of unit of work is removed."); } }
/// <summary> /// Throw away all <see cref="UnitOfWorkTestContext"/> objects within <see cref="Contexts"/> /// and referenced by <see cref="CurrentContext"/>. /// WARNING: Subsequent calls to <see cref="InitializeNHibernateAndIoC(string, DatabaseEngine, string, MappingInfo, System.Action{NHibernate.Cfg.Configuration})"/> /// and all its overloads 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. /// <para> /// Calling this method will dispose of <see cref="UnitOfWorkTestContext"/> objects within /// <see cref="Contexts"/>. Each context maintains a reference to a <see cref="WindsorContainer"/>. /// If this container object is referenced by <see cref="IoC"/>. /// <see cref="IoC.Container"/> then any subsequent calls to <see cref="IoC"/>. /// <see cref="IoC.Resolve(Type)"/> and any of the overloads will throw. /// </para> /// </remarks> public static void DisposeAndRemoveAllUoWTestContexts() { if (IsDebugEnabled) { log.Debug("Dispose and remove all unit of work testing context is starting..."); } foreach (var context in Contexts) { var context1 = context; try { if (context1 != null) { context1.Dispose(); } } catch (Exception ex) { if (log.IsWarnEnabled) { log.Warn(ex); } } } CurrentContext.DisposeUnitOfWork(); CurrentContext = null; IsRunningInTestMode = false; Contexts.Clear(); if (IsDebugEnabled) { log.Debug("all testing context of unit of work is removed."); } }
private static bool IsInversionOfControlContainerOutOfSyncWith(UnitOfWorkTestContext context) { return (IoC.IsNotInitialized) != (context.Container == null); }
/// <summary> /// Throw away all <see cref="UnitOfWorkTestContext"/> objects within <see cref="Contexts"/> /// and referenced by <see cref="CurrentContext"/>. WARNING: Subsequent calls to <see cref="InitializeNHibernateAndIoC(string,DatabaseEngine,string,NFramework.Data.NHibernateEx.ForTesting.MappingInfo,System.Action{NHibernate.Cfg.Configuration})"/> /// and all its overloads 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. /// <para> /// Calling this method will dispose of <see cref="UnitOfWorkTestContext"/> objects within /// <see cref="Contexts"/>. Each context maintains a reference to a <see cref="WindsorContainer"/>. /// If this container object is referenced by <see cref="IoC"/>. /// <see cref="IoC.Container"/> then any subsequent calls to <see cref="IoC"/>. /// <see cref="IoC.Resolve(Type)"/> and any of the overloads will throw. /// </para> /// </remarks> public static void DisposeAndRemoveAllUoWTestContexts() { if(IsDebugEnabled) log.Debug("Dispose and remove all unit of work testing context is starting..."); foreach(var context in Contexts) { var context1 = context; With.TryAction(() => { if(context1 != null) { context1.Dispose(); context1 = null; } }, ex => { if(log.IsWarnEnabled) log.Warn(ex); }); } CurrentContext.DisposeUnitOfWork(); CurrentContext = null; IsRunningInTestMode = false; Contexts.Clear(); if(log.IsInfoEnabled) log.Info("All testing context of unit of work is removed."); }
private static bool IsInversionOfControlContainerOutOfSyncWith(UnitOfWorkTestContext context) { return((IoC.IsNotInitialized) != (context.Container == null)); }
/// <summary> /// Throw away all <see cref="UnitOfWorkTestContext"/> objects within <see cref="Contexts"/> /// and referenced by <see cref="CurrentContext"/>. /// WARNING: Subsequent calls to <see cref="InitializeNHibernateAndIoC(string, DatabaseEngine, string, MappingInfo, System.Action{NHibernate.Cfg.Configuration})"/> /// and all its overloads 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. /// <para> /// Calling this method will dispose of <see cref="UnitOfWorkTestContext"/> objects within /// <see cref="Contexts"/>. Each context maintains a reference to a <see cref="WindsorContainer"/>. /// If this container object is referenced by <see cref="IoC"/>. /// <see cref="IoC.Container"/> then any subsequent calls to <see cref="IoC"/>. /// <see cref="IoC.Resolve(Type)"/> and any of the overloads will throw. /// </para> /// </remarks> public static void DisposeAndRemoveAllUoWTestContexts() { if(IsDebugEnabled) log.Debug("Dispose and remove all unit of work testing context is starting..."); foreach(var context in Contexts) { var context1 = context; try { if(context1 != null) context1.Dispose(); } catch(Exception ex) { if(log.IsWarnEnabled) log.Warn(ex); } } CurrentContext.DisposeUnitOfWork(); CurrentContext = null; IsRunningInTestMode = false; Contexts.Clear(); if(IsDebugEnabled) log.Debug("all testing context of unit of work is removed."); }