public void IsAllowing_WhenAlreadyTripped_DoesntReTripBreaker()
        {
            const long durationMillis = 10000;

            var mockMetrics = CreateMockMetricsWithSnapshot(10, 100); // 10 ops, 100% failing.
            var stats       = new InternallyCountingStats();
            var breaker     = new BreakerBuilder(1, 1, "Test")        // Trip at 1 op, 1% failing.
                              .WithMockMetrics(mockMetrics)
                              .WithWaitMillis(durationMillis)
                              .WithStats(stats)
                              .Create();

            breaker.IsAllowing(); // Trip the breaker.
            Assert.Equal(1, stats.ServicesAndStates.Count(ss => ss.Service == "mjolnir breaker Test" && ss.State == "Tripped"));

            breaker.IsAllowing(); // Make another call, which should bail immediately (and not re-trip).

            // Best way to test this right now is to make sure we don't fire a stat for the state change.
            Assert.Equal(1, stats.ServicesAndStates.Count(ss => ss.Service == "mjolnir breaker Test" && ss.State == "Tripped"));
        }
        public void IsAllowing_WhenAlreadyTripped_DoesntReTripBreaker()
        {
            const long durationMillis = 10000;

            var mockMetrics = CreateMockMetricsWithSnapshot(10, 100); // 10 ops, 100% failing.
            var stats = new InternallyCountingStats();
            var metricEvents = new Mock<IMetricEvents>();
            var breaker = new BreakerBuilder(1, 1, "Test") // Trip at 1 op, 1% failing.
                .WithMockMetrics(mockMetrics)
                .WithWaitMillis(durationMillis)
                .WithStats(stats)
                .WithMetricEvents(metricEvents.Object)
                .Create();
            breaker.IsAllowing(); // Trip the breaker.
            Assert.Equal(1, stats.ServicesAndStates.Count(ss => ss.Service == "mjolnir breaker Test" && ss.State == "Tripped"));
            metricEvents.Verify(m => m.BreakerTripped("Test"));
            metricEvents.ResetCalls();

            breaker.IsAllowing(); // Make another call, which should bail immediately (and not re-trip).

            // Best way to test this right now is to make sure we don't fire a stat for the state change.
            Assert.Equal(1, stats.ServicesAndStates.Count(ss => ss.Service == "mjolnir breaker Test" && ss.State == "Tripped"));
            metricEvents.Verify(m => m.BreakerTripped(It.IsAny<string>()), Times.Never);
        }