public static ManualConfigSource GetManualConfigSource() { var source = new ManualConfigSource(); source.ObjectContainer = typeof(UnityObjectContainer); return(source); }
public static void StartBDDD(TestContext context) { ManualConfigSource configSource = ConfigHelper.GetManualConfigSource(); application = AppRuntime.Create(configSource); application.AppInitEvent += application_AppInitEvent; application.Start(); }
protected static void InitAppRuntime() { ManualConfigSource configSource = new ManualConfigSource { ObjectContainer = typeof(UnityObjectContainer) }; application = AppRuntime.Create(configSource); application.AppInitEvent += application_AppInitEvent; application.Start(); }
public void AddInterceptor() { ManualConfigSource configSource = ConfigHelper.GetManualConfigSource(); configSource.AddInterceptor("ExceptionHandler", typeof(ExceptionHandlerInterceptor)); App app = AppRuntime.Create(configSource); app.Start(); Assert.AreEqual(1, app.Interceptors.Count()); }
public static void Initial(TestContext context) { ManualConfigSource configSource = ConfigHelper.GetManualConfigSource(); application = AppRuntime.Create(configSource); application.Start(); var c = application.ObjectContainer.GetRealObjectContainer <UnityContainer>(); c.RegisterType <ICache, MemcachedCache>(); c.RegisterType <AbsoluteTimeExpiration, MemcachedAbsoluteTimeExpiration>("SCache", new InjectionConstructor( TimeSpan.FromSeconds(5))); c.RegisterType <AbsoluteTimeExpiration, MemcachedAbsoluteTimeExpiration>("S1Cache", new InjectionConstructor( TimeSpan.FromSeconds(15))); }
public void AddInterceptor_AddInterceptorRef() { Type typeWantToIntercept = typeof(IRepositoryContext); MethodInfo addMethod = typeWantToIntercept.GetMethod("RegisterNew", BindingFlags.Public | BindingFlags.Instance); Assert.IsNotNull(addMethod); ManualConfigSource configSource = ConfigHelper.GetManualConfigSource(); configSource.AddInterceptor(typeof(ExceptionHandlerInterceptor)); configSource.AddInterceptorRef(typeWantToIntercept, addMethod, typeof(ExceptionHandlerInterceptor).AssemblyQualifiedName); App app = AppRuntime.Create(configSource); app.Start(); Assert.AreEqual(1, app.Interceptors.Count()); Assert.AreEqual(typeWantToIntercept.AssemblyQualifiedName, app.ConfigSource.Config.Interception.Contracts.GetItemAt(0).Type); }
public void AddInterceptor_TestInterceptor() { Type typeWantToIntercept = typeof(IUnitOfWork); MethodInfo addMethod = typeWantToIntercept.GetMethod("Commit", BindingFlags.Public | BindingFlags.Instance); Assert.IsNotNull(addMethod); ManualConfigSource configSource = ConfigHelper.GetManualConfigSource(); configSource.AddInterceptor("TestHandler", typeof(TestInterceptor)); configSource.AddInterceptorRef(typeWantToIntercept, addMethod, "TestHandler"); App app = AppRuntime.Create(configSource); app.Start(); var container = AppRuntime.Instance.CurrentApplication.ObjectContainer.GetRealObjectContainer <UnityContainer>(); container.RegisterType <INHibernateConfiguration, NHibernateConfiguration>( new InjectionConstructor(nhibernateCfg)); container.RegisterType <IRepositoryContext, NHibernateContext>( new InjectionConstructor(new ResolvedParameter <INHibernateConfiguration>())); using (var context = ServiceLocator.Instance.GetService <IRepositoryContext>()) { IRepository <ItemCategory> customerRepository = context.GetRepository <ItemCategory>(); var itemCategory = new ItemCategory { CategoryName = "日常用品" }; //这里的cutsomerRepository没有使用透明代理,所以他的方法不会被拦截 customerRepository.Add(itemCategory); context.Commit(); } Assert.IsTrue(TestInterceptor.execCount == 1); }