public async Task WhenPolicyIsSet_PolicyIsAppliedCorrectly(string action, bool applyPolicy) { var policy = Policy.Handle <Exception>().RetryAsync(); var innerCache = new MockDistributedCache <int, int>(); var cache = applyPolicy ? new DistributedCachePollyWrapper <int, int>(innerCache, policy) : new DistributedCachePollyWrapper <int, int>(innerCache); var task = action switch { "tryget" => (Func <Task>)(() => cache.TryGet(1)), "set" => () => cache.Set(1, 1, TimeSpan.FromSeconds(1)), "getmany" => () => cache.GetMany(new[] { 1 }), "setmany" => () => cache.SetMany(new[] { new KeyValuePair <int, int>(1, 1) }, TimeSpan.FromSeconds(1)), "tryremove" => () => cache.TryRemove(1), _ => throw new Exception() }; innerCache.ThrowExceptionOnNextAction(); if (applyPolicy) { await task.Should().NotThrowAsync(); } else { await task.Should().ThrowAsync <Exception>(); } } }
public async Task DeleteAsync_should_prefix_id_with_CacheKeyPrefix() { var distributedCache = new MockDistributedCache(); var messageStore = new DistributedCacheAuthorizationParametersMessageStore(distributedCache, null); await messageStore.DeleteAsync("id"); distributedCache.LastKeyRemoveRequest.Should().Be("DistributedCacheAuthorizationParametersMessageStore-id"); }