Exemplo n.º 1
0
        // HACK: just duplicating the other overload of 'GetErrorCode'
        /// <summary>Hack around lack of proper way of retrieving the error code through a property.</summary>
        public static string GetErrorCode(DataServiceQueryException ex)
        {
            var o = JsonConvert.DeserializeObject<ODataWrapper>(ex.InnerException.Message);

            if (o == null || o.Error == null || o.Error.Code == null)
                return string.Empty;

            return o.Error.Code;
        }
        public void WebRequestTransientErrorDetectionStrategyTestDataServiceQueryException()
        {
            // Unfortunately this exception isn't easy to Mock with an actual error code so just
            // do a basic test
            var exception = new DataServiceQueryException("Simulated DataServiceQueryException");

            bool actual = new WebRequestTransientErrorDetectionStrategy().IsTransient(exception);

            Assert.IsFalse(actual);
        }
        public void StorageTransientErrorDetectionStrategyDataServiceClientExceptionTestByErrorString()
        {
            List<String> allStorageErrorCodeStrings = GetAllStorageErrorStringConstants();

            StorageTransientErrorDetectionStrategy strategy = new StorageTransientErrorDetectionStrategy();

            foreach (string errorString in allStorageErrorCodeStrings)
            {
                var innerException = new Exception(FormatErrorString(errorString));
                var exception = new DataServiceQueryException("Simulated DataServiceQueryException", innerException);

                if (strategy.IsTransient(exception))
                {
                    Assert.IsTrue(SupportedRetryableStorageErrorStrings.Contains(errorString));
                }
                else
                {
                    Assert.IsFalse(SupportedRetryableStorageErrorStrings.Contains(errorString));
                }
            }
        }
 // HACK: just duplicating the other overload of 'GetErrorCode'
 /// <summary>Hack around lack of proper way of retrieving the error code through a property.</summary>
 public static string GetErrorCode(DataServiceQueryException ex)
 {
     var r = new Regex(@"<code>(\w+)</code>", RegexOptions.IgnoreCase);
     var match = r.Match(ex.InnerException.Message);
     return match.Groups[1].Value;
 }
 private static bool IsResourceNotFoundError(DataServiceQueryException ex)
 {
     return ex.InnerException is DataServiceClientException &&
         ((DataServiceClientException)ex.InnerException).StatusCode == 404;
 }