Mock

public struct Mock: Equatable

A Mock which can be used for mocking data requests with the Mocker by calling Mocker.register(...).

  • Declaration

    Swift

    public enum HTTPMethod: String
  • The types of content of a request. Will be used as Content-Type header inside a Mock.

    Declaration

    Swift

    public enum ContentType: String
  • The type of the data which is returned.

    Declaration

    Swift

    public let contentType: ContentType
  • The headers to send back with the response.

    Declaration

    Swift

    public let headers: [String: String]
  • The HTTP status code to return with the response.

    Declaration

    Swift

    public let statusCode: Int
  • url

    The URL value generated based on the Mock data.

    Declaration

    Swift

    public let url: URL
  • The file extensions to match for.

    Declaration

    Swift

    public let fileExtensions: [String]?
  • Creates a Mock for the given data type. The mock will be automatically matched based on a URL created from the given parameters.

    Declaration

    Swift

    public init(contentType: ContentType, statusCode: Int, data: [HTTPMethod: Data], additionalHeaders: [String: String] = [:])

    Parameters

    contentType

    The type of the data which is returned.

    statusCode

    The HTTP status code to return with the response.

    data

    The data which will be returned as the response based on the HTTP Method.

    additionalHeaders

    Additional headers to be added to the response.

  • Creates a Mock for the given URL.

    Declaration

    Swift

    public init(url: URL, contentType: ContentType, statusCode: Int, data: [HTTPMethod: Data], additionalHeaders: [String: String] = [:])

    Parameters

    url

    The URL to match for and to return the mocked data for.

    contentType

    The type of the data which is returned.

    statusCode

    The HTTP status code to return with the response.

    data

    The data which will be returned as the response based on the HTTP Method.

    additionalHeaders

    Additional headers to be added to the response.

  • Creates a Mock for the given file extensions. The mock will only be used for urls matching the extension.

    Declaration

    Swift

    public init(fileExtensions: String..., contentType: ContentType, statusCode: Int, data: [HTTPMethod: Data], additionalHeaders: [String: String] = [:])

    Parameters

    fileExtensions

    The file extension to match for.

    contentType

    The type of the data which is returned.

    statusCode

    The HTTP status code to return with the response.

    data

    The data which will be returned as the response based on the HTTP Method.

    additionalHeaders

    Additional headers to be added to the response.

  • Declaration

    Swift

    public static func == (lhs: Mock, rhs: Mock) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.