public void RwsExceptionHandler_raises_exception_for_401_responses_with_ODM_content() { var responseMessage = new HttpResponseMessage { Content = new StringContent(@"<?xml version=""1.0"" encoding=""utf-8""?> <ODM xmlns:mdsol=""http://www.mdsol.com/ns/odm/metadata"" FileType=""Snapshot"" CreationDateTime=""2013-04-08T10:28:49.578-00:00"" FileOID=""4d13722a-ceb6-4419-a917-b6ad5d0bc30e"" ODMVersion=""1.3"" mdsol:ErrorDescription=""Incorrect login and password combination. [RWS00008]"" xmlns=""http://www.cdisc.org/ns/odm/v1.3"" />", Encoding.UTF8, "text/xml"), StatusCode = System.Net.HttpStatusCode.Unauthorized, RequestMessage = new HttpRequestMessage { Method = HttpMethod.Get } }; try { RwsExceptionHandler.Parse(responseMessage); } catch (RwsException ex) { Assert.AreEqual("Incorrect login and password combination. [RWS00008]", ex.Message); } }
public void RwsExceptionHandler_raises_exception_for_400_responses_with_RWS_content() { var content = new StringContent(@"<Response ReferenceNumber=""0b47fe86-542f-4070-9e7d-16396a5ef08a"" InboundODMFileOID=""Not Supplied"" IsTransactionSuccessful=""0"" ReasonCode=""RWS00092"" ErrorClientResponseMessage=""CRF version not found""> </Response>", Encoding.UTF8, "text/xml"); var responseMessage400 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { Method = HttpMethod.Get } }; try { RwsExceptionHandler.Parse(responseMessage400); } catch (RwsException ex) { Assert.AreEqual("CRF version not found", ex.Message); var errorResponse = ex.ErrorResponse as RwsErrorResponse; Assert.AreEqual("RWS00092", errorResponse.ReasonCode); } }
public void RwsExceptionHandler_raises_exception_for_404_responses_with_html() { var content = new StringContent(@"<!DOCTYPE html> <html> <head> <meta charset=""utf-8"" /> <title>OOPS! Error Occurred. Sorry about this.</title> </head> <body> <h2>OOPS! Error Occurred</h2> </body> </html>", Encoding.UTF8); var responseMessage404 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.NotFound }; try { RwsExceptionHandler.Parse(responseMessage404); } catch (RwsException ex) { Assert.AreEqual("IIS Error", ex.Message); } }
public void RwsExceptionHandler_attaches_a_RwsPostErrorResponse_for_POST_requests() { var content = new StringContent(@"<Response ReferenceNumber=""0b47fe86-542f-4070-9e7d-16396a5ef08a"" InboundODMFileOID=""Not Supplied"" IsTransactionSuccessful=""0"" ReasonCode=""RWS00024"" ErrorOriginLocation=""/ODM/ClinicalData[1]/SubjectData[1]"" SuccessStatistics=""Rave objects touched: Subjects=0; Folders=0; Forms=0; Fields=0; LogLines=0"" ErrorClientResponseMessage=""Subject already exists.""> </Response>", Encoding.UTF8, "text/xml"); var responseMessage400 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { Method = HttpMethod.Post } }; try { RwsExceptionHandler.Parse(responseMessage400); } catch (RwsException ex) { Assert.IsInstanceOfType(ex.ErrorResponse, typeof(RwsPostErrorResponse)); } }
public void RwsExceptionHandler_raises_exception_for_400_responses_with_generic_text() { var content = new StringContent(@"Unknown text."); var responseMessage404 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.BadRequest }; RwsExceptionHandler.Parse(responseMessage404); }
public void RwsExceptionHandler_raises_exception_for_unexpected_status_codes() { var content = new StringContent(@"Whoops, something is wrong."); var responseMessage410 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.Gone }; try { RwsExceptionHandler.Parse(responseMessage410); } catch (RwsException ex) { Assert.AreEqual("Unexpected Status Code (410)", ex.Message); } }
public void RwsExceptionHandler_raises_exception_for_401_responses_with_html() { var content = new StringContent(@"<h2>HTTP Error 401.0 - Unauthorized</h2>"); var responseMessage401 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.Unauthorized }; try { RwsExceptionHandler.Parse(responseMessage401); } catch (RwsException ex) { Assert.AreEqual("Unauthorized.", ex.Message); } }
public void RwsExceptionHandler_raises_exception_for_500_responses() { var content = new StringContent(@"Some error"); var responseMessage500 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.InternalServerError }; try { RwsExceptionHandler.Parse(responseMessage500); } catch (RwsException ex) { Assert.AreEqual("Server Error (500)", ex.Message); } }
public void RwsExceptionHandler_raises_authorization_exception_for_401_responses() { var content = new StringContent(@"Authorization Header not provided"); var responseMessage401 = new HttpResponseMessage { Content = content, StatusCode = System.Net.HttpStatusCode.Unauthorized, RequestMessage = new HttpRequestMessage { Method = HttpMethod.Get } }; try { RwsExceptionHandler.Parse(responseMessage401); } catch (RwsAuthorizationException ex) { Assert.AreEqual("Authorization Header not provided", ex.Message); } }
public async Task <IRwsResponse> SendRequestAsync(IRwsRequest request, int?timeout = null) { var client = new FlurlRequest(Url.Combine(BaseUrl, request.UrlPath())); if (timeout != null) { client.WithTimeout((int)timeout); } if (request.RequiresAuthentication) { client.WithBasicAuth(_username, _password); } client.WithHeaders(request.Headers); var stopwatch = Stopwatch.StartNew(); HttpResponseMessage response = null; try { response = await client.AllowAnyHttpStatus().SendAsync(request.Method, request.RequestBody); } catch (FlurlHttpTimeoutException ex) { throw new RwsException($"Connection timeout for {client.Url.ToString()}", ex); } stopwatch.Stop(); LastResult = response; RequestTime = stopwatch.Elapsed; RwsExceptionHandler.Parse(response); return(request.Result(response)); }