private static void InvokeOnceFailWithUnexceptedException(bool useExceptionName, bool isDelay)
        {
            TestSleepHandler   testSleepHandler = new TestSleepHandler();
            ITestRemoteService rs = GetRemoteService(3, useExceptionName, isDelay, testSleepHandler);

            try
            {
                rs.DoTransfer2();
                Assert.Fail("Should have failed.");
            }
            catch (ArgumentException)
            {
            }
        }
        private static void InvokeOncePassOnceFail(bool useExceptionName, bool isDelay)
        {
            TestSleepHandler   testSleepHandler = new TestSleepHandler();
            ITestRemoteService rs = GetRemoteService(2, useExceptionName, isDelay, testSleepHandler);

            rs.DoTransfer();
            AssertSleepsAndReset(testSleepHandler, 2, isDelay);

            rs = GetRemoteService(3, useExceptionName, isDelay, testSleepHandler);
            try
            {
                rs.DoTransfer();
                Assert.Fail("Should have failed.");
            } catch (ArithmeticException)
            {
                // they maximum retry count is 3, thus only 2 sleep calls
                AssertSleepsAndReset(testSleepHandler, 2, isDelay);
            }
        }
        private static ITestRemoteService GetRemoteService(int numFailures, bool usingExceptionName, bool isDelay, TestSleepHandler testSleepHandler)
        {
            TestRemoteService remoteService = new TestRemoteService();

            remoteService.NumFailures = numFailures;
            ProxyFactory factory = new ProxyFactory(remoteService);

            RetryAdvice retryAdvice = new RetryAdvice(new RetryAdvice.SleepHandler(testSleepHandler.Sleep));

            if (usingExceptionName)
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x rate (1*#n + 0.5)";
                }
            }
            else
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x rate (1*#n + 0.5)";
                }
            }
            retryAdvice.AfterPropertiesSet();
            factory.AddAdvice(retryAdvice);
            ITestRemoteService rs = factory.GetProxy() as ITestRemoteService;

            Assert.IsNotNull(rs);
            return(rs);
        }