public void CustomMediaRetryPolicyTestExceededMaxRetryAttempts()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetBlobStorageClientRetryPolicy();

            int exceptionCount = 4;
            int expected = 10;
            //This is the new exception included for retrypolicy in the customretrypolicy
            var fakeException = new IOException("CustomRetryPolicyException");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                target.ExecuteAction(func);
            }
            catch (AggregateException ax)
            {
                IOException x = (IOException)ax.Flatten().InnerException;
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                //Exception is retried only for max retrial attempts,
                //In this case there are max of 2 attempts for blob retry policy.
                Assert.AreEqual(exceptionCount, 1);
                throw;
            }
        }
        public void CustomMediaRetryPolicyTestExecuteActionRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 3;
            int expected = 10;
            //This is the new exception included for retrypolicy in the customretrypolicy
            var fakeException = new IOException("CustomRetryPolicyException");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            int actual = target.ExecuteAction(func);
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(0, exceptionCount);
        }
 public void CustomMediaRetryPolicyTestExecuteAsyncTrivial()
 {
     MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetSaveChangesRetryPolicy(null);
     int expected = 10;
     var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => expected));
     Assert.AreEqual(expected, task.Result);
 }
        public void CustomMediaRetryPolicyTestExecuteAsyncRetry()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new IOException("Test CustomMediaRetryPolicyTestExecuteAsyncRetry");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => func()));
            Assert.AreEqual(expected, task.Result);
            Assert.AreEqual(0, exceptionCount);
        }
        public void CustomMediaRetryPolicyTestExecuteAsyncNonTransient()
        {
            MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetSaveChangesRetryPolicy(null);

            int exceptionCount = 2;
            int expected = 10;
            var fakeException = new InvalidOperationException("Test CustomMediaRetryPolicyTestExecuteAsyncRetry");

            Func<int> func = () =>
            {
                if (--exceptionCount > 0) throw fakeException;
                return expected;
            };

            try
            {
                var task = target.ExecuteAsync(() => Task.Factory.StartNew<int>(() => func()));
                task.Wait();
                var result = task.Result;
            }
            catch (AggregateException ax)
            {
                InvalidOperationException x = (InvalidOperationException)ax.Flatten().InnerException;
                Assert.AreEqual(1, exceptionCount);
                Assert.AreEqual(fakeException, x);
                throw x;
            }

            Assert.Fail("Expected exception");
        }
 public void CustomMediaRetryPolicyTestExecuteActionTrivial()
 {
     MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetSaveChangesRetryPolicy(null);
     int expected = 10;
     Func<int> func = () => expected;
     int actual = target.ExecuteAction(func);
     Assert.AreEqual(expected, actual);
 }