public void RetriesWhenSqlExceptionIsThrownWithNetworkLevelError()
        {
            int executeCount = 0;

            try
            {
                RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy> retryPolicy = this.retryManager.GetRetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>("Retry 5 times");
                retryPolicy.ExecuteAction(() =>
                {
                    executeCount++;

                    SqlException ex = SqlExceptionCreator.CreateSqlException("A network-related or instance-specific error occurred while establishing a connection to SQL Server.", 10054);
                    throw ex;
                });

                Assert.Fail("Should have thrown SqlException");
            }
            catch (SqlException)
            { }
            catch (Exception)
            {
                Assert.Fail("Should have thrown SqlException");
            }

            Assert.AreEqual(6, executeCount);
        }
        public void DoesNotRetryWhenSqlExceptionIsThrownWithSqlQueryError()
        {
            int executeCount = 0;

            try
            {
                RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy> retryPolicy = this.retryManager.GetRetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>("Retry 5 times");
                retryPolicy.ExecuteAction(() =>
                {
                    executeCount++;

                    SqlException ex = SqlExceptionCreator.CreateSqlException("ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.", 104);
                    throw ex;
                });

                Assert.Fail("Should have thrown SqlException");
            }
            catch (SqlException)
            { }
            catch (Exception)
            {
                Assert.Fail("Should have thrown SqlException");
            }

            Assert.AreEqual(1, executeCount);
        }
        public void RetriesWhenSqlExceptionIsThrownWithTransportLevelError()
        {
            int executeCount = 0;

            try
            {
                RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy> retryPolicy = this.retryManager.GetRetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>("Retry 5 times");
                retryPolicy.ExecuteAction(() =>
                {
                    executeCount++;

                    SqlException ex = SqlExceptionCreator.CreateSqlException("A transport-level error has occurred when sending the request to the server", 10053);
                    throw ex;
                });

                Assert.Fail("Should have thrown SqlException");
            }
            catch (SqlException)
            { }
            catch (Exception)
            {
                Assert.Fail("Should have thrown SqlException");
            }

            Assert.AreEqual(6, executeCount);
        }