public void Test_retry_interceptor()
        {
            var counter = new Counter();
            var a       = new SimpleInterceptor(counter);
            var b       = new RetryInterceptor(10);
            var c       = new SimpleInterceptor(counter);

            var inv = new TestInvocation();

            Assert.AreEqual(0, inv.ProceedCount);
            Assert.AreEqual(0, inv.InvokeCount);

            var chain = new AopInterceptorChain(new IInterceptor[] { a, b, c });

            chain.Intercept(inv);

            // check invocation ultimately invoked 10 times, but NOT via the Proceed() method
            Assert.AreEqual(0, inv.ProceedCount);
            Assert.AreEqual(10, inv.InvokeCount);

            // check each interceptor called correct number of times
            Assert.AreEqual(1, a.InterceptCount);
            Assert.AreEqual(1, b.InterceptCount);
            Assert.AreEqual(10, c.InterceptCount);
        }
        public void Test_basic_interception_chain()
        {
            var counter = new Counter();
            var a       = new SimpleInterceptor(counter);
            var b       = new SimpleInterceptor(counter);
            var c       = new SimpleInterceptor(counter);

            var inv = new TestInvocation();

            Assert.IsFalse(inv.Proceeded);
            Assert.IsFalse(inv.Invoked);

            var chain = new AopInterceptorChain(new[] { a, b, c });

            chain.Intercept(inv);

            // check invocation ultimately invoked, but NOT via the Proceed() method
            Assert.IsFalse(inv.Proceeded);
            Assert.IsTrue(inv.Invoked);

            // check each interceptor called in correct order
            Assert.AreEqual(0, a.InterceptIndex);
            Assert.AreEqual(1, b.InterceptIndex);
            Assert.AreEqual(2, c.InterceptIndex);
        }
示例#3
0
        /// <summary>
        /// Obtains an instance of the service that implements the specified contract.
        /// </summary>
        /// <returns></returns>
        public object GetService(Type serviceContract)
        {
            lock (_syncLock)
            {
                // instantiate service object
                object service = _serviceExtensionPoint.CreateExtension(new TypeExtensionFilter(serviceContract));

                // note: _proxyGenerator does internal caching based on service contract
                // so subsequent calls based on the same contract will be fast
                var aopChain = new AopInterceptorChain(_interceptors);
                return(_proxyGenerator.CreateInterfaceProxyWithTarget(serviceContract, service, aopChain));
            }
        }
        public void Test_empty_interception_chain()
        {
            var inv = new TestInvocation();

            Assert.IsFalse(inv.Proceeded);
            Assert.IsFalse(inv.Invoked);

            var chain = new AopInterceptorChain(new IInterceptor[0]);

            chain.Intercept(inv);

            // check invocation ultimately invoked, but NOT via the Proceed() method
            Assert.IsFalse(inv.Proceeded);
            Assert.IsTrue(inv.Invoked);
        }
        public void Test_interceptor_does_not_proceed()
        {
            var counter = new Counter();
            var a       = new SimpleInterceptor(counter, false);

            var inv = new TestInvocation();

            Assert.IsFalse(inv.Proceeded);
            Assert.IsFalse(inv.Invoked);

            var chain = new AopInterceptorChain(new[] { a });

            chain.Intercept(inv);

            // check invocation not invoked
            Assert.IsFalse(inv.Proceeded);
            Assert.IsFalse(inv.Invoked);

            // check each interceptor called in correct order
            Assert.AreEqual(0, a.InterceptIndex);
        }
示例#6
0
		public void Test_retry_interceptor()
		{
			var counter = new Counter();
			var a = new SimpleInterceptor(counter);
			var b = new RetryInterceptor(10);
			var c = new SimpleInterceptor(counter);

			var inv = new TestInvocation();

			Assert.AreEqual(0, inv.ProceedCount);
			Assert.AreEqual(0, inv.InvokeCount);

			var chain = new AopInterceptorChain(new IInterceptor[] { a, b, c });
			chain.Intercept(inv);

			// check invocation ultimately invoked 10 times, but NOT via the Proceed() method
			Assert.AreEqual(0, inv.ProceedCount);
			Assert.AreEqual(10, inv.InvokeCount);

			// check each interceptor called correct number of times
			Assert.AreEqual(1, a.InterceptCount);
			Assert.AreEqual(1, b.InterceptCount);
			Assert.AreEqual(10, c.InterceptCount);
		}
示例#7
0
		public void Test_interceptor_does_not_proceed()
		{
			var counter = new Counter();
			var a = new SimpleInterceptor(counter, false);

			var inv = new TestInvocation();

			Assert.IsFalse(inv.Proceeded);
			Assert.IsFalse(inv.Invoked);

			var chain = new AopInterceptorChain(new[] { a });
			chain.Intercept(inv);

			// check invocation not invoked
			Assert.IsFalse(inv.Proceeded);
			Assert.IsFalse(inv.Invoked);

			// check each interceptor called in correct order
			Assert.AreEqual(0, a.InterceptIndex);
		}
示例#8
0
		public void Test_empty_interception_chain()
		{
			var inv = new TestInvocation();

			Assert.IsFalse(inv.Proceeded);
			Assert.IsFalse(inv.Invoked);

			var chain = new AopInterceptorChain(new IInterceptor[0]);
			chain.Intercept(inv);

			// check invocation ultimately invoked, but NOT via the Proceed() method
			Assert.IsFalse(inv.Proceeded);
			Assert.IsTrue(inv.Invoked);
		}
示例#9
0
		public void Test_basic_interception_chain()
		{
			var counter = new Counter();
			var a = new SimpleInterceptor(counter);
			var b = new SimpleInterceptor(counter);
			var c = new SimpleInterceptor(counter);

			var inv = new TestInvocation();

			Assert.IsFalse(inv.Proceeded);
			Assert.IsFalse(inv.Invoked);

			var chain = new AopInterceptorChain(new[] {a, b, c});
			chain.Intercept(inv);

			// check invocation ultimately invoked, but NOT via the Proceed() method
			Assert.IsFalse(inv.Proceeded);
			Assert.IsTrue(inv.Invoked);

			// check each interceptor called in correct order
			Assert.AreEqual(0, a.InterceptIndex);
			Assert.AreEqual(1, b.InterceptIndex);
			Assert.AreEqual(2, c.InterceptIndex);
		}