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 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 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"); }