MODIFIED: The code uses HttpRequest.InputStream to read the request body, parse it, and save it. I would like to be able to unit test this class, but I cannot insert anything into the body. Is it possible? Perhaps I could somehow hack class A, and set the value of _body to some value.
ADDED: here is a simplified design:
class A
{
private string _body;
public string Body { get { return _body; } }
public A(HttpRequest r)
{
{parse r and store data, i.e. query parameter, etc. }
_body = {read body from r.InputStream };
}
}
class B
{
public void ProcessRequest(HttpRequest r)
{
var c = new C(r);
ParseBody(c.Body);
}
}
Everything is fine, I can really check ParseBody, even if it is private. However, I am a class A testing module and where the problem is. I can create the Body R / W property, but this is an encapsulation violation, which I hate because A is supposed to be invariant.
source
share