コード例 #1
0
        public void Set_Throws_WhenPastOffsetExpirationDate()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            Func <Task> action = async() => await redcache.Set(key, "value", DateTimeOffset.UtcNow.AddDays(-1));

            // Assert
            action.Should().Throw <ArgumentException>().WithMessage("Expiration date must be a future date*");
        }
コード例 #2
0
        public async Task Get_WhenAccessingNonexistentKey_ReturnsNull()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            var cached = await redcache.Get <string>(key);

            // Assert
            cached.IsNone.Should().BeTrue();
        }
コード例 #3
0
        public void Set_Throws_WhenNegativeSlidingExpiration()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            Func <Task> action = async() => await redcache.Set(key, "value", TimeSpan.FromSeconds(-1));

            // Assert
            action.Should().Throw <ArgumentException>().WithMessage("Expiration must be a positive value*");
        }
コード例 #4
0
        public async Task Exists_WhenAccessingNonexistentKey_ReturnsFalse()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            var keyExists = await redcache.Exists(key);

            // Assert
            keyExists.Should().BeFalse();
        }
コード例 #5
0
        public async Task GetOrSet_WhenAccessingNonexistentKeyWithSetter_ReturnsSetterValue()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            var cachedValue = await redcache.GetOrSet(key, () => "value");

            // Assert
            cachedValue.Should().Be("value");
        }
コード例 #6
0
        public async Task Serilize_SimpleObject(string serilizerName)
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, SerializerFactory(serilizerName));
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key, "value");

            var cached = await redcache.Get <string>(key);

            // Assert
            cached.Value.Should().Be("value");
        }
コード例 #7
0
        public async Task GetList_WhenPagerIsSpecified_ReturnsListPage(int from, int to, int[] expectedList)
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.AppendList(key, Enumerable.Range(1, 100).ToArray());

            var cachedList = await redcache.GetList <int>(key, from..to);

            // Assert
            cachedList.Should().Equal(expectedList);
        }
コード例 #8
0
        public async Task Set_Then_Get_WhenAccessingKey_ReturnsItsValue()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key, "value");

            var cached = await redcache.Get <string>(key);

            // Assert
            cached.Value.Should().Be("value");
        }
コード例 #9
0
        public async Task Serializes_ComplexObject(string serilizerName)
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, SerializerFactory(serilizerName));
            var key      = _fixture.GetRandomKey();
            var person   = _faker.GenerateOne();

            // Act
            await redcache.Set(key, person);

            var cached = await redcache.Get <Person>(key);

            // Assert
            cached.Value.Should().BeEquivalentTo(person);
        }
コード例 #10
0
        public async Task GetOrSet_WhenUsedMultipleTimesWithDifferentSetters_ReturnsFirstValue()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            var firstCachedValue = await redcache.GetOrSet(key, () => "value1");

            var secondCachedValue = await redcache.GetOrSet(key, () => "value2");

            // Assert
            firstCachedValue.Should().Be("value1");
            secondCachedValue.Should().Be("value1");
        }
コード例 #11
0
        public async Task Exists_WhenAccessingKeyAfterExpiration_ReturnsFalse()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key, "value", TimeSpan.FromMilliseconds(100));

            await Task.Delay(TimeSpan.FromMilliseconds(101));

            var keyExists = await redcache.Exists(key);

            // Assert
            keyExists.Should().BeFalse();
        }
コード例 #12
0
        public async Task Delete_RemovesKey()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key, "value");

            await redcache.Delete(key);

            var keyExists = await redcache.Exists(key);

            // Assert
            keyExists.Should().BeFalse();
        }
コード例 #13
0
        public async Task Set_Then_Get_WhenAccessingKeyAfterExpiration_ReturnsNull()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key, "value", TimeSpan.FromMilliseconds(100));

            await Task.Delay(TimeSpan.FromMilliseconds(101));

            var cached = await redcache.Get <string>(key);

            // Assert
            cached.Value.Should().BeNull();
        }
コード例 #14
0
        public async Task Append_WhenMultipleItems_AddsAllGivenValueToEndOfList()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key      = _fixture.GetRandomKey();

            // Act
            await redcache.AppendList(key, new[] { "value1", "value2" });

            var cachedList1 = await redcache.GetList <string>(key);

            await redcache.AppendList(key, new[] { "value3", "value4" });

            var cachedList2 = await redcache.GetList <string>(key);

            // Assert
            cachedList1.Should().Equal("value1", "value2");
            cachedList2.Should().Equal("value1", "value2", "value3", "value4");
        }
コード例 #15
0
        public async Task DeleteMultiple_RemovesAllGivenKeys()
        {
            // Arrange
            var redcache = new RedcacheService(_fixture.Multiplexer, _serializer);
            var key1     = _fixture.GetRandomKey();
            var key2     = _fixture.GetRandomKey();

            // Act
            await redcache.Set(key1, "value");

            await redcache.Set(key2, "value");

            await redcache.DeleteMultiple(new[] { key1, key2 });

            var key1Exists = await redcache.Exists(key1);

            var key2Exists = await redcache.Exists(key2);

            // Assert
            key1Exists.Should().BeFalse();
            key2Exists.Should().BeFalse();
        }