public async Task Should_handle_faulted_tasks()
        {
            var didThrow = false;
            UnhandledExceptionEventHandler exHandler = (s, e) =>
            {
                if (e.ExceptionObject is LazyMemoryCacheSpecException)
                    didThrow = true;
            };

            AppDomain.CurrentDomain.UnhandledException += exHandler;
            using (var cache = new LazyMemoryCache<Uri, Data>("endpoints", async key => { throw new LazyMemoryCacheSpecException(); },
                x => x.SlidingWindow(TimeSpan.FromSeconds(5))))
            {
                try
                {
                    await (await cache.Get(new Uri("loopback://localhost"))).Value;
                }
                catch (LazyMemoryCacheSpecException e)
                {
                }

                await cache.Get(new Uri("loopback://localhost"));
                await Task.Delay(5000);
            }
            AppDomain.CurrentDomain.UnhandledException -= exHandler;
            Assert.That(!didThrow);
        }
        public async Task Should_handle_faulted_tasks()
        {
            var didThrow = false;
            UnhandledExceptionEventHandler exHandler = (s, e) =>
            {
                if (e.ExceptionObject is LazyMemoryCacheSpecException)
                {
                    didThrow = true;
                }
            };

            AppDomain.CurrentDomain.UnhandledException += exHandler;
            using (var cache = new LazyMemoryCache <Uri, Data>("endpoints", async key => { throw new LazyMemoryCacheSpecException(); },
                                                               x => x.SlidingWindow(TimeSpan.FromSeconds(5))))
            {
                try
                {
                    await(await cache.Get(new Uri("loopback://localhost"))).Value;
                }
                catch (LazyMemoryCacheSpecException e)
                {
                }

                await cache.Get(new Uri("loopback://localhost"));

                await Task.Delay(5000);
            }
            AppDomain.CurrentDomain.UnhandledException -= exHandler;
            Assert.That(!didThrow);
        }
        public ILog Get(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(_logs.Get(name).Value.Result);
        }
        public async Task Should_store_a_cached_item()
        {
            using (var cache = new LazyMemoryCache<Uri, Data>("endpoints", key => Task.FromResult(new Data {Value = $"The Key: {key}"}),
                x => x.SlidingWindow(TimeSpan.FromSeconds(5))))
            {
                var endpoint = await (await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);

                await Task.Delay(TimeSpan.FromSeconds(2));

                endpoint = await (await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);

                await Task.Delay(TimeSpan.FromSeconds(10));

                endpoint = await (await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);
            }
        }
        public async Task Should_store_a_cached_item()
        {
            using (var cache = new LazyMemoryCache <Uri, Data>("endpoints", key => Task.FromResult(new Data {
                Value = $"The Key: {key}"
            }),
                                                               x => x.SlidingWindow(TimeSpan.FromSeconds(5))))
            {
                var endpoint = await(await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);

                await Task.Delay(TimeSpan.FromSeconds(2));

                endpoint = await(await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);

                await Task.Delay(TimeSpan.FromSeconds(10));

                endpoint = await(await cache.Get(new Uri("loopback://localhost"))).Value;
                Console.WriteLine("Endpoint: {0}", endpoint.Created);
            }
        }