Ejemplo n.º 1
0
        public void Remove_does_clear_cache()
        {
            var context = new TestableCacheService();

            context.SutInMemoryObject.Set(new InMemoryObject("stays"));
            context.SutInMemoryObject.Clear();
            Assert.Null(context.SutInMemoryObject.Get());
        }
Ejemplo n.º 2
0
        public void Get_does_call_func_if_provided_and_cache_empty()
        {
            var context = new TestableCacheService();
            var called  = false;
            var cache   = context.SutInMemoryObject.Get(() =>
            {
                called = true;
                return(new InMemoryObject("is.called"));
            });

            Assert.True(called);
            Assert.NotNull(cache);
            Assert.Equal("is.called", cache.Value);
        }
Ejemplo n.º 3
0
        public void Get_does_not_call_func_if_cache_present()
        {
            var context = new TestableCacheService();

            context.SutInMemoryObject.Set(new InMemoryObject("stays"));
            var called = false;
            var cache  = context.SutInMemoryObject.Get(() =>
            {
                called = true;
                return(new InMemoryObject("never.reached"));
            });

            Assert.False(called);
            Assert.NotNull(cache);
            Assert.Equal("stays", cache.Value);
        }
Ejemplo n.º 4
0
        public void ClearAll_does_clear_everything()
        {
            var context = new TestableCacheService();

            context.Sut.Set(typeof(InMemoryObject), new InMemoryObject("stays"));
            context.Sut.Set(typeof(string), "hello");

            var internalCache = context.Sut.MemoryCache;

            context.Sut.ClearAll();

            context.Sut.MemoryCache.TryGetValue(typeof(string), out object stringValue);
            context.Sut.MemoryCache.TryGetValue(typeof(InMemoryObject), out object testObject);

            Assert.Null(stringValue);
            Assert.Null(testObject);
            Assert.NotEqual(internalCache, context.Sut.MemoryCache);
        }
Ejemplo n.º 5
0
        public void Get_does_return_null_if_nothing_set()
        {
            var context = new TestableCacheService();

            Assert.Null(context.SutInMemoryObject.Get());
        }