public void TripWillTransitionToOpen()
 {
     // Fixture setup
     var fixture = new WcfFixture();
     var sut = fixture.CreateAnonymous<CircuitBreaker>();
     // Exercise system
     fixture.Do((Exception e) => sut.Trip(e));
     // Verify outcome
     Assert.IsAssignableFrom<OpenCircuitState>(sut.State);
     // Teardown
 }
        public void TripWillTransitionToOpen()
        {
            // Fixture setup
            var fixture = new WcfFixture();
            var sut     = fixture.CreateAnonymous <CircuitBreaker>();

            // Exercise system
            fixture.Do((Exception e) => sut.Trip(e));
            // Verify outcome
            Assert.IsAssignableFrom <OpenCircuitState>(sut.State);
            // Teardown
        }
        public void DeleteProductWillTripBreakerWhenAgentThrows()
        {
            // Fixture setup
            var fixture = new WcfFixture();
            var e = fixture.CreateAnonymous<TimeoutException>();

            var breakerMock = fixture.Freeze<Mock<ICircuitBreaker>>();

            fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Throws(e);

            var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>();
            // Exercise system
            try { fixture.Do((int id) => sut.DeleteProduct(id)); }
            // Verify outcome
            catch (TimeoutException) { }
            finally { breakerMock.Verify(b => b.Trip(e)); }
            // Teardown
        }
        public void DeleteProductWillOrchestrateBreakerCorrectly()
        {
            // Fixture setup
            var fixture = new WcfFixture();

            var spy = new List<int>();
            var breakerStub = fixture.Freeze<Mock<ICircuitBreaker>>();
            breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1));
            fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Callback(() => spy.Add(2));
            breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3));

            var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>();
            // Exercise system
            fixture.Do((int id) => sut.DeleteProduct(id));
            // Verify outcome
            Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy));
            // Teardown
        }
Beispiel #5
0
        public void DeleteProductWillRethrow()
        {
            // Fixture setup
            var fixture           = new WcfFixture();
            var expectedException = fixture.CreateAnonymous <InvalidOperationException>();

            fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Throws(expectedException);

            var verified = false;
            var sut      = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>();

            // Exercise system
            try { fixture.Do((int id) => sut.DeleteProduct(id)); }
            // Verify outcome
            catch (InvalidOperationException e) { verified = e == expectedException; }
            finally { Assert.True(verified); }
            // Teardown
        }
Beispiel #6
0
        public void DeleteProductWillTripBreakerWhenAgentThrows()
        {
            // Fixture setup
            var fixture = new WcfFixture();
            var e       = fixture.CreateAnonymous <TimeoutException>();

            var breakerMock = fixture.Freeze <Mock <ICircuitBreaker> >();

            fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Throws(e);

            var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>();

            // Exercise system
            try { fixture.Do((int id) => sut.DeleteProduct(id)); }
            // Verify outcome
            catch (TimeoutException) { }
            finally { breakerMock.Verify(b => b.Trip(e)); }
            // Teardown
        }
Beispiel #7
0
        public void DeleteProductWillOrchestrateBreakerCorrectly()
        {
            // Fixture setup
            var fixture = new WcfFixture();

            var spy         = new List <int>();
            var breakerStub = fixture.Freeze <Mock <ICircuitBreaker> >();

            breakerStub.Setup(cb => cb.Guard()).Callback(() => spy.Add(1));
            fixture.Freeze <Mock <IProductManagementAgent> >().Setup(a => a.DeleteProduct(It.IsAny <int>())).Callback(() => spy.Add(2));
            breakerStub.Setup(b => b.Succeed()).Callback(() => spy.Add(3));

            var sut = fixture.CreateAnonymous <CircuitBreakerProductManagementAgent>();

            // Exercise system
            fixture.Do((int id) => sut.DeleteProduct(id));
            // Verify outcome
            Assert.True(Enumerable.Range(1, 3).SequenceEqual(spy));
            // Teardown
        }
        public void DeleteProductWillRethrow()
        {
            // Fixture setup
            var fixture = new WcfFixture();
            var expectedException = fixture.CreateAnonymous<InvalidOperationException>();
            fixture.Freeze<Mock<IProductManagementAgent>>().Setup(a => a.DeleteProduct(It.IsAny<int>())).Throws(expectedException);

            var verified = false;
            var sut = fixture.CreateAnonymous<CircuitBreakerProductManagementAgent>();
            // Exercise system
            try { fixture.Do((int id) => sut.DeleteProduct(id)); }
            // Verify outcome
            catch (InvalidOperationException e) { verified = e == expectedException; }
            finally { Assert.True(verified); }
            // Teardown
        }