C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
MockResponse.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Net;
4using RestSharp;
5
7{
8 public class MockResponse : RestResponse
9 {
10 public RestResponse Response { get; set; }
11
13 public static MockResponse Error(Exception requestException, ResponseStatus status = ResponseStatus.Error)
14 {
15 return new MockResponse
16 {
17 ResponseStatus = status,
18 ErrorException = requestException,
19 };
20 }
21
23 public static MockResponse Completed(HttpStatusCode httpStatus, ResponseStatus status = ResponseStatus.Completed)
24 {
25 return new MockResponse
26 {
27 StatusCode = httpStatus,
28 ResponseStatus = status,
29 };
30 }
31
35 public static MockResponse RetryAfter(double? retry_time, int? queue_position)
36 {
37 MockResponse response = new MockResponse
38 {
39 StatusCode = HttpStatusCode.ServiceUnavailable,
40 };
41 List<Parameter> mockHeaders = new List<Parameter>();
42 if (retry_time.HasValue)
43 mockHeaders.Add(new Parameter
44 {
45 Type = ParameterType.HttpHeader,
46 Name = "Retry-After",
47 Value = retry_time.Value
48 });
49 if (queue_position.HasValue)
50 mockHeaders.Add(new Parameter
51 {
52 Type = ParameterType.HttpHeader,
53 Name = "Queue-Position",
54 Value = queue_position.Value
55 });
56 response.Headers = mockHeaders;
57 return response;
58 }
59 }
60}
static MockResponse RetryAfter(double? retry_time, int? queue_position)
Throw a server-like retry-after response.
static MockResponse Error(Exception requestException, ResponseStatus status=ResponseStatus.Error)
Create a mock response with the specified error.
static MockResponse Completed(HttpStatusCode httpStatus, ResponseStatus status=ResponseStatus.Completed)
Create a mock response with the specified error.