Ejemplo n.º 1
0
        public void GivenDefaultRetryPolicy_WhenCallingMethodWithReturnInRetryMode_ShouldCallServiceThreeTimes()
        {
            // ARRANGE
            var service = _fixture.Fake <IRemoteService>();
            var counter = 0;

            service.MethodWithReturn().Returns(c =>
            {
                counter++;
                if (counter < 3)
                {
                    throw new Exception("Error");
                }

                return(5);
            });

            // ACT
            var actual = service.ExecuteWithPolicy(s => s.MethodWithReturn(),
                                                   PolicyFor.RetryPolicy <Exception>(new PolicyRetryOptions()));

            // ASSERT
            service.Received(3).MethodWithReturn();
            actual.Should().Be(5);
        }
Ejemplo n.º 2
0
        public void GivenDefaultRetryPolicy_WhenCallingVoidMethodInRetryMode_ShouldCallServiceThreeTimes()
        {
            // ARRANGE
            var service = _fixture.Fake <IRemoteService>();
            var counter = 0;

            service.When(m => m.Method()).Do(c =>
            {
                counter++;
                if (counter < 3)
                {
                    throw new Exception("Error");
                }
            });

            // ACT
            service.ExecuteWithPolicy(s => s.Method(),
                                      PolicyFor.RetryPolicy <Exception>(new PolicyRetryOptions()));

            // ASSERT
            service.Received(3).Method();
        }