Example #1
0
        public void ResetTest()
        {
            string item  = "Item to be cached";
            var    cache = new CacheObject <string>(TimeSpan.FromMilliseconds(100)).Set(item);

            cache.TryGetValue(out string value).Should().BeTrue();
            value.Should().NotBeNullOrEmpty();
            value.Should().Be(item);
            cache.IsValid().Should().BeTrue();

            cache.Clear();
            cache.IsValid().Should().BeFalse();
        }
Example #2
0
        public void GivenCacheObject_Initialize_ShouldBeFalseState()
        {
            var cache = new CacheObject <string>(TimeSpan.FromSeconds(10));

            cache.IsValid().Should().BeFalse();
            cache.TryGetValue(out string value).Should().BeFalse();
            value.Should().BeNullOrEmpty();
        }
Example #3
0
        public void EmptyTest()
        {
            var cache = new CacheObject <string>(TimeSpan.FromSeconds(10));

            cache.IsValid().Should().BeFalse();
            cache.IsRefresh().Should().BeFalse();
            cache.TryGetValue(out string value).Should().BeFalse();
            value.Should().BeNullOrEmpty();
        }
Example #4
0
        public void StoreExtensionTest()
        {
            string item = "Item to be cached";
            CacheObject <string> cache = item.ToCacheObject(TimeSpan.FromSeconds(100));

            cache.IsValid().Should().BeTrue();
            cache.TryGetValue(out string value).Should().BeTrue();
            value.Should().NotBeNullOrEmpty();
            value.Should().Be(item);
        }