Ejemplo n.º 1
0
        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");
        }