/// <summary>Hack around lack of proper way of retrieving the error code through a property.</summary>
        public static string GetErrorCode(DataServiceRequestException 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 WebRequestTransientErrorDetectionStrategyTestDataServiceRequestException()
        {
            // Unfortunately this exception isn't easy to Mock with an actual error code so just
            // do a basic test
            var exception = new DataServiceRequestException("Simulated DataServiceRequestException");

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

            Assert.IsFalse(actual);
        }
 /// <summary>Hack around lack of proper way of retrieving the error code through a property.</summary>
 public static string GetErrorCode(DataServiceRequestException ex)
 {
     var r = new Regex(@"<code>(\w+)</code>", RegexOptions.IgnoreCase);
     var match = r.Match(ex.InnerException.Message);
     return match.Groups[1].Value;
 }
        public void StorageTransientErrorDetectionStrategyTestDataServiceRequestException()
        {
            List<String> allStorageErrorCodeStrings = GetAllStorageErrorStringConstants();

            StorageTransientErrorDetectionStrategy strategy = new StorageTransientErrorDetectionStrategy();

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

                if (strategy.IsTransient(exception))
                {
                    Assert.IsTrue(SupportedRetryableStorageErrorStrings.Contains(errorString));
                }
                else
                {
                    Assert.IsFalse(SupportedRetryableStorageErrorStrings.Contains(errorString));
                }
            }
        }
        public void ErrorCodeExtraction()
        {
            // HACK: just reproducing the code being tested, no direct linking
            var r = new Regex(@"<code>(\w+)</code>", RegexOptions.IgnoreCase);

            var errorMessage =
            @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
            <error xmlns=""http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"">
              <code>OperationTimedOut</code>
              <message xml:lang=""en-US"">Operation could not be completed within the specified time.
            RequestId:f8e1e934-99ca-4a6f-bca7-e8e5fbd059ea
            Time:2010-01-15T12:37:25.1611631Z</message>
            </error>";

            var ex = new DataServiceRequestException("", new Exception(errorMessage));

            Assert.AreEqual("OperationTimedOut", GetErrorCode(ex));
        }
        private static string GetErrorCode(DataServiceRequestException ex)
        {
            if (ex != null && ex.InnerException != null)
            {
                var regEx = new Regex(@"<code>(\w+)</code>", RegexOptions.IgnoreCase);
                var match = regEx.Match(ex.InnerException.Message);

                return match.Groups[1].Value;
            }
            else
            {
                return null;
            }
        }
        protected static string GetErrorCode(DataServiceRequestException ex)
        {
            if (ex != null && ex.InnerException != null)
            {
                var match = errorCodeRegex.Match(ex.InnerException.Message);

                return match.Groups[1].Value;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// Gets the error code string from the exception.
        /// </summary>
        /// <param name="ex">The exception that contains the error code as a string inside the message.</param>
        /// <returns>The error code string.</returns>
        protected static string GetErrorCode(DataServiceRequestException ex)
        {
            string value = null;
            if (ex != null && ex.InnerException != null)
            {
                var match = _errorCodeRegex.Match(ex.InnerException.Message);

                value = match.Groups[1].Value;
            }
            return value;
        }