public void CircuitBreaker_ReturnsOnOpenCircuit()
        {
            var circuitBreaker = new SimpleCircuitBreaker();
            var cache          = new CircuitBreakingFluentDictionaryCache(circuitBreaker)
                                 .WithSource(new CacheMe());

            CacheStrategy <double> cacheStrategy = cache.Method(r => r.DoWork());


            Assert.IsFalse(circuitBreaker.IsBroken, "circuit should be open");

            CachedValue <double> result1 = cacheStrategy.Get();

            Assert.IsNotNull(result1, "because the circuit is open, we should have gotten a result");

            CachedValue <double> result2 = cacheStrategy.Get();

            Assert.IsNotNull(result2, "because the circuit is open, we should have gotten a result");
            Assert.AreEqual(result1.Version, result2.Version, "the first and 2nd results should be the same");
        }
        public void CircuitBreaker_NullOnBrokenCircuit()
        {
            var circuitBreaker = new SimpleCircuitBreaker();
            var cache          = new CircuitBreakingFluentDictionaryCache(circuitBreaker)
                                 .WithSource(new CacheMe());

            CacheStrategy <double> cacheStrategy = cache.Method(r => r.DoWork());


            Assert.IsFalse(circuitBreaker.IsBroken, "circuit should be open");

            CachedValue <double> result1 = cacheStrategy.Get();

            Assert.IsNotNull(result1, "because the circuit is open, we should have gotten a result");

            circuitBreaker.TryBreak(new InvalidOperationException());
            Assert.IsTrue(circuitBreaker.IsBroken, "circuit should be closed");

            CachedValue <double> result2 = cacheStrategy.Get();

            Assert.IsNull(result2, "because the circuit is closed, we should have gotten no result");
        }