Beispiel #1
0
        public void ShouldCallImplementedInterfaceMethod()
        {
            var random = new Random();

            for (int i = 0; i < 100; i++)
            {
                var interceptor1 = new Interceptor1();
                var interceptor2 = new Interceptor2();
                var interceptor3 = new Interceptor3();
                var interceptor4 = new Interceptor4();

                var interceptors = new IResponseCachingInterceptor[] { interceptor1, interceptor2, interceptor3, interceptor4 };

                //随机组合进行测试
                interceptors = interceptors.OrderBy(_ => random.Next()).ToArray();

                Console.WriteLine($"time: {i:D3} - order:{string.Join(" -> ", interceptors.Select(m => m.GetType().Name))}");

                var interceptorAggregator = new InterceptorAggregator(interceptors);

                interceptorAggregator.OnCacheStoringAsync(null, null, null, (_, _, _) => Task.FromResult <ResponseCacheEntry>(null));
                interceptorAggregator.OnResponseWritingAsync(null, null, (_, _) => Task.FromResult(true));

                NormalCheck(interceptors);
            }
        }
Beispiel #2
0
        public void ShouldShortCircuits()
        {
            var random = new Random();

            for (int i = 0; i < 100; i++)
            {
                var interceptor1             = new Interceptor1();
                var interceptor2             = new Interceptor2();
                var interceptor3             = new Interceptor3();
                var interceptor4             = new Interceptor4();
                var shortCircuitsInterceptor = new ShortCircuitsInterceptor();

                var interceptors = new IResponseCachingInterceptor[] { interceptor1, interceptor2, interceptor3, interceptor4, shortCircuitsInterceptor };

                //随机组合进行测试
                interceptors = interceptors.OrderBy(_ => random.Next()).ToArray();

                Console.WriteLine($"time: {i:D3} - order:{string.Join(" -> ", interceptors.Select(m => m.GetType().Name))}");

                var interceptorAggregator = new InterceptorAggregator(interceptors);

                interceptorAggregator.OnCacheStoringAsync(null, null, null, (_, _, _) => Task.FromResult <ResponseCacheEntry>(null));
                interceptorAggregator.OnResponseWritingAsync(null, null, (_, _) => Task.FromResult(true));

                bool shortCircuited = false;
                foreach (var interceptor in interceptors)
                {
                    if (shortCircuited)
                    {
                        ShouldNoAnyCalled(interceptor);
                    }
                    else
                    {
                        NormalCheck(interceptor);
                        shortCircuited = interceptor is ShortCircuitsInterceptor;
                    }
                }
            }
        }