public void Create_FromFailedInvocation_IsOk() { _descr.Category = ErrorCategory.FailedInvocation; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <InvocationException>(ex); }
public void Create_FromNoFileAccess_IsOk() { _descr.Category = ErrorCategory.NoFileAccess; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <FileException>(ex); }
public void Create_FromMisconfiguration_IsOk() { _descr.Category = ErrorCategory.Misconfiguration; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <ConfigException>(ex); }
public void Create_FromNoResponse_IsOk() { _descr.Category = ErrorCategory.NoResponse; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <ConnectionException>(ex); }
public void Create_FromInternal_IsOk() { _descr.Category = ErrorCategory.Internal; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <InternalException>(ex); }
public void Create_FromUnknown_IsOk() { _descr.Category = ErrorCategory.Unknown; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <UnknownException>(ex); }
public void Create_FromNotFound_IsOk() { _descr.Category = ErrorCategory.NotFound; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <NotFoundException>(ex); }
public void Create_FromConflict_IsOk() { _descr.Category = ErrorCategory.Conflict; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <ConflictException>(ex); }
public void Create_FromDefault_IsOk() { _descr.Category = "any_other"; var ex = ApplicationExceptionFactory.Create(_descr); CheckProperties(ex); Assert.IsType <UnknownException>(ex); Assert.Equal(_descr.Category, ex.Category); Assert.Equal(_descr.Status, ex.Status); }
/// <summary> /// Calls a remote method via gRPC commadable protocol. /// </summary> /// <typeparam name="T">the class type</typeparam> /// <param name="name">a name of the command to call.</param> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <param name="requestEntity">body object.</param> /// <returns>result of the command.</returns> public async Task <T> CallCommandAsync <T>(string name, string correlationId, object requestEntity) where T : class { var method = _name + '.' + name; var request = new InvokeRequest { Method = method, CorrelationId = correlationId, ArgsEmpty = requestEntity == null, ArgsJson = requestEntity == null ? null : JsonConverter.ToJson(requestEntity) }; InvokeReply response; var timing = Instrument(correlationId, method); try { response = await CallAsync <InvokeRequest, InvokeReply>("invoke", request); } catch (Exception ex) { InstrumentError(correlationId, method, ex); throw ex; } finally { timing.EndTiming(); } // Handle error response if (response.Error != null) { var errorDescription = ObjectMapper.MapTo <Commons.Errors.ErrorDescription>(response.Error); throw ApplicationExceptionFactory.Create(errorDescription); } // Handle empty response if (response.ResultEmpty || response.ResultJson == null) { return(null); } // Handle regular response var result = JsonConverter.FromJson <T>(response.ResultJson); return(result); }
public void Shutdowns() { if (this._mode == "null" || this._mode == "nullpointer") { throw new NullReferenceException("nullpointer"); } else if (this._mode == "zero" || this._mode == "dividebyzero") { var crash = 0 / 100; } else if (this._mode == "exit" || this._mode == "processexit") { Environment.Exit(1); } else { var err = ApplicationExceptionFactory.Create(new ErrorDescription() { Category = "test", Message = "Crash test exception" }); throw err; } }
private async Task <HttpResponseMessage> ExecuteRequestAsync( string correlationId, HttpMethod method, Uri uri, HttpContent content = null) { if (_client == null) { throw new InvalidOperationException("REST client is not configured"); } // Set headers foreach (var key in _headers.Keys) { if (!_client.DefaultRequestHeaders.Contains(key)) { _client.DefaultRequestHeaders.Add(key, _headers[key]); } } HttpResponseMessage result = null; var retries = Math.Min(1, Math.Max(5, _retries)); while (retries > 0) { try { if (method == HttpMethod.Get) { result = await _client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); } else if (method == HttpMethod.Post) { result = await _client.PostAsync(uri, content); } else if (method == HttpMethod.Put) { result = await _client.PutAsync(uri, content); } else if (method == HttpMethod.Delete) { result = await _client.DeleteAsync(uri); } #if !NETSTANDARD2_0 else if (method == HttpMethod.Patch) { result = await _client.PatchAsync(uri, content); } #endif else { throw new InvalidOperationException("Invalid request type"); } retries = 0; } catch (HttpRequestException ex) { retries--; if (retries > 0) { throw new ConnectionException(correlationId, null, "Unknown communication problem on REST client", ex); } else { _logger.Trace(correlationId, $"Connection failed to uri '{uri}'. Retrying..."); } } } if (result == null) { throw ApplicationExceptionFactory.Create(ErrorDescriptionFactory.Create( new UnknownException(correlationId, $"Unable to get a result from uri '{uri}' with method '{method}'"))); } if ((int)result.StatusCode >= 400) { var responseContent = await result.Content.ReadAsStringAsync(); ErrorDescription errorObject = null; try { errorObject = JsonConverter.FromJson <ErrorDescription>(responseContent); } finally { if (errorObject == null) { errorObject = ErrorDescriptionFactory.Create(new UnknownException(correlationId, $"UNKNOWN_ERROR with result status: '{result.StatusCode}'", responseContent)); } } throw ApplicationExceptionFactory.Create(errorObject); } return(result); }