public void Should_BuildPolicy_WithCacheItemPriorityDefaultValue()
        {
            const CacheItemPriority expected = CacheItemPriority.Default;

            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .Build();

            policy.CacheItemPriority.Should().Be(expected);
        }
        public void Should_BuildPolicy_WithValidSlidingExpiration()
        {
            var validSlidingExpiration = TimeSpan.FromSeconds(1);

            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .WithSlidingExpiration(validSlidingExpiration)
                .Build();

            policy.SlidingExpiration.Should().Be(validSlidingExpiration);
        }
        public void Should_BuildPolicy_WithValidCacheItemPriority()
        {
            const CacheItemPriority validCacheItemPriority = CacheItemPriority.High;

            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .WithCacheItemPriority(validCacheItemPriority)
                .Build();

            policy.CacheItemPriority.Should().Be(validCacheItemPriority);
        }
        public void Should_BuildPolicy_WithValidAbsolutegExpiration()
        {
            var validAbsolutegExpiration = DateTimeOffset.Now.AddSeconds(1);

            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .WithAbsoluteExpiration(validAbsolutegExpiration)
                .Build();

            policy.AbsoluteExpiration.Should().Be(validAbsolutegExpiration);
        }
        public void Should_BuildPolicy_WithValidDirectoriesOrFilesChangeMonitor()
        {
            var validDirectoriesOrFilesChangeMonitor = new[] {DirectoryStub};

            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .WithDirectoriesOrFilesChangeMonitor(validDirectoriesOrFilesChangeMonitor)
                .Build();

               validDirectoriesOrFilesChangeMonitor
                .SequenceEqual(policy.DirectoriesOrFiles)
                .Should()
                .BeTrue();
        }
        public void Should_BuildSimplePolicy()
        {
            var policy = new CacheItemPolicy
                .CacheItemPolicyBuilder()
                .Build();

            policy.Should().NotBeNull();
        }
        public void Should_Expire_GivenPolicyWithSlidingExpirationOf_SomeMiliseconds()
        {
            const int someMiliseconds = 2;

            var policy = new CacheItemPolicy.CacheItemPolicyBuilder()
                .WithSlidingExpiration(TimeSpan.FromMilliseconds(someMiliseconds))
                .Build();

            const string key = "ShouldExpire_GivenPolicyWithSlidingExpirationOf_SomeMilisecondsKey";
            const string value = "ShouldExpire_GivenPolicyWithSlidingExpirationOf_SomeMilisecondsValue";

            _cacher.Add(key, value, policy);
            Thread.Sleep(5);

            var result = _cacher.Retrieve<string>(key);

            result.Should().BeNull();
        }
        public void Should_UseCacheItemPriorityConverter_WhenAddSomething_AndHasNotCacheItemPriorityValue()
        {
            const int someMiliseconds = 2;

            var policy = new CacheItemPolicy.CacheItemPolicyBuilder()
                .WithSlidingExpiration(TimeSpan.FromMilliseconds(someMiliseconds))
                .Build();

            _cacher.Add("ShouldUseCacheItemPriorityConverterWhenAddSomethingAndHasNotCacheItemPriorityValue",
                "ShouldUseCacheItemPriorityConverterWhenAddSomethingAndHasNotCacheItemPriorityValue",
                policy);

            _cacheItemPriorityMock
                .Verify(e => e.Convert(It.IsAny<CacheItemPriority>()), Times.Once);
        }
        public void Should_UseCacheItemPriorityConverter_WhenAddSomething()
        {
            var policy = new CacheItemPolicy.CacheItemPolicyBuilder()
                .WithCacheItemPriority(CacheItemPriority.Normal)
                .Build();

            _cacher.Add("ShouldUseCacheItemPriorityConverterWhenAddSomething",
                "ShouldUseCacheItemPriorityConverterWhenAddSomethingValue",
                policy);

            _cacheItemPriorityMock
                .Verify(e => e.Convert(It.IsAny<CacheItemPriority>()), Times.Once);
        }