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*"); }
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(); }
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*"); }
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(); }
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"); }
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"); }
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); }
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"); }
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); }
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"); }
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(); }
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(); }
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(); }
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"); }
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(); }