PeanutButter
Loading...
Searching...
No Matches
PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder Class Reference

Builds a fake http response. More...

Inheritance diagram for PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder:
PeanutButter.TestUtils.AspNetCore.Builders.RandomizableBuilder< TBuilder, TSubject > PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >

Public Member Functions

 HttpResponseBuilder ()
HttpResponseBuilder WithHasStarted (bool hasStarted)
 Sets the HasStarted flag on the response HttpResponses have "started" when the headers have already been sent to the client.
HttpResponseBuilder WithOnStartingHandler (Action< Func< object, Task >, object > handler)
 Add a handler for when OnStarting is called.
HttpResponseBuilder WithOnCompletedHandler (Action< Func< object, Task >, object > handler)
 Add a handler for when the response completes.
HttpResponseBuilder WithRedirectHandler (Action< string, bool > handler)
 Add a handler for when the response redirect.
HttpResponseBuilder WithCookies (IResponseCookies cookies)
 Set the response cookies (opaque service which can only set cookies)
HttpResponseBuilder WithCookies (Func< FakeHttpResponse, IResponseCookies > generator)
 Set the response cookies.
HttpResponseBuilder WithStatusCode (HttpStatusCode code)
 Set the status code for the response.
HttpResponseBuilder WithStatusCode (int code)
 Set the status code for the response.
override HttpResponseBuilder Randomize ()
 Randomizes the response.
HttpResponseBuilder WithHttpContext (HttpContext context)
 Sets the http context on the response.
HttpResponseBuilder WithHttpContext (Func< HttpContext > accessor)
 Sets the http context accessor on the response.
HttpResponseBuilder WithBody (string body)
 Sets the body from utf8-encoded text.
HttpResponseBuilder WithBody (string body, Encoding encoding)
 Sets the body from the provided text, using the provided encoding.
HttpResponseBuilder WithBody (Stream body)
 Sets the body from a stream.
HttpResponseBuilder WithBody (byte[] body)
 Sets the body from some bytes.
HttpResponseBuilder WithCookie (string key, string value)
 Adds a cookie to the response, with default cookie options.
HttpResponseBuilder WithCookie (string key, string value, CookieOptions options)
 Adds a cookie to the response with the provided cookie options.
HttpResponseBuilder WithHeader (string key, string value)
 Sets a header on the response.
HttpResponseBuilder WithHeaders (IDictionary< string, string > headers)
 Sets one or more headers on the response.
HttpResponseBuilder WithHeaders (NameValueCollection headers)
 Sets one or more headers on the response.
Public Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.RandomizableBuilder< TBuilder, TSubject >
TBuilder Randomize ()
 Derivatives must implement this so that BuildRandom can work.
Public Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
TBuilder With (Action< TSubject > action)
 Adds a mutator for the artifact.
virtual TSubject Build ()
 Builds the subject artifact.
 Mutator (Action< T > action, string identifier)

Protected Member Functions

override HttpResponse ConstructEntity ()
 Constructs the fake http response.
Protected Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
TBuilder With (Action< TSubject > action, string identifier)
 Adds an identified mutator for the artifact - if a mutator with the same identity already exists, it will be removed.
TBuilder With< TCast > (Action< TCast > action)
 Adds a mutator for the artifact, cast to TCast.
TBuilder With< TCast > (Action< TCast > action, string identifier)
 Adds an identified mutator for the artifact, cast to TCast.
TBuilder WithRandomTimes (Action< TSubject > action)
 Applies the given mutator a random (1-4) number of times.
TBuilder WithRandomTimes< TCast > (Action< TCast > action)
 Applies the given mutator on a cast item a random (1-4) number of times.
TBuilder WithPreCursor (Action toRun)
 Run a precursor before your entity is constructed - use when your entity requires constructor parameters you'd like to make user-tweakable via builder methods.
TBuilder WithPostBuild (Action< TSubject > action)
 Add post-build actions.

Additional Inherited Members

Static Public Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.RandomizableBuilder< TBuilder, TSubject >
static TSubject BuildRandom ()
 Builds a random variant output artifact.
Static Public Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
static TBuilder Create ()
 Returns a new instance of the builder.
static TSubject BuildDefault ()
 Builds the default output artifact.
Static Protected Member Functions inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
static void WarnIf (bool condition, string message)
 Print a traced warning if the condition is found to be false.
static void ErrorIf (bool condition, string message)
 Print a traced warning if the condition is found to be false.
Protected Attributes inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
TSubject CurrentEntity
 During build, CurrentEntity will be set to the currently-building entity. You may implement actualizer(s) in your derivative to pull this value in lazily to consumers.
Properties inherited from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >
Action< T > Action [get]
string Identifier [get]

Detailed Description

Builds a fake http response.

Member Function Documentation

◆ ConstructEntity()

override HttpResponse PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.ConstructEntity ( )
protectedvirtual

Constructs the fake http response.

Returns

Reimplemented from PeanutButter.TestUtils.AspNetCore.Builders.Builder< TBuilder, TSubject >.

◆ Randomize()

override HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.Randomize ( )

Randomizes the response.

Returns

◆ WithBody() [1/4]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithBody ( byte[] body)

Sets the body from some bytes.

Parameters
body
Returns

◆ WithBody() [2/4]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithBody ( Stream body)

Sets the body from a stream.

Parameters
body
Returns

◆ WithBody() [3/4]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithBody ( string body)

Sets the body from utf8-encoded text.

Parameters
body
Returns

◆ WithBody() [4/4]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithBody ( string body,
Encoding encoding )

Sets the body from the provided text, using the provided encoding.

Parameters
body
encoding
Returns

◆ WithCookie() [1/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithCookie ( string key,
string value )

Adds a cookie to the response, with default cookie options.

Parameters
key
value
Returns

◆ WithCookie() [2/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithCookie ( string key,
string value,
CookieOptions options )

Adds a cookie to the response with the provided cookie options.

Parameters
key
value
options
Returns

◆ WithCookies() [1/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithCookies ( Func< FakeHttpResponse, IResponseCookies > generator)

Set the response cookies.

Parameters
generator
Returns

◆ WithCookies() [2/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithCookies ( IResponseCookies cookies)

Set the response cookies (opaque service which can only set cookies)

Parameters
cookies
Returns

◆ WithHasStarted()

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHasStarted ( bool hasStarted)

Sets the HasStarted flag on the response HttpResponses have "started" when the headers have already been sent to the client.

Parameters
hasStarted
Returns

◆ WithHeader()

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHeader ( string key,
string value )

Sets a header on the response.

Parameters
key
value
Returns

◆ WithHeaders() [1/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHeaders ( IDictionary< string, string > headers)

Sets one or more headers on the response.

Parameters
headers
Returns

◆ WithHeaders() [2/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHeaders ( NameValueCollection headers)

Sets one or more headers on the response.

Parameters
headers
Returns

◆ WithHttpContext() [1/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHttpContext ( Func< HttpContext > accessor)

Sets the http context accessor on the response.

Parameters
accessor
Returns

◆ WithHttpContext() [2/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithHttpContext ( HttpContext context)

Sets the http context on the response.

Parameters
context
Returns

◆ WithOnCompletedHandler()

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithOnCompletedHandler ( Action< Func< object, Task >, object > handler)

Add a handler for when the response completes.

Parameters
handler
Returns

◆ WithOnStartingHandler()

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithOnStartingHandler ( Action< Func< object, Task >, object > handler)

Add a handler for when OnStarting is called.

Parameters
handler
Returns

◆ WithRedirectHandler()

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithRedirectHandler ( Action< string, bool > handler)

Add a handler for when the response redirect.

Parameters
handler
Returns

◆ WithStatusCode() [1/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithStatusCode ( HttpStatusCode code)

Set the status code for the response.

Parameters
code
Returns

◆ WithStatusCode() [2/2]

HttpResponseBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpResponseBuilder.WithStatusCode ( int code)

Set the status code for the response.

Parameters
code
Returns

The documentation for this class was generated from the following file:
  • source/TestUtils/PeanutButter.TestUtils.AspNetCore/Builders/HttpResponseBuilder.cs