public void ShouldStopIfDeadlockHasBeenFixed()
        {
            SqlExceptionHelper.EmulateDeadlock = true;
            try
            {
                int invokesCount = 0;

                Action action = () =>
                {
                    invokesCount++;
                    if (invokesCount < 2)
                    {
                        throw new InvalidOperationException();
                    }
                };

                var attribute = new RetryOnDeadlockAttribute { RetryAttemptsCount = 3 };
                attribute.Apply(null, action);

                Assert.AreEqual(2, invokesCount);
            }
            catch (Exception)
            {
                SqlExceptionHelper.EmulateDeadlock = false;
                throw;
            }
        }
        public void ShouldInvokeOnceWhenNoExceptionsHasBeenThrown()
        {
            var attribute = new RetryOnDeadlockAttribute();
            int invokesCount = 0;
            Action action = () => invokesCount++;
            attribute.Apply(null, action);

            Assert.AreEqual(1, invokesCount);
        }
        public void ShouldInvokeManyTimesIfDeadlockExceptionHasBeenEncountered()
        {
            SqlExceptionHelper.EmulateDeadlock = true;
            try
            {
                int invokesCount = 0;

                Action action = () =>
                {
                    invokesCount++;
                    throw new InvalidOperationException();
                };

                var attribute = new RetryOnDeadlockAttribute { RetryAttemptsCount = 3 };
                attribute.Apply(null, action);

                Assert.AreEqual(3, invokesCount);
            }
            catch (Exception)
            {
                SqlExceptionHelper.EmulateDeadlock = false;
                throw;
            }
        }