コード例 #1
0
		public void NonTransientExceptionDoesNotRetry()
		{
			// all exceptions are bad
			_mockRetryStrategy.Setup(r => r.IsTransientException(It.IsAny<Exception>())).Returns(false);

			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.IsFalse(Retries > 0);
		}
コード例 #2
0
		public void ExecuteStoredProcWithTVPThroughReliableConnection()
		{
			ReliableConnection retry = new ReliableConnection(_connection, RetryStrategy);

			try
			{
				retry.ExecuteSql("CREATE TYPE [Int32Table] AS TABLE ([Value] [int])");
				retry.ExecuteSql("CREATE PROC InsightTestProc (@Value Int32Table READONLY) AS SELECT * FROM @Value");

				// the ListParameterHelper.AddEnumerableClassParameters code looks specifically for SqlCommand. 
				// This test ensures that reliable connections work with this.
				var result = retry.Query<int>("InsightTestProc", new int[] { 1, 2, 3, 4, 5 });

				Assert.AreEqual(5, result.Count());
			}
			finally
			{
				Cleanup("IF EXISTS (SELECT * FROM sys.objects WHERE name = 'InsightTestProc') DROP PROCEDURE [InsightTestProc]");
				Cleanup("IF EXISTS (SELECT * FROM sys.types WHERE name = 'Int32Table') DROP TYPE [Int32Table]");
			}
		}
コード例 #3
0
		public void StoredProcedureParametersDetectedWithReliableSqlConnection()
		{
			ReliableConnection retry = new ReliableConnection(_connection, RetryStrategy);

			// the SqlCommand.DeriveParameters code looks specifically for SqlCommand. 
			// This test ensures that reliable connections work with this.

			using (IDbTransaction t = retry.BeginTransaction())
			{
				retry.ExecuteSql("CREATE PROC InsightTestProc (@Value int = 5) AS SELECT Value=@Value", transaction: t);

				int result = retry.Query<int>("InsightTestProc", new { Value = 1 }, transaction: t).First();

				Assert.AreEqual(1, result);
			}
		}
コード例 #4
0
		public void MaxRetryCountCapsNumberOfRetries()
		{
			int retries = 0;
			RetryStrategy.Retrying += (sender, re) => { retries++; };
			RetryStrategy.MaxRetryCount = 5;

			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.AreEqual(5, retries);
		}
コード例 #5
0
		public void BadOpenPerformsRetry()
		{
			// try a bad connection
			SqlConnectionStringBuilder b = new SqlConnectionStringBuilder(_connection.ConnectionString);
			b.InitialCatalog = "bad";
			ReliableConnection<SqlConnection> retry = new ReliableConnection<SqlConnection>(b.ConnectionString, RetryStrategy);

			try
			{
				retry.Query("SELECT 1");
			}
			catch
			{
			}

			Assert.IsTrue(Retries > 0);
		}
コード例 #6
0
		public void ExecuteStoredProcWithTVPThroughReliableConnection()
		{
			using (ReliableConnection retry = new ReliableConnection<SqlConnection>(ConnectionString, RetryStrategy))
			{
				retry.Open();

				// the ListParameterHelper.AddEnumerableClassParameters code looks specifically for SqlCommand. 
				// This test ensures that reliable connections work with this.
				var result = retry.Query<int>("ReflectInt32Table", new int[] { 1, 2, 3, 4, 5 });

				Assert.AreEqual(5, result.Count());
			}
		}