public void CanSetUpAPolicyWithGivenRulesAndHandlers() { IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); IMatchingRule rule1 = new AlwaysMatchingRule(); ICallHandler handler1 = new CallCountHandler(); container .Configure <Interception>() .AddPolicy("policy1") .AddMatchingRule(rule1) .AddCallHandler(handler1); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new VirtualMethodInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, ((CallCountHandler)handler1).CallCount); }
public void ConfigureContainerReturnEmptyIfNoInterception() { ICallHandler myHandler1 = new CallCountHandler(); IMatchingRule myMatchingRule1 = new AlwaysMatchingRule(); IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); container.Configure <Interception>(). AddPolicy("myRDP"). AddCallHandler(myHandler1). AddMatchingRule(myMatchingRule1); Assert.AreEqual(0, ((CallCountHandler)myHandler1).CallCount); }
public void ConfigureContainerbyAddingPolicyHanlderRule() { ICallHandler myHandler1 = new CallCountHandler(); IMatchingRule myMatchingRule1 = new AlwaysMatchingRule(); IUnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container.Configure<Interception>(). AddPolicy("myRDP"). AddCallHandler(myHandler1). AddMatchingRule(myMatchingRule1); container.Configure<Interception>(). SetInterceptorFor<InterceptionClass>("interceptionclass", new TransparentProxyInterceptor()); InterceptionClass ic = container.Resolve<InterceptionClass>("interceptionclass"); ic.MethodA(); Assert.AreEqual(1, ((CallCountHandler)myHandler1).CallCount); }
public void ConfigureContainerbyAddingPolicyHanlderRule() { ICallHandler myHandler1 = new CallCountHandler(); IMatchingRule myMatchingRule1 = new AlwaysMatchingRule(); IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); container.Configure <Interception>(). AddPolicy("myRDP"). AddCallHandler(myHandler1). AddMatchingRule(myMatchingRule1); container.Configure <Interception>(). SetInterceptorFor <InterceptionClass>("interceptionclass", new TransparentProxyInterceptor()); InterceptionClass ic = container.Resolve <InterceptionClass>("interceptionclass"); ic.MethodA(); Assert.AreEqual(1, ((CallCountHandler)myHandler1).CallCount); }
public UnityProvider(IDictionary<Type, object> map, int dbRetries, int dbSleepSeconds) { IMatchingRule alwaysMatch = new AlwaysMatchingRule(); _map = map; _container = new UnityContainer(); _retries = dbRetries; _sleepSeconds = dbSleepSeconds; IDictionary<Type, RetryOrHandleExceptionDelgate> exceptionTranslators = GetExceptionTranslators(map); _container.AddNewExtension<Interception>(); Interception inter = _container.Configure<Interception>(); if (inter == null) { Trace.WriteLine("No interception"); } PolicyDefinition definition = inter.AddPolicy("DbRetry"); if (definition == null) { Trace.WriteLine("No policy definition 0"); } if (definition.AddMatchingRule(alwaysMatch) == null) { Trace.WriteLine("No policy definition 1"); } _interceptor = new DbRetryInterceptor(dbRetries, dbSleepSeconds, exceptionTranslators); if (definition.AddCallHandler(_interceptor) == null) { Trace.WriteLine("No policy definition 2"); } IInstanceInterceptor _instanceInterceptor = new InterfaceInterceptor(); foreach (KeyValuePair<Type, object> entry in map) { _container.RegisterInstance(entry.Key, entry.Value); if (entry.Key.IsInterface) { _container.Configure<Interception>().SetInterceptorFor(entry.Key, _instanceInterceptor); } } }
public void ConfigureContainerReturnEmptyIfNoInterception() { ICallHandler myHandler1 = new CallCountHandler(); IMatchingRule myMatchingRule1 = new AlwaysMatchingRule(); IUnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container.Configure<Interception>(). AddPolicy("myRDP"). AddCallHandler(myHandler1). AddMatchingRule(myMatchingRule1); Assert.AreEqual(0, ((CallCountHandler)myHandler1).CallCount); }