Ejemplo n.º 1
0
        public async Task InvokeSuccessAsync()
        {
            var instance     = new RetryProxySubject();
            var retryTest    = new CanRetryProxySubjectException();
            var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(5));
            var retryProxy   = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest);
            var result       = await retryProxy.SucceedAsync();

            Assert.AreEqual("succeed", result);
        }
Ejemplo n.º 2
0
        public void Create_OptionsNull()
        {
            var instance       = new RetryProxySubject();
            var options        = new RetryOptions(5, TimeSpan.FromSeconds(5));
            var canRetryTester = new CanRetryProxySubjectException();

            try
            {
                var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, null, canRetryTester);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual(nameof(options), ex.ParamName);
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task InvokeFailure_TimeoutExceededAsync()
        {
            var instance     = new RetryProxySubject();
            var retryTest    = new CanRetryProxySubjectException();
            var retryOptions = new RetryOptions(10000, TimeSpan.FromSeconds(1));
            var retryProxy   = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest);

            try
            {
                var result = await retryProxy.FailAsync();
            }
            catch (RetryException ex)
            {
                Assert.IsTrue(ex.InnerException is ProxySubjectException);
                Assert.IsTrue(ex.Duration >= TimeSpan.FromSeconds(1));
                Assert.AreEqual(ex.Attempts, ex.Exceptions.Count);
                throw;
            }
        }
Ejemplo n.º 4
0
        public void InvokeFailure_MaxAttemptsExceeded()
        {
            var instance     = new RetryProxySubject();
            var retryTest    = new CanRetryProxySubjectException();
            var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(60));
            var retryProxy   = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest);

            try
            {
                var result = retryProxy.Fail();
            }
            catch (RetryException ex)
            {
                Assert.IsTrue(ex.InnerException is ProxySubjectException);
                Assert.AreEqual(5, ex.Attempts);
                Assert.AreEqual(ex.Attempts, ex.Exceptions.Count);
                throw;
            }
        }
Ejemplo n.º 5
0
        public async Task InvokeFailure_RetryForbiddenAsync()
        {
            var instance     = new RetryProxySubject();
            var retryTest    = new CanNotRetryProxySubjectException();
            var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(5));
            var retryProxy   = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest);

            //Assert.ThrowsException<RetryNotAllowedException>()
            try
            {
                var result = await retryProxy.FailAsync();
            }
            catch (RetryException ex)
            {
                Assert.IsTrue(ex.InnerException is ProxySubjectException);
                Assert.AreEqual(1, ex.Attempts);
                Assert.AreEqual(ex.Attempts, ex.Exceptions.Count);
                throw;
            }
        }