Exemple #1
0
            public void CreatesAStringWithBodyAndNoHeaders()
            {
                string body                  = "Body.";
                var    endpoint              = new Uri("https://www.some.url");
                var    method                = new HttpMethod("GET");
                var    request               = new Request("", endpoint, new HttpHeader[0], method);
                var    response              = new Response(body, false, "plain/text", new List <KeyValuePair <string, IEnumerable <string> > >(), HttpStatusCode.InternalServerError);
                var    exception             = new InternalServerErrorException(request, response, "Custom message.");
                var    expectedSerialization = $"InternalServerErrorException (Custom message.) for request {method} {endpoint} with response {{\"status\":\"500 InternalServerError\",\"headers\":{{}},\"body\":\"{body}\"}}";

                var serialized = exception.ToString();

                serialized.Should().Be(expectedSerialization);
            }
Exemple #2
0
        /// <summary>
        /// Monta InternalServerErrorException e imprimir um log de erro de acordo com os parâmetros.
        /// </summary>
        /// <param name="exception">Exceção lançada.</param>
        /// <param name="logger">Objeto para impressão da mensagem de log.</param>
        /// <param name="code">Código do erro à ser mostrado na mensagem.</param>
        /// <param name="message">Mensagem complementar à ser mostrada no log e na exceção.</param>
        /// <param name="args">Uma lista de objetos que contém um ou mais objetos para formatar com a mensagem.</param>
        /// <returns>Exceção do tipo <see cref="InternalServerErrorException"/> com a mensagem gerada.</returns>
        public static InternalServerErrorException ToInternalServerException(
            this Exception exception,
            ILogger logger,
            string code,
            string message,
            params object[] args)
        {
            var newEx = new InternalServerErrorException(message, code, exception);

            // ReSharper disable once TemplateIsNotCompileTimeConstantProblem
            logger.LogError(exception, newEx.ToString());

            return(newEx);
        }
            public void CreatesAStringWithBodyAndNoHeaders()
            {
                string body = "Body.";
                var endpoint = new Uri("https://www.some.url");
                var method = new HttpMethod("GET");
                var request = new Request("", endpoint, new HttpHeader[0], method);
                var response = new Response(body, false, "application/json", new List<KeyValuePair<string, IEnumerable<string>>>(), HttpStatusCode.InternalServerError);
                var exception = new InternalServerErrorException(request, response, "Custom message.");
                var expectedSerialization = $"ApiException for request {method} {endpoint}: Response: (Status: [500 InternalServerError]) (Headers: []) (Body: {body}) (Message: Custom message.)";

                var serialized = exception.ToString();

                serialized.Should().Be(expectedSerialization);
            }
            public void CreatesAStringWithBodyAndWithHeaders()
            {
                string body                  = "Body of a response with headers.";
                var    endpoint              = new Uri("https://www.some.url/endpoint");
                var    method                = new HttpMethod("GET");
                var    request               = new Request("", endpoint, new HttpHeader[0], method);
                var    headers               = new[] { new KeyValuePair <string, IEnumerable <string> >("abc", new[] { "a", "b", "c" }) };
                var    response              = new Response(body, false, "application/json", headers, HttpStatusCode.InternalServerError);
                var    exception             = new InternalServerErrorException(request, response, "Custom message.");
                var    expectedSerialization = $"InternalServerErrorException for request {method} {endpoint}: Response: (Status: [500 InternalServerError]) (Headers: ['abc': ['a', 'b', 'c']]) (Body: {body}) (Message: Custom message.)";

                var serialized = exception.ToString();

                serialized.Should().Be(expectedSerialization);
            }