Class MockedResponseContent
Represents a mocked response content.
public class MockedResponseContent : PreMadeResponse
- Inheritance
-
MockedResponseContent
- Inherited Members
Constructors
MockedResponseContent(int, BodyContent)
public MockedResponseContent(int statusCode, BodyContent body)
Parameters
statusCodeintbodyBodyContent
Properties
Body
public BodyContent? Body { get; set; }
Property Value
Headers
[JsonInclude]
public List<MockedResponseHeader> Headers { get; set; }
Property Value
StatusCode
public int StatusCode { get; set; }
Property Value
Methods
CreateEmptyWithStatusCode(int)
Creates a mocked response content with the specified status code.
public static MockedResponseContent CreateEmptyWithStatusCode(int statusCode)
Parameters
statusCodeintThe status code of the mocked response content.
Returns
- MockedResponseContent
A mocked response content object with the specified status code.
CreateFromByteArray(byte[], int, string)
Creates a MockedResponseContent object from a byte array.
public static MockedResponseContent CreateFromByteArray(byte[] data, int statusCode = 200, string contentType = "application/octet-stream")
Parameters
databyte[]The data to be included in the response body.
statusCodeintThe status code of the response (optional, default is 200).
contentTypestringThe content type of the response (optional, default is "application/octet-stream").
Returns
- MockedResponseContent
A new instance of MockedResponseContent with the specified data, status code, and content type.
Exceptions
- ArgumentNullException
Thrown when the
dataparameter is null.- ArgumentOutOfRangeException
Thrown when the
statusCodeparameter is less than 100 or greater than 599.
CreateFromFile(string, int, string?)
Create a body content from a file, if contentType is null, it will be inferred from the file extension
public static MockedResponseContent CreateFromFile(string fileName, int statusCode = 200, string? contentType = null)
Parameters
Returns
Exceptions
CreateFromHtmlContent(string, int, string)
Creates a mocked response content from HTML content.
public static MockedResponseContent CreateFromHtmlContent(string htmlContent, int statusCode = 200, string contentType = "text/html")
Parameters
htmlContentstringThe HTML content of the response.
statusCodeintThe status code of the response (default is 200).
contentTypestringThe content type of the response (default is "text/html").
Returns
- MockedResponseContent
A mocked response content object.
CreateFromHtmlFile(string, int, string)
Creates a MockedResponseContent object by reading the contents of an HTML file.
public static MockedResponseContent CreateFromHtmlFile(string fileName, int statusCode = 200, string contentType = "text/html")
Parameters
fileNamestringThe path to the HTML file to be read.
statusCodeintThe HTTP status code to be associated with the mocked response. Default value is 200.
contentTypestringThe content-type of the mocked response. Default value is "text/html".
Returns
- MockedResponseContent
A MockedResponseContent object representing the contents of the HTML file.
CreateFromJsonContent(string, int, string)
Creates a mocked response content object from a JSON content string.
public static MockedResponseContent CreateFromJsonContent(string jsonContent, int statusCode = 200, string contentType = "application/json")
Parameters
jsonContentstringThe JSON content string to be used.
statusCodeintThe status code of the response (default is 200).
contentTypestringThe content type of the response (default is "application/json").
Returns
- MockedResponseContent
A MockedResponseContent object created from the provided JSON content.
CreateFromJsonFile(string, int, string)
Creates a mocked response content from a JSON file.
public static MockedResponseContent CreateFromJsonFile(string fileName, int statusCode = 200, string contentType = "application/json")
Parameters
fileNamestringThe name of the JSON file.
statusCodeintThe status code of the response content (default is 200).
contentTypestringThe content type of the response content (default is "application/json").
Returns
- MockedResponseContent
A mocked response content object.
CreateFromPlainText(string, int, string)
Creates a mocked response content object from plain text.
public static MockedResponseContent CreateFromPlainText(string text, int statusCode = 200, string contentType = "text/plain")
Parameters
textstringThe text content.
statusCodeintThe HTTP status code of the mocked response content. Default value is 200.
contentTypestringThe content type of the mocked response content. Default value is "text/plain".
Returns
- MockedResponseContent
A MockedResponseContent object representing the mocked response content.
CreateFromPlainTextFile(string, int, string)
Creates a MockedResponseContent object from a plain text file.
public static MockedResponseContent CreateFromPlainTextFile(string fileName, int statusCode = 200, string contentType = "text/plain")
Parameters
fileNamestringThe name of the plain text file.
statusCodeintThe status code of the response. Defaults to 200.
contentTypestringThe content type of the response. Defaults to "text/plain".
Returns
- MockedResponseContent
A MockedResponseContent object.
CreateFromString(string, int, string)
Creates a new instance of the MockedResponseContent class with the specified text, status code, and content type.
public static MockedResponseContent CreateFromString(string text, int statusCode, string contentType)
Parameters
textstringThe content of the response as a string.
statusCodeintThe HTTP status code to be returned.
contentTypestringThe MIME type of the content.
Returns
- MockedResponseContent
A new instance of the MockedResponseContent class with the specified parameters.
Exceptions
- ArgumentNullException
Thrown when the 'text' parameter is null.
- ArgumentOutOfRangeException
Thrown when the 'statusCode' parameter is not within the range of 100 to 599.
CreateFromXmlContent(string, int, string)
Creates a MockedResponseContent object from XML content.
public static MockedResponseContent CreateFromXmlContent(string xmlContent, int statusCode = 200, string contentType = "text/xml")
Parameters
xmlContentstringThe XML content to be used in the response.
statusCodeintThe HTTP status code for the response. Default value is 200.
contentTypestringThe content type for the response. Default value is "text/xml".
Returns
- MockedResponseContent
A MockedResponseContent object representing the response.
CreateFromXmlFile(string, int, string)
Creates a MockedResponseContent object from an XML file.
public static MockedResponseContent CreateFromXmlFile(string fileName, int statusCode = 200, string contentType = "text/xml")
Parameters
fileNamestringThe path of the XML file.
statusCodeintThe status code of the mock response. Default is 200.
contentTypestringThe content type of the mock response. Default is 'text/xml'.
Returns
- MockedResponseContent
A MockedResponseContent object representing the XML file content.
GetFlatH11Header(Authority, ExchangeContext?)
public override string GetFlatH11Header(Authority authority, ExchangeContext? exchangeContext)
Parameters
authorityAuthorityexchangeContextExchangeContext
Returns
ReadBody(Authority)
public override Stream ReadBody(Authority authority)
Parameters
authorityAuthority