Beispiel #1
0
        public void GetOrAdd_WhenItemNotAlreadyCached_ShouldRecordTime()
        {
            //when
            DateTimeOffset expectedTime = DateTimeOffset.Now;

            _cache.GetOrAdd("key1", _ => new object());

            Thread.Sleep(60);

            //then
            AssertAccessTime(_cache.Statistics, CacheStatisticsKeys.LastWrite, expectedTime);
        }
        public void GetOrAddShouldRecordTime()
        {
            //given
            _cache.GetOrAdd("key1", _ => new object());

            //when
            DateTimeOffset expectedTime = DateTimeOffset.Now;

            _cache.GetOrAdd("key1", _ => new object());

            //then
            Thread.Sleep(60);
            AssertAccessTime(_cache.Statistics, CacheStatisticsKeys.LastRead, expectedTime);
        }
Beispiel #3
0
        public void GetOrAdd_Miss()
        {
            // when
            _cache.GetOrAdd("key1", _ => new object());

            // then
            var ratio = _cache.Statistics.SafeGetValue <decimal?>(CacheStatisticsKeys.CacheHitRatio);

            Assert.That(ratio, Is.EqualTo(0m));
        }