Пример #1
0
        private static CacheCallStackContext GetCallStackContext()
        {
            var callStackContext = CallContext.GetData(CallStackContextKey) as CacheCallStackContext;
            
            if (callStackContext == null)
            {
                callStackContext = new CacheCallStackContext();
                CallContext.SetData(CallStackContextKey, callStackContext);
            }

            return callStackContext;
        }
Пример #2
0
        private bool TryServeValueFromCache(IInvocation invocation, StageResult stageResult,
                                            CacheCallStackContext callStackContext, string cacheKey, ICacheProvider cacheProvider)
        {
            object cacheEntry;

            if (cacheProvider.TryGetCachedObject(cacheKey, out cacheEntry))
            {
                if (cacheEntry == null)
                {
                    invocation.ReturnValue = null;
                }
                else
                {
                    SetReturnValueFromCacheEntry(invocation, cacheEntry);
                }

                stageResult.Proceed = false;

                // We're not going to run the "After" stage, and so we need to process exiting now
                callStackContext.Exit();

                return true;
            }

            return false;
        }
 protected override void ExecuteTest()
 {
     callContext = new CacheCallStackContext();
     callContext.Enter(invocations[0]);
 }
Пример #4
0
        protected override void BeforeExecuteTest()
        {
            var cacheCallStackContext = new CacheCallStackContext();

            // Reinitialize the context
            CallContext.FreeNamedDataSlot(CacheInterceptor.CallStackContextKey);
            CallContext.SetData(CacheInterceptor.CallStackContextKey, cacheCallStackContext);

            // Simulate invocation already entered the cache interceptor
            cacheCallStackContext.Enter(invocation);

            Assert.That(GetCacheCallStackContext().CurrentDepth, Is.GreaterThan(0));
        }
        protected override void ExecuteTest()
        {
            callContext = new CacheCallStackContext();

            // First service call context
            callContext.Enter(invocations[0]); // Outer service ENTER
            callContext.Enter(invocations[1]); // Inner service ENTER
            callContext.Exit();                // Inner service EXIT
            fakeInterceptor.MarkAsProcessed(); // Result modified by upstream interceptor
            callContext.Exit();                // Outer service EXIT

            // Starting a second service call
            callContext.Enter(invocations[2]); // Outer service ENTER
            callContext.Enter(invocations[3]); // Inner service ENTER
            callContext.Exit();                // Inner service EXIT
        }