Exemple #1
0
        public void GetAsyncCacheStore_should_throw_exception_if_store_type_not_found()
        {
            var provider = new DefaultCacheStoreProvider();

            Assert.Throws <KeyNotFoundException>(() => provider.GetAsyncCacheStore(typeof(DefaultCacheStoreProviderTests)));
            Assert.IsNotNull(provider.GetCacheStore(typeof(IAsyncCacheStore)));
        }
Exemple #2
0
        public void GetAsyncCacheStore_should_return_null_if_storeId_less_than_0_or_not_found()
        {
            var provider = new DefaultCacheStoreProvider();

            Assert.IsNull(provider.GetAsyncCacheStore(-1));
            Assert.IsNull(provider.GetAsyncCacheStore(1));
            Assert.IsNotNull(provider.GetAsyncCacheStore(0));
        }
Exemple #3
0
        public void Dispose_should_clear_all_cached_stores()
        {
            var provider = new DefaultCacheStoreProvider();

            provider.Dispose();
            Assert.IsNull(provider.GetCacheStore(0));
            Assert.IsNull(provider.GetAsyncCacheStore(0));
        }
Exemple #4
0
        public void GetAsyncCacheStore_should_return_async_store_adaptor_if_sync_store_with_same_id_found()
        {
            var store = Substitute.For <ICacheStore>();

            store.StoreId.Returns(10);
            var provider = new DefaultCacheStoreProvider();

            provider.RegisterStore(store);
            Assert.IsNotNull(provider.GetAsyncCacheStore(10));
        }
Exemple #5
0
        public void RegisterAsyncStore_should_register_both_type_and_id()
        {
            var store = Substitute.For <IAsyncCacheStore>();

            store.StoreId.Returns(10);
            var provider = new DefaultCacheStoreProvider();

            Assert.Throws <ArgumentNullException>(() => provider.RegisterAsyncStore(null));
            provider.RegisterAsyncStore(store);
            Assert.IsNotNull(provider.GetAsyncCacheStore(10));
            Assert.IsNotNull(provider.GetAsyncCacheStore(store.GetType()));
        }
Exemple #6
0
        public void RegisterStore_should_throw_exception_if_duplicated_async_store_id()
        {
            var store = Substitute.For <ICacheStore>();

            store.StoreId.Returns(10);

            var asyncStore = Substitute.For <IAsyncCacheStore>();

            asyncStore.StoreId.Returns(10);
            var provider = new DefaultCacheStoreProvider();

            provider.RegisterAsyncStore(asyncStore);
            Assert.Throws <InvalidOperationException>(() => provider.RegisterStore(store));
        }
Exemple #7
0
        internal static void Init()
        {
            Cache = new MethodInfoCache();

            CacheStrategyProvider     = new DefaultCacheStrategyProvider();
            AttributeProvider         = new DefaulAttributeProvider();
            HashCodeGeneratorProvider = new DefaultHashCodeGeneratorProvider();
            CacheKeyProvider          = new DefaultCacheKeyProvider(HashCodeGeneratorProvider);
            CacheStoreProvider        = new DefaultCacheStoreProvider();
            ServiceActivator          = new DefaultServiceActivator();
            Logger = new NullLogger();
            BackgroundTaskManager = new DefaultBackgroundTaskManager();

            var configFolder = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            CacheProfileProvider = new YamlCacheProfileProvider(Path.Combine(configFolder ?? "", "cacheProfile.yaml"));
        }