Joutsen  v0.4.1
Public Member Functions | List of all members
Joutsen.Fakes.MvcFakesFactory Class Reference

A factory class for various faked ASP.NET Mvc controller related objects which can be used to ease unit testing. More...

Public Member Functions

ControllerContext CreateContext (Controller controller, String httpMethod=null)
 Creates a fake System.Web.Mvc.ControllerContext. More...
 
HtmlHelper< TModel > HtmlHelper< TModel > (ViewDataDictionary viewData, ViewContext viewContext)
 Creates a fake System.Web.Mvc.HtmlHelper. More...
 
HtmlHelper< TModel > HtmlHelper< TModel > (ViewDataDictionary viewData, HttpContextBase httpContext)
 Creates a fake System.Web.Mvc.HtmlHelper. More...
 
HtmlHelper< TModel > HtmlHelper< TModel > (ViewDataDictionary viewData)
 Creates a fake System.Web.Mvc.HtmlHelper. More...
 
HtmlHelper< TModel > HtmlHelper< TModel > (TModel model)
 Creates a fake System.Web.Mvc.HtmlHelper. More...
 
HttpRequestBase Request (String httpMethod)
 Creates a fake System.Web.HttpRequestBase for a HTTP method. More...
 
HttpResponseBase Response ()
 Creates a fake System.Web.HttpResponseBase. More...
 
HttpContextBase HttpContext (String httpMethod=null)
 Creates a fake System.Web.HttpContextBase. More...
 
HttpServerUtilityBase ServerUtility ()
 Creates a fake System.Web.HttpServerUtilityBase. More...
 
ModelBindingContext ModelBindingContext (string modelName, Type modelType, Dictionary< string, object > values)
 Creates a System.Web.Mvc.ModelBindingContext that contains a System.Web.Mvc.IValueProvider which retrieves its values from a dictionary. More...
 
IValueProvider ValueProvider (Dictionary< string, object > values)
 Creates a System.Web.Mvc.IValueProvider which will map requested value names to keys of a dictionary and return the respective value. More...
 
UrlHelper UrlHelper (HttpContextBase httpContext)
 Creates a fake System.Web.Mvc.UrlHelper. More...
 

Detailed Description

A factory class for various faked ASP.NET Mvc controller related objects which can be used to ease unit testing.

A factory class for various faked ASP.NET Mvc objects related to System.Web.Mvc.UrlHelper which can be used to ease unit testing.

A factory class for various faked ASP.NET Mvc model binding objects which can be used to ease unit testing.

A factory class for various faked ASP.NET Mvc objects which can be used to ease unit testing.

A factory class for various faked ASP.NET Mvc objects related to System.Web.Mvc.HtmlHelper which can be used to ease unit testing.

Since
0.4.0
Remarks
the fake objects returned by this class are created using NSubstitute. They are sometimes preconfigured to return certain values. Their behaviour can easily be modified by using the documented functions on NSubstitute fakes.
Since
0.4.0

Member Function Documentation

◆ CreateContext()

ControllerContext Joutsen.Fakes.MvcFakesFactory.CreateContext ( Controller  controller,
String  httpMethod = null 
)

Creates a fake System.Web.Mvc.ControllerContext.

Parameters
controllerthe controller for which the context is created
httpMethodthe HTTP method of the request, if the request is to be faked as well. See Framework.UnitTest.Mvc.Http.CreateRequest(String).
Returns
a faked ControllerContext object created by NSubstitute

◆ HtmlHelper< TModel >() [1/4]

HtmlHelper<TModel> Joutsen.Fakes.MvcFakesFactory.HtmlHelper< TModel > ( ViewDataDictionary  viewData,
ViewContext  viewContext 
)

Creates a fake System.Web.Mvc.HtmlHelper.

Template Parameters
TModelthe type of the model of the helper
Parameters
viewDatathe view related data of the helper
viewContextthe viewContext for the new helper
Returns
a new fake HtmlHelper

◆ HtmlHelper< TModel >() [2/4]

HtmlHelper<TModel> Joutsen.Fakes.MvcFakesFactory.HtmlHelper< TModel > ( ViewDataDictionary  viewData,
HttpContextBase  httpContext 
)

Creates a fake System.Web.Mvc.HtmlHelper.

Template Parameters
TModelthe type of the model of the helper
Parameters
viewDatathe view related data of the helper
httpContextthe httpcontext for the new helper
Returns
a new fake HtmlHelper

◆ HtmlHelper< TModel >() [3/4]

HtmlHelper<TModel> Joutsen.Fakes.MvcFakesFactory.HtmlHelper< TModel > ( ViewDataDictionary  viewData)

Creates a fake System.Web.Mvc.HtmlHelper.

Template Parameters
TModelthe type of the model of the helper
Parameters
viewDatathe view related data of the helper
Returns
a new fake HtmlHelper

◆ HtmlHelper< TModel >() [4/4]

HtmlHelper<TModel> Joutsen.Fakes.MvcFakesFactory.HtmlHelper< TModel > ( TModel  model)

Creates a fake System.Web.Mvc.HtmlHelper.

Template Parameters
TModelthe type of the model of the helper
Parameters
modelThe model of the helper
Returns
a new fake HtmlHelper

◆ HttpContext()

HttpContextBase Joutsen.Fakes.MvcFakesFactory.HttpContext ( String  httpMethod = null)

Creates a fake System.Web.HttpContextBase.

Parameters
httpMethodthe HTTP method of the request, if the request is to be faked as well
Returns
a faked HttpContextBase object created by NSubstitute

◆ ModelBindingContext()

ModelBindingContext Joutsen.Fakes.MvcFakesFactory.ModelBindingContext ( string  modelName,
Type  modelType,
Dictionary< string, object >  values 
)

Creates a System.Web.Mvc.ModelBindingContext that contains a System.Web.Mvc.IValueProvider which retrieves its values from a dictionary.

Parameters
modelNamethe name of the model the context shall provide data for
modelTypethe type of the model the context shall provide data for
valuesthe data values as a mapping of property name to value which are used by the System.Web.Mvc.IValueProvider.
Returns
a System.Web.Mvc.ModelBindingContext for the specified model that will provide the specified values

◆ Request()

HttpRequestBase Joutsen.Fakes.MvcFakesFactory.Request ( String  httpMethod)

Creates a fake System.Web.HttpRequestBase for a HTTP method.

Parameters
httpMethodthe HTTP method of the request: GET, POST, HEAD, PUT, etc
Returns
a faked System.Web.HttpRequestBase object created by NSubstitute

◆ Response()

HttpResponseBase Joutsen.Fakes.MvcFakesFactory.Response ( )

Creates a fake System.Web.HttpResponseBase.

Returns
a faked HttpResponseBase object created by NSubstitute.

◆ ServerUtility()

HttpServerUtilityBase Joutsen.Fakes.MvcFakesFactory.ServerUtility ( )

Creates a fake System.Web.HttpServerUtilityBase.

Returns
a faked HttpServerUtilityBase object created by NSubstitute

◆ UrlHelper()

UrlHelper Joutsen.Fakes.MvcFakesFactory.UrlHelper ( HttpContextBase  httpContext)

Creates a fake System.Web.Mvc.UrlHelper.

Parameters
httpContextthe httpcontext for the new helper
Returns
a new fake System.Web.Mvc.UrlHelper

◆ ValueProvider()

IValueProvider Joutsen.Fakes.MvcFakesFactory.ValueProvider ( Dictionary< string, object >  values)

Creates a System.Web.Mvc.IValueProvider which will map requested value names to keys of a dictionary and return the respective value.

Parameters
valuesthe dictionary providing the name value mapping
Returns
a IValueProvider which will return values from the dictionary