private async Task <bool> SimulateFailureAsync(HttpMessage message, bool async)
 {
     if (_trackedRequestMethods.Contains(message.Request.Method))
     {
         if (_delayBetweenAttempts > 0)
         {
             if (async)
             {
                 await Task.Delay(_delayBetweenAttempts);
             }
             else
             {
                 Thread.Sleep(_delayBetweenAttempts);
             }
         }
         _currentInvocationNumber++;
         HostsSetInRequests.Add(message.Request.Uri.Host);
         if (message.Request.Headers.TryGetValue("x-ms-date", out string date))
         {
             DatesSetInRequests.Add(Convert.ToDateTime(date));
         }
         if (_currentInvocationNumber <= _numberOfFailuresToSimulate)
         {
             message.Response = new MockResponse(
                 _simulate404 && message.Request.Uri.Host == _secondaryUri?.Host ? 404 : 429);
             return(true);
         }
     }
     return(false);
 }
Example #2
0
 private bool SimulateFailure(HttpMessage message)
 {
     if (TrackedRequestMethods.Contains(message.Request.Method))
     {
         CurrentInvocationNumber++;
         HostsSetInRequests.Add(message.Request.Uri.Host);
         if (CurrentInvocationNumber <= NumberOfReadFailuresToSimulate)
         {
             message.Response = new MockResponse(Simulate404 && message.Request.Uri.Host == SecondaryUri.Host ? 404 : 429);
             return(true);
         }
     }
     return(false);
 }