public void RetryExceptionConstructorTest4() { string errorMessage = "This is an error message."; RetryException target = new RetryException(errorMessage); Assert.AreEqual(target.Message, errorMessage); }
public void RetryExceptionConstructorTest3() { string message = "Retry Policy Exception was raised."; RetryException target = new RetryException(); Assert.AreEqual(target.Message, message); }
public void RetryExceptionConstructorTest5() { string errorMessage = "This is an error message."; System.Exception innerException = new ArgumentNullException(); RetryException target = new RetryException(errorMessage, innerException); Assert.AreEqual(target.Message, errorMessage); Assert.ReferenceEquals(target.InnerException, innerException); }
public void RetryExceptionConstructorTest() { string errorMessage = "Unauthorized"; string errorCode = "401"; string source = "Intuit.Ipp.Test"; RetryException target = new RetryException(errorMessage, errorCode, source); Assert.AreEqual(target.Message, errorMessage); Assert.AreEqual(target.ErrorCode, errorCode); Assert.AreEqual(target.Source, source); }
public void RetryExceptionConstructorTest1() { string errorMessage = "Unauthorized"; string errorCode = "401"; string source = "Intuit.Ipp.Test"; System.Exception innerException = new ArgumentNullException(); RetryException target = new RetryException(errorMessage, errorCode, source, innerException); Assert.AreEqual(target.Message, errorMessage); Assert.AreEqual(target.ErrorCode, errorCode); Assert.AreEqual(target.Source, source); Assert.ReferenceEquals(target.InnerException, innerException); }
public static void Do(Action action, int retries, Action <Exception> onException = null) { RetryException ex = null; var attempt = 1; while (true) { try { action(); return; } catch (Exception e) { if (ex == null) { ex = new RetryException(retries, new List <AttemptException>()); } var attemptException = new AttemptException(e, attempt); onException?.Invoke(attemptException); ex.AttemptExceptions.Add(attemptException); attempt++; retries--; if (retries <= 0) { throw ex; } Thread.Sleep(TimeSpan.FromSeconds(10)); } } }
public void RetryExceptionConstructorTest2() { string errorMessage = "Unauthorized"; string errorCode = "401"; string source = "Intuit.Ipp.Test"; System.Exception innerException = new ArgumentNullException(); RetryException target = new RetryException(errorMessage, errorCode, source, innerException); RetryException newTarget = null; using (Stream s = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(s, target); s.Position = 0; // Reset stream position newTarget = (RetryException)formatter.Deserialize(s); } Assert.IsNotNull(newTarget); Assert.AreEqual(newTarget.Message, errorMessage); Assert.AreEqual(newTarget.ErrorCode, errorCode); Assert.AreEqual(newTarget.Source, source); Assert.ReferenceEquals(newTarget.InnerException, innerException); }