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
statusCode
intbody
BodyContent
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
statusCode
intThe 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
data
byte[]The data to be included in the response body.
statusCode
intThe status code of the response (optional, default is 200).
contentType
stringThe 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
data
parameter is null.- ArgumentOutOfRangeException
Thrown when the
statusCode
parameter 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
htmlContent
stringThe HTML content of the response.
statusCode
intThe status code of the response (default is 200).
contentType
stringThe 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
fileName
stringThe path to the HTML file to be read.
statusCode
intThe HTTP status code to be associated with the mocked response. Default value is 200.
contentType
stringThe 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
jsonContent
stringThe JSON content string to be used.
statusCode
intThe status code of the response (default is 200).
contentType
stringThe 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
fileName
stringThe name of the JSON file.
statusCode
intThe status code of the response content (default is 200).
contentType
stringThe 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
text
stringThe text content.
statusCode
intThe HTTP status code of the mocked response content. Default value is 200.
contentType
stringThe 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
fileName
stringThe name of the plain text file.
statusCode
intThe status code of the response. Defaults to 200.
contentType
stringThe 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
text
stringThe content of the response as a string.
statusCode
intThe HTTP status code to be returned.
contentType
stringThe 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
xmlContent
stringThe XML content to be used in the response.
statusCode
intThe HTTP status code for the response. Default value is 200.
contentType
stringThe 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
fileName
stringThe path of the XML file.
statusCode
intThe status code of the mock response. Default is 200.
contentType
stringThe 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
authority
AuthorityexchangeContext
ExchangeContext
Returns
ReadBody(Authority)
public override Stream ReadBody(Authority authority)
Parameters
authority
Authority