コード例 #1
0
        public void You_cannot_retry_an_operation_where_a_non_idempotent_child_operation_has_executed()
        {
            var operation = new FakeOperation(new IdempotentOperation(), new FakeOperation {
                ThrowOnExecute = new Exception(), ErrorCount = 1
            });
            var sut = new RetryBehavior(1, TimeSpan.Zero);

            sut.AttachTo(operation);

            Assert.Throws <Exception>(() => sut.Execute());
        }
コード例 #2
0
        public void Failing_operations_are_retried_a_specific_number_of_times()
        {
            var operation = new FakeOperation {
                ThrowOnExecute = new Exception(), ErrorCount = 2
            };
            var sut = new RetryBehavior(1, TimeSpan.Zero);

            sut.AttachTo(operation);

            Assert.Throws <Exception>(() => sut.Execute());
        }
コード例 #3
0
        public void Failing_operations_are_retried()
        {
            var operation = new FakeOperation {
                ThrowOnExecute = new Exception(), ErrorCount = 1
            };
            var sut = new RetryBehavior(1, TimeSpan.Zero);

            sut.AttachTo(operation);

            sut.Execute();
        }
コード例 #4
0
        public void When_retry_exception_types_are_specified_errors_of_different_types_will_not_be_retried()
        {
            var operation = new FakeOperation {
                ThrowOnExecute = new NullReferenceException(), ErrorCount = 1
            };
            var sut = new RetryBehavior(1, TimeSpan.Zero, typeof(InsufficientMemoryException));

            sut.AttachTo(operation);

            Assert.Throws <NullReferenceException>(() => sut.Execute());
        }
コード例 #5
0
        public void When_retry_exception_types_are_specified_errors_of_sub_types_will_be_retried()
        {
            var operation = new FakeOperation {
                ThrowOnExecute = new ArgumentNullException(), ErrorCount = 1
            };
            var sut = new RetryBehavior(1, TimeSpan.Zero, typeof(ArgumentException));

            sut.AttachTo(operation);

            sut.Execute();
        }
コード例 #6
0
        public void Retries_are_delayed_the_specified_duration()
        {
            var operation = new FakeOperation {
                ThrowOnExecute = new Exception(), ErrorCount = 1
            };
            var sut = new RetryBehavior(1, TimeSpan.FromSeconds(5));

            sut.AttachTo(operation);
            var before = Time.OffsetUtcNow;

            sut.Execute();

            var duration = Time.OffsetUtcNow - before;

            Assert.Equal(TimeSpan.FromSeconds(5), duration);
        }