• Stubbery
Show / Hide Table of Contents

Class ApiStub

Represents an Api stub that responds to certain requests with preconfigured responses.

Inheritance
System.Object
ApiStub
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Stubbery
Assembly: Stubbery.dll
Syntax
public class ApiStub : IDisposable
Remarks

After instantiating and setting up the stubbed endpoints, the stub needs to be started by calling the Start() method.

Constructors

| Improve this Doc View Source

ApiStub()

Creates a new instance of ApiStub

Declaration
public ApiStub()
Remarks

The constructor does not start up the stub web server. In order to start listening for requests, the Start() method needs to be called.

Properties

| Improve this Doc View Source

Address

Gets the full url at which the stub is accessible.

Declaration
public string Address { get; }
Property Value
Type Description
System.String
Remarks

When calling the Start() method, the stub is started on a randomly picked free port. Thus Address will return a url like "http://localhost:51234".

| Improve this Doc View Source

Port

Sets the Port for the stub to start />

Declaration
public int? Port { set; }
Property Value
Type Description
System.Nullable<System.Int32>
Remarks

The Post property cannot be set after the stub has already started. The Start() method needs to be called after the Port is set.

Methods

| Improve this Doc View Source

Delete()

Sets up a new stubbed DELETE request.

Declaration
public ISetup Delete()
Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Delete(String, CreateStubResponse)

Sets up a new stubbed DELETE request on a specific route with a response.

Declaration
public ISetup Delete(string route, CreateStubResponse responder)
Parameters
Type Name Description
System.String route

The route on which the stub will respond.

CreateStubResponse responder

The stubbed response to send.

Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Dispose()

Stops the stub server.

Declaration
public void Dispose()
Remarks

The stub needs to be disposed when it's not needed, so the TCP port used is freed up.

| Improve this Doc View Source

EnsureStarted()

Ensures that the stub server is started.

Declaration
public void EnsureStarted()
Remarks

The stub is started on a randomly picked free port, so it will be accessible on an url like "http://localhost:51234". The exact address can be retrieved through the Address property. If the stub has already been started, then the method returns without doing anything.

| Improve this Doc View Source

Get()

Sets up a new stubbed GET request.

Declaration
public ISetup Get()
Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Get(String, CreateStubResponse)

Sets up a new stubbed GET request on a specific route with a response.

Declaration
public ISetup Get(string route, CreateStubResponse responder)
Parameters
Type Name Description
System.String route

The route on which the stub will respond.

CreateStubResponse responder

The stubbed response to send.

Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Post()

Sets up a new stubbed POST request.

Declaration
public ISetup Post()
Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Post(String, CreateStubResponse)

Sets up a new stubbed POST request on a specific route with a response.

Declaration
public ISetup Post(string route, CreateStubResponse responder)
Parameters
Type Name Description
System.String route

The route on which the stub will respond.

CreateStubResponse responder

The stubbed response to send.

Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Put()

Sets up a new stubbed PUT request.

Declaration
public ISetup Put()
Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Put(String, CreateStubResponse)

Sets up a new stubbed PUT request on a specific route with a response.

Declaration
public ISetup Put(string route, CreateStubResponse responder)
Parameters
Type Name Description
System.String route

The route on which the stub will respond.

CreateStubResponse responder

The stubbed response to send.

Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Request(HttpMethod[])

Sets up a new stubbed request for the specified HTTP methods.

Declaration
public ISetup Request(params HttpMethod[] methods)
Parameters
Type Name Description
System.Net.Http.HttpMethod[] methods

The HTTP methods for which we want to respond.

Returns
Type Description
ISetup

An ISetup object on which further conditions can be set.

| Improve this Doc View Source

Start()

Starts the stub server and starts listening to requests.

Declaration
public void Start()
Remarks

The stub is started on a randomly picked free port, so it will be accessible on an url like "http://localhost:51234". The exact address can be retrieved through the Address property.

Exceptions
Type Condition
System.InvalidOperationException

The stub has already been started.

Implements

System.IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018 Mark Vincze
Generated by DocFX