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

Builds an HttpContext. More...

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

Public Member Functions

override HttpContextBuilder Randomize ()
 Randomizes the context.
 HttpContextBuilder ()
 Constructs the builder.
HttpContextBuilder WithDefaultConnection ()
 Populates a ConnectionInfo on the HttpContext with the local and remote addresses both being 127.0.0.1.
HttpContextBuilder WithRandomConnection ()
 Populates a random ConnectionInfo on the HttpContext.
HttpContextBuilder WithRequestServices (IServiceProvider serviceProvider)
 Sets the RequestServices service provider for the context.
HttpContextBuilder WithItem (object key, object value)
 Sets an Item on the context.
HttpContextBuilder WithWebSockets (WebSocketManager webSocketManager)
 Sets the WebSockets manager on the request.
HttpContextBuilder WithFeature< TFeature > (TFeature feature)
 Adds a feature to the request.
HttpContextBuilder WithFeature< TFeature > (Func< HttpContext, TFeature > factory)
 Set a feature via a factory which has access to the HttpContext.
HttpContextBuilder WithUser (ClaimsPrincipal principal)
 Sets the user on the request.
HttpContextBuilder WithConnection (ConnectionInfo connectionInfo)
 Sets the connection info on the request.
HttpContextBuilder WithResponse (HttpResponse response)
 Sets the response on the context.
HttpContextBuilder WithResponse (Func< HttpResponse > accessor)
 Sets the response accessor on the context.
HttpContextBuilder WithRequest (HttpRequest request)
 Sets the request on the context.
HttpContextBuilder WithRequest (Func< HttpRequest > requestAccessor)
 Sets the request accessor on the context.
HttpContextBuilder WithFeatures (IFeatureCollection features)
 Sets the feature collection on the request.
HttpContextBuilder WithFormFile (string content, string name, string fileName=null)
 Adds a form file to the context.
HttpContextBuilder WithRequestQueryParameter (string key, string value)
 Sets a query parameter on the request.
HttpContextBuilder WithRequestQueryParameters (IDictionary< string, string > parameters)
 Bulk-sets query parameters on the request.
HttpContextBuilder WithFormField (string key, string value)
 Adds a form field to the request Use this when what you want to do can be accomplished on the proper IFormCollection type.
HttpContextBuilder WithFakeRequestFormModifier (Action< FakeFormCollection > modifier)
 Modifies some aspect of the request form. Use this when you want access to the functionality of the underlying fake.
HttpContextBuilder WithRequestMutator (Action< HttpRequest > mutator)
 Modifies some aspect of the request. Use this when what you want to do can be achieved on the proper HttpRequest type.
HttpContextBuilder WithResponseMutator (Action< HttpResponse > mutator)
 Modifies some aspect of the response. Use this when what you want to do can be achieved on the proper HttpResponse type.
HttpContextBuilder WithFakeRequestModifier (Action< FakeHttpRequest > modifier)
 Modifies some aspect of the request. Use this when you want access to the functionality of the underlying fake.
HttpContextBuilder WithUrl (Uri uri)
 Set the full url for the request.
HttpContextBuilder WithUrl (string url)
 Set the full url for the request.
HttpContextBuilder WithTransientService< TService, TImplementation > ()
 Register a transient service.
HttpContextBuilder WithSingletonService< TService, TImplementation > ()
 Register a singleton service.
HttpContextBuilder WithService< TService > (TService service)
 Register a service instance.
HttpContextBuilder WithService< TService > (Func< HttpContext, TService > factory)
 Register a service factory.
HttpContextBuilder WithService< TService > (Func< TService > factory)
 Register a service factory.
HttpContextBuilder WithServicesMutator (Action< HttpContext, MinimalServiceProvider > mutator)
 Open access to apply mutations to the MinimalServiceProvider, if not overridden.
HttpContextBuilder WithServicesMutator (Action< MinimalServiceProvider > mutator)
 Open access to apply mutations to the MinimalServiceProvider, if not overridden.
HttpContextBuilder WithRequestHeader (string key, string value)
 Set a request header.
HttpContextBuilder WithRequestCookie (string key, string value)
 Set a request cookie.
HttpContextBuilder WithRequestPath (string path)
 Sets the path on the request.
HttpContextBuilder WithRequestContentType (string contentType)
 Sets the ContentType (and related Content-Type header) on the request.
HttpContextBuilder WithResponseHeader (string key, string value)
 Set a response header.
HttpContextBuilder WithRemoteAddress (string ipAddress)
 Sets the HttpContext.Connection.RemoteIpAddress value.
HttpContextBuilder WithRemoteAddress (IPAddress address)
 Sets the HttpContext.Connection.RemoteIpAddress value.
HttpContextBuilder WithSessionItems (IDictionary< string, object > items)
 Sets session items on the HttpContext from the provided collection.
HttpContextBuilder WithSessionItem (string key, object value)
 Sets an item in the HttpContext.Session.
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 HttpContext ConstructEntity ()
 Constructs the fake http context.
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 an HttpContext.

Member Function Documentation

◆ ConstructEntity()

override HttpContext PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.ConstructEntity ( )
protectedvirtual

Constructs the fake http context.

Returns

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

◆ Randomize()

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

Randomizes the context.

Returns

◆ WithConnection()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithConnection ( ConnectionInfo connectionInfo)

Sets the connection info on the request.

Parameters
connectionInfo
Returns

◆ WithDefaultConnection()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithDefaultConnection ( )

Populates a ConnectionInfo on the HttpContext with the local and remote addresses both being 127.0.0.1.

Returns

◆ WithFakeRequestFormModifier()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFakeRequestFormModifier ( Action< FakeFormCollection > modifier)

Modifies some aspect of the request form. Use this when you want access to the functionality of the underlying fake.

Parameters
modifier
Returns

◆ WithFakeRequestModifier()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFakeRequestModifier ( Action< FakeHttpRequest > modifier)

Modifies some aspect of the request. Use this when you want access to the functionality of the underlying fake.

Parameters
modifier
Returns

◆ WithFeature< TFeature >() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFeature< TFeature > ( Func< HttpContext, TFeature > factory)

Set a feature via a factory which has access to the HttpContext.

Parameters
factory
Template Parameters
TFeature
Returns

◆ WithFeature< TFeature >() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFeature< TFeature > ( TFeature feature)

Adds a feature to the request.

Parameters
feature
Template Parameters
TFeature
Returns

◆ WithFeatures()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFeatures ( IFeatureCollection features)

Sets the feature collection on the request.

Parameters
features
Returns

◆ WithFormField()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFormField ( string key,
string value )

Adds a form field to the request Use this when what you want to do can be accomplished on the proper IFormCollection type.

Parameters
key
value
Returns

◆ WithFormFile()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithFormFile ( string content,
string name,
string fileName = null )

Adds a form file to the context.

Parameters
content
name
fileName
Returns

◆ WithItem()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithItem ( object key,
object value )

Sets an Item on the context.

Parameters
key
value
Returns

◆ WithRandomConnection()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRandomConnection ( )

Populates a random ConnectionInfo on the HttpContext.

Returns

◆ WithRemoteAddress() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRemoteAddress ( IPAddress address)

Sets the HttpContext.Connection.RemoteIpAddress value.

Parameters
address
Returns

◆ WithRemoteAddress() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRemoteAddress ( string ipAddress)

Sets the HttpContext.Connection.RemoteIpAddress value.

Parameters
ipAddress
Returns

◆ WithRequest() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequest ( Func< HttpRequest > requestAccessor)

Sets the request accessor on the context.

Parameters
requestAccessor
Returns

◆ WithRequest() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequest ( HttpRequest request)

Sets the request on the context.

Parameters
request
Returns

◆ WithRequestContentType()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestContentType ( string contentType)

Sets the ContentType (and related Content-Type header) on the request.

Parameters
contentType
Returns

◆ WithRequestCookie()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestCookie ( string key,
string value )

Set a request cookie.

Parameters
key
value
Returns

◆ WithRequestHeader()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestHeader ( string key,
string value )

Set a request header.

Parameters
key
value
Returns
Exceptions
NotImplementedException

◆ WithRequestMutator()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestMutator ( Action< HttpRequest > mutator)

Modifies some aspect of the request. Use this when what you want to do can be achieved on the proper HttpRequest type.

Parameters
mutator
Returns

◆ WithRequestPath()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestPath ( string path)

Sets the path on the request.

Parameters
path
Returns

◆ WithRequestQueryParameter()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestQueryParameter ( string key,
string value )

Sets a query parameter on the request.

Parameters
key
value
Returns

◆ WithRequestQueryParameters()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestQueryParameters ( IDictionary< string, string > parameters)

Bulk-sets query parameters on the request.

Returns

◆ WithRequestServices()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithRequestServices ( IServiceProvider serviceProvider)

Sets the RequestServices service provider for the context.

Parameters
serviceProvider
Returns

◆ WithResponse() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithResponse ( Func< HttpResponse > accessor)

Sets the response accessor on the context.

Parameters
accessor
Returns

◆ WithResponse() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithResponse ( HttpResponse response)

Sets the response on the context.

Parameters
response
Returns

◆ WithResponseHeader()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithResponseHeader ( string key,
string value )

Set a response header.

Parameters
key
value
Returns
Exceptions
NotImplementedException

◆ WithResponseMutator()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithResponseMutator ( Action< HttpResponse > mutator)

Modifies some aspect of the response. Use this when what you want to do can be achieved on the proper HttpResponse type.

Parameters
mutator
Returns

◆ WithService< TService >() [1/3]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithService< TService > ( Func< HttpContext, TService > factory)

Register a service factory.

Parameters
factory
Template Parameters
TService
Returns

◆ WithService< TService >() [2/3]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithService< TService > ( Func< TService > factory)

Register a service factory.

Parameters
factory
Template Parameters
TService
Returns

◆ WithService< TService >() [3/3]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithService< TService > ( TService service)

Register a service instance.

Parameters
service
Template Parameters
TService
Returns

◆ WithServicesMutator() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithServicesMutator ( Action< HttpContext, MinimalServiceProvider > mutator)

Open access to apply mutations to the MinimalServiceProvider, if not overridden.

Parameters
mutator
Returns
Exceptions
NotSupportedException

◆ WithServicesMutator() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithServicesMutator ( Action< MinimalServiceProvider > mutator)

Open access to apply mutations to the MinimalServiceProvider, if not overridden.

Parameters
mutator
Returns
Exceptions
NotSupportedException

◆ WithSessionItem()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithSessionItem ( string key,
object value )

Sets an item in the HttpContext.Session.

Parameters
key
value
Returns

◆ WithSessionItems()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithSessionItems ( IDictionary< string, object > items)

Sets session items on the HttpContext from the provided collection.

Parameters
items
Returns
Exceptions
ArgumentException

◆ WithSingletonService< TService, TImplementation >()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithSingletonService< TService, TImplementation > ( )

Register a singleton service.

Template Parameters
TService
TImplementation
Returns
Type Constraints
TImplementation :TService 

◆ WithTransientService< TService, TImplementation >()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithTransientService< TService, TImplementation > ( )

Register a transient service.

Template Parameters
TService
TImplementation
Returns
Type Constraints
TImplementation :TService 

◆ WithUrl() [1/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithUrl ( string url)

Set the full url for the request.

Parameters
url
Returns

◆ WithUrl() [2/2]

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithUrl ( Uri uri)

Set the full url for the request.

Parameters
uri
Returns

◆ WithUser()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithUser ( ClaimsPrincipal principal)

Sets the user on the request.

Parameters
principal
Returns

◆ WithWebSockets()

HttpContextBuilder PeanutButter.TestUtils.AspNetCore.Builders.HttpContextBuilder.WithWebSockets ( WebSocketManager webSocketManager)

Sets the WebSockets manager on the request.

Parameters
webSocketManager
Returns

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