예제 #1
0
        public void CanMakeAsync()
        {
            var instance    = new LongWait();
            var interceptor = new DispatchProxyInterceptor();
            var proxy       = interceptor.Intercept(instance, typeof(ILongWait), new AsyncInterceptionHandler()) as ILongWait;
            var timer       = Stopwatch.StartNew();

            proxy.DoLongOperation();
            Assert.True(timer.Elapsed < TimeSpan.FromSeconds(5));
        }
예제 #2
0
        public void CanEnforceTimeout()
        {
            var instance    = new LongWait();
            var interceptor = new InterfaceInterceptor();
            var handler     = new TimeoutInterceptionHandler(3);

            var proxy = this.InstanceInterception(interceptor, instance, handler) as ILongWait;

            Assert.Throws <TimeoutException>(() => proxy.DoLongOperation());
        }
예제 #3
0
        public void CanDoCallback()
        {
            var called      = false;
            var instance    = new LongWait();
            var interceptor = new InterfaceInterceptor();
            var handler     = new CallbackInterceptionHandler(() => called = true);

            var proxy = this.InstanceInterception(interceptor, instance, handler) as ILongWait;

            proxy.DoLongOperation();

            Assert.True(called);
        }