public static async Task RemoveAsync_WithRegionsTryGetValue_ReturnFalse(ICache <int, string> cache) { await cache.AddOrUpdateAsync(1, "TestValue1", "region1").ConfigureAwait(false); await cache.AddOrUpdateAsync(1, "TestValue1", "region2").ConfigureAwait(false); await cache.AddOrUpdateAsync(2, "TestValue2", "region1").ConfigureAwait(false); await cache.AddOrUpdateAsync(2, "TestValue2", "region2").ConfigureAwait(false); await cache.RemoveAsync(1, "region1"); var cacheRequestResult1 = await cache.TryGetAsync(1, "region1").ConfigureAwait(false); var cacheRequestResult2 = await cache.TryGetAsync(1, "region2").ConfigureAwait(false); var cacheRequestResult3 = await cache.TryGetAsync(2, "region1").ConfigureAwait(false); var cacheRequestResult4 = await cache.TryGetAsync(2, "region2").ConfigureAwait(false); Assert.False(cacheRequestResult1.EntryExists); Assert.True(cacheRequestResult2.EntryExists); Assert.True(cacheRequestResult3.EntryExists); Assert.True(cacheRequestResult4.EntryExists); }
public static async Task TryGetAsync_KeyExistsWithRegion_ReturnsTrueAndValue(ICache <int, string> cache) { await cache.AddOrUpdateAsync(1, "TestValue", "region1").ConfigureAwait(false); await cache.AddOrUpdateAsync(1, "TestValue2", "region2").ConfigureAwait(false); var cacheRequestResult = await cache.TryGetAsync(1, "region1").ConfigureAwait(false); Assert.True(cacheRequestResult.EntryExists); Assert.Equal("TestValue", cacheRequestResult.Value); }
public static async Task TryGetAsync_AddOrUpdateTwoValue_ReturnsLastValue(ICache <int, string> cache) { await cache.AddOrUpdateAsync(1, "TestValue").ConfigureAwait(false); await cache.AddOrUpdateAsync(1, "TestValue1234").ConfigureAwait(false); var cacheRequestResult = await cache.TryGetAsync(1).ConfigureAwait(false); Assert.True(cacheRequestResult.EntryExists); Assert.Equal("TestValue1234", cacheRequestResult.Value); }
public static async Task GetValueAsync_GetExistingWithRegion_ReturnsValue(ICache <int, string> cache) { await cache.AddOrUpdateAsync(1, "TestValue", "region1").ConfigureAwait(false); await cache.AddOrUpdateAsync(1, "TestValue2", "region2").ConfigureAwait(false); var value = await cache.GetValueAsync(1, "region1").ConfigureAwait(false); var value2 = await cache.GetValueAsync(1, "region2").ConfigureAwait(false); Assert.Equal("TestValue", value); Assert.Equal("TestValue2", value2); }
public static async Task ClearAsync_TryGetValue_ReturnFalse(ICache <int, string> cache) { await cache.AddOrUpdateAsync(1, "TestValue1").ConfigureAwait(false); await cache.AddOrUpdateAsync(2, "TestValue2").ConfigureAwait(false); await cache.ClearAsync().ConfigureAwait(false); var cacheRequestResult1 = await cache.TryGetAsync(1).ConfigureAwait(false); var cacheRequestResult2 = await cache.TryGetAsync(2).ConfigureAwait(false); Assert.False(cacheRequestResult1.EntryExists); Assert.False(cacheRequestResult2.EntryExists); }
public static async Task TryGetAsync_AfterExpirationTimeSpan_ReturnsFalse(ICache <int, string> cache) { var expirationPolicy = A.Fake <ICacheExpirationPolicy>(); A.CallTo(() => expirationPolicy.ExpirationMode).Returns(CacheExpirationMode.SlidingTimeSpan); A.CallTo(() => expirationPolicy.SlidingTimeSpan).Returns(TimeSpan.FromMilliseconds(50)); await cache.AddOrUpdateAsync(1, "TestValue", expirationPolicy).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); Assert.False(cache.TryGet(1, out _)); }
public static async Task TryGetAsync_AfterExpiration_ReturnsFalse(ICache <int, string> cache) { var expirationPolicy = A.Fake <ICacheExpirationPolicy>(); A.CallTo(() => expirationPolicy.ExpirationMode).Returns(CacheExpirationMode.AbsoluteDateTime); var expirationDateTime = DateTime.Now; A.CallTo(() => expirationPolicy.AbsoluteDateTime).Returns(expirationDateTime); await cache.AddOrUpdateAsync(1, "TestValue", expirationPolicy).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); Assert.False(cache.TryGet(1, out _)); }
public static async Task GetValueAsync_KeyExists_ReturnOldValue(ICache <int, string> cache) { var getValueCalled = 0; await cache.AddOrUpdateAsync(1, "TestValue").ConfigureAwait(false); var value = await cache.GetOrAddAsync(1, () => { getValueCalled++; return("DefaultValue"); }).ConfigureAwait(false); var secondValue = await cache.GetValueAsync(1).ConfigureAwait(false); Assert.Equal("TestValue", value); Assert.Equal("TestValue", secondValue); Assert.Equal(0, getValueCalled); }