C# Client Library
A C# Client Library for the AnalyzeRe REST API
MockResponse.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Net;
4 using RestSharp;
5 
6 namespace AnalyzeReTesting.Utilities
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 Error(Exception requestException, ResponseStatus status=ResponseStatus.Error)
Create a mock response with the specified error.
Definition: MockResponse.cs:13
static MockResponse Completed(HttpStatusCode httpStatus, ResponseStatus status=ResponseStatus.Completed)
Create a mock response with the specified error.
Definition: MockResponse.cs:23
static MockResponse RetryAfter(double?retry_time, int?queue_position)
Throw a server-like retry-after response.
Definition: MockResponse.cs:35