Esempio n. 1
0
        public async Task ShouldSetKeyExpirySuccessfully()
        {
            // Arrange
            await _redisClient.Remove(_setKey).ConfigureAwait(false);

            var key = _fixture.FormatKey("expiringkey");

            // Act & Assert
            Should.NotThrow(() => _sut.SetKeyExpiry(_redisClient, key, DateTime.Now.AddYears(-1)));
        }
Esempio n. 2
0
        public void ShouldAddSuccessfully()
        {
            // Arrange
            var          key    = _fixture.FormatKey("TagCacheTests:Add");
            const string value  = "Test Value";
            var          expiry = DateTime.Now.AddSeconds(3);

            // Act & Assert
            Should.NotThrow(async() => await _sut.Set(key, value, expiry).ConfigureAwait(false));
        }
        public async Task ShouldRemoveExpiredItemFromCache()
        {
            // Arrange
            await _sut.RemoveExpiredKeys().ConfigureAwait(false);

            var          key     = _fixture.FormatKey($"TagCacheTests:{nameof(ShouldRemoveExpiredItemFromCache)}");
            const string value   = "Test Value";
            var          expires = DateTime.Now.AddSeconds(3);

            const string tag1 = "tag1";
            const string tag2 = "tag2";

            await _sut.SetItem(key, value, expires, tag1, tag2).ConfigureAwait(false);

            var result = await _sut.GetItem <string>(key).ConfigureAwait(false);

            result.ShouldNotBeNull();
            result.Value.ShouldBe(value);

            Thread.Sleep(1000);

            result = await _sut.GetItem <string>(key).ConfigureAwait(false);

            result.ShouldNotBeNull();
            result.Value.ShouldBe(value);

            // Act
            Thread.Sleep(2500);
            await _sut.RemoveExpiredKeys().ConfigureAwait(false);

            Thread.Sleep(500);
            result = await _sut.GetItem <string>(key).ConfigureAwait(false);

            // Assert
            result.ShouldBeNull();
        }
        public void ShouldConstructSuccessfully()
        {
            // Arrange
            var config = BuildCacheConfiguration(_redis);

            config.RootNamespace            = "_TestRootNamespace";
            config.Serializer               = new BinarySerializationProvider();
            config.RedisClientConfiguration = new RedisClientConfiguration(config.RedisClientConfiguration.RedisConnectionManager)
            {
                DbIndex   = DatabaseIndex,
                TimeoutMs = 50
            };

            // Act
            var cache = new RedisCacheProvider(config)
            {
                Logger = new TestRedisLogger()
            };
            var          key    = _fixture.FormatKey($"{Guid.NewGuid()}TagCacheTests:Add");
            var          expiry = DateTime.Now.AddSeconds(3);
            const string value  = "Test Value";

            // Assert
            Should.NotThrow(async() => await cache.SetItem(key, value, expiry).ConfigureAwait(false));
        }