Example #1
0
        public static async Task GetByKeyAsync_WhenCalledTwiceWithSameKey_InvokesFactoryOnlyOnce()
        {
            var counter = 0;
            var cache   = new AsyncCache <string, string, string>((string key, string cache, CancellationToken cancellationToken) =>
            {
                counter++;
                return(Task.FromResult(string.Empty));
            });

            await cache.GetByKeyAsync("a", "cache_ignore").ConfigureAwait(false);

            await cache.GetByKeyAsync("a", "cache_ignore").ConfigureAwait(false);

            Assert.That(counter, Is.EqualTo(1));
        }
Example #2
0
        public static void GetByKeyAsync_GivenNullCache_ThrowsArgumentNullException()
        {
            var cache = new AsyncCache <object, object, object>((object key, object cache, CancellationToken cancellationToken) => Task.FromResult(new object()));

            Assert.That(() => cache.GetByKeyAsync(new object(), null), Throws.ArgumentNullException);
        }