コード例 #1
0
        public void GetAllExceptionMessages_WithMultipleExceptions_ReturnsJoinedString()
        {
            Exception inner = new Exception(TEST_MESSAGE);
            Exception ex    = new Exception(TEST_MESSAGE, inner);

            Assert.AreEqual(string.Join(" ", TEST_MESSAGE, TEST_MESSAGE), ExceptionUtilities.GetAllExceptionMessages(ex));
        }
コード例 #2
0
        /// <summary>
        /// Sends an HTTP request to the server and handles the response.
        /// </summary>
        /// <param name="verb">The HTTP verb to use for the request.</param>
        /// <param name="urlParameter">Any URL parameters to send.</param>
        /// <param name="bodyParameter">Any body parameters to send.</param>
        /// <returns>The HTTP Response information.</returns>
        /// <exception cref="System.NotImplementedException">Thrown when the HTTP verb given has not been
        /// implemented yet.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when the request was already sent by
        /// the client instance or the URI is invalid.</exception>
        public async Task <HttpResponse> Send(HttpVerb verb, IHttpRequestParameter urlParameter = null, IHttpRequestParameter bodyParameter = null)
        {
            string              fullRequestUrl  = $"{_requestUrl}{ConstructParameterString(urlParameter)}";
            HttpContent         content         = new StringContent(ConstructParameterString(bodyParameter));
            HttpResponseMessage responseMessage = null;

            try
            {
                switch (verb)
                {
                case HttpVerb.DELETE:
                    responseMessage = await _httpClient.DeleteAsync(fullRequestUrl);

                    break;

                case HttpVerb.GET:
                    responseMessage = await _httpClient.GetAsync(fullRequestUrl);

                    break;

                case HttpVerb.POST:
                    responseMessage = await _httpClient.PostAsync(fullRequestUrl, content);

                    break;

                case HttpVerb.PUT:
                    responseMessage = await _httpClient.PutAsync(fullRequestUrl, content);

                    break;

                default:
                    throw new NotImplementedException($"HTTP Verb not implemented: {verb.ToString()}");
                }
            }
            catch (HttpRequestException ex)
            {
                string error = ExceptionUtilities.GetAllExceptionMessages(ex);
                return(new HttpResponse(
                           fullRequestUrl,
                           System.Net.HttpStatusCode.InternalServerError,
                           error,
                           verb
                           ));
            }

            string responseBody = await responseMessage.Content.ReadAsStringAsync();

            return(new HttpResponse(
                       fullRequestUrl,
                       responseMessage.StatusCode,
                       responseBody,
                       verb
                       ));
        }
コード例 #3
0
        public void GetAllExceptionMessages_WithOneException_ReturnsMessage()
        {
            Exception ex = new Exception(TEST_MESSAGE);

            Assert.AreEqual(TEST_MESSAGE, ExceptionUtilities.GetAllExceptionMessages(ex));
        }
コード例 #4
0
 public void GetAllExceptionMessages_WithNullException_ReturnsEmptyString()
 {
     Assert.AreEqual(string.Empty, ExceptionUtilities.GetAllExceptionMessages(null));
 }