I am trying unit-test a method. The method takes in a single argument, which belongs to the class HttpContext
in NET Framework Class Library.
So I guess I need to prepare an object of HttpContext
.
All that the method needs from the argument, say context
, are
context.Request.QueryString
context.Request.Headers
Here are my thoughts and questions
To learn how to use
HttpContext
, I click going to definition in Visual Studio, I found that the class has a constructorpublic HttpContext(HttpRequest request, HttpResponse response);
so I need to provide its two arguments, in order to create a object of the class.
To provide the first argument, which is an object of HttpRequest, I found its constructor
// // Summary: // Initializes an System.Web.HttpRequest object. // // Parameters: // filename: // The name of the file associated with the request. // // url: // The information regarding the URL of the current request. // // queryString: // The entire query string sent with the request (everything after the'?'). public HttpRequest(string filename, string url, string queryString);
What does
filename
mean?Which is
url
, the full url containing the query strings, or just the part before?
?
To provide the second argument of class
HttpResponse
, I found its constructorpublic HttpResponse(TextWriter writer);
The method to be tested actually doesn't need
context.Response
. So can I simply create this as the second argument to the constructor ofHttpContext
:writer = new TextWriter (); response = new HttpResponse(writer);
given that the constructors of
TextWriter
are protected?protected TextWriter(); protected TextWriter(IFormatProvider formatProvider);
After I can create an object of HttpContext, do I need to call some method to parse the url and query strings to obtain
context.Request.QueryString
context.Request.Headers
or the
HttpContext
will implicitly do the work without me explicitly calling any method?
Thanks.