public void GetAsyncCacheStore_by_id_should_handle_Exception()
        {
            var invocation = Substitute.For <_IInvocation>();
            var context    = new Dictionary <string, object>
            {
                [Global.__flatwhite_outputcache_attribute] = new OutputCacheAttribute
                {
                    CacheStoreId   = 101,
                    CacheStoreType = Substitute.For <IAsyncCacheStore>().GetType()
                }
            };
            var cacheStoreProvider = Substitute.For <ICacheStoreProvider>();

            cacheStoreProvider.When(x => x.GetAsyncCacheStore(101)).Do(x => { throw new Exception(); });
            cacheStoreProvider.GetAsyncCacheStore(Arg.Any <Type>()).Returns(Substitute.For <IAsyncCacheStore>());
            Global.CacheStoreProvider = cacheStoreProvider;

            var stg = new DefaultCacheStrategy();

            // Action
            var store = stg.GetAsyncCacheStore(invocation, context);

            // Assert
            cacheStoreProvider.DidNotReceive().GetAsyncCacheStore(0);
        }
        public void GetAsyncCacheStore_should_return_default_store_if_cannot_get_store_adaptor()
        {
            var invocation = Substitute.For <_IInvocation>();
            var context    = new Dictionary <string, object>
            {
                [Global.__flatwhite_outputcache_attribute] = new OutputCacheAttribute
                {
                    CacheStoreType = Substitute.For <ICacheStore>().GetType()
                }
            };
            var cacheStoreProvider = Substitute.For <ICacheStoreProvider>();

            cacheStoreProvider.When(x => x.GetAsyncCacheStore(Arg.Is <Type>(t => typeof(IAsyncCacheStore).IsAssignableFrom(t)))).Do(x => { throw new KeyNotFoundException(); });
            cacheStoreProvider.When(x => x.GetCacheStore(Arg.Is <Type>(t => typeof(ICacheStore).IsAssignableFrom(t)))).Do(x => { throw new KeyNotFoundException(); });
            Global.CacheStoreProvider = cacheStoreProvider;

            var stg = new DefaultCacheStrategy();

            // Action
            var store = stg.GetAsyncCacheStore(invocation, context);

            // Assert
            cacheStoreProvider.Received(1).GetCacheStore(Arg.Is <Type>(t => t == Substitute.For <ICacheStore>().GetType()));
            cacheStoreProvider.Received(1).GetAsyncCacheStore(0);
            Assert.IsFalse(store is CacheStoreAdaptor);
        }
        public void GetAsyncCacheStore_should_try_to_get_by_type()
        {
            var invocation = Substitute.For <_IInvocation>();
            var context    = new Dictionary <string, object>
            {
                [Global.__flatwhite_outputcache_attribute] = new OutputCacheAttribute
                {
                    CacheStoreId   = 101,
                    CacheStoreType = Substitute.For <IAsyncCacheStore>().GetType()
                }
            };
            var cacheStoreProvider = Substitute.For <ICacheStoreProvider>();

            cacheStoreProvider.GetAsyncCacheStore(Arg.Any <int>()).Returns((IAsyncCacheStore)null);
            cacheStoreProvider.GetAsyncCacheStore(Arg.Any <Type>()).Returns(Substitute.For <IAsyncCacheStore>());
            Global.CacheStoreProvider = cacheStoreProvider;

            var stg = new DefaultCacheStrategy();

            // Action
            var store = stg.GetAsyncCacheStore(invocation, context);

            // Assert
            cacheStoreProvider.DidNotReceive().GetAsyncCacheStore(0);
        }
        public void GetAsyncCacheStore_should_return_found_async_store_by_id()
        {
            var invocation = Substitute.For <_IInvocation>();
            var context    = new Dictionary <string, object>
            {
                [Global.__flatwhite_outputcache_attribute] = new OutputCacheAttribute
                {
                    CacheStoreId = 100
                }
            };
            var cacheStoreProvider = Substitute.For <ICacheStoreProvider>();

            cacheStoreProvider.GetAsyncCacheStore(100).Returns(Substitute.For <IAsyncCacheStore>());
            Global.CacheStoreProvider = cacheStoreProvider;

            var stg = new DefaultCacheStrategy();

            // Action
            var store = stg.GetAsyncCacheStore(invocation, context);

            // Assert
            cacheStoreProvider.Received(1).GetAsyncCacheStore(100);
            cacheStoreProvider.DidNotReceive().GetAsyncCacheStore(0);
        }