Current solution
So, I have something very similar to
[HttpPost]
public ActionResult Upload()
{
var length = Request.ContentLength;
var bytes = new byte[length];
if (Request.Files != null )
{
if (Request.Files.Count > 0)
{
var successJson1 = new {success = true};
return Json(successJson1, "text/html");
}
}
...
return Json(successJson2,"text/html");
}
A single test solution?
I need something like this:
[HttpPost]
public ActionResult Upload(HttpRequestBase request)
{
var length = request.ContentLength;
var bytes = new byte[length];
if (request.Files != null )
{
if (request.Files.Count > 0)
{
var successJson1 = new {success = true};
return Json(successJson1);
}
}
return Json(failJson1);
}
However, this fails, which is annoying since I can make a Mock from the base class and use it.
Notes
- I know that this is not the best way to parse the form / load and for example, say that other things are happening here (namely, that this load can be a form or xmlhttprequest - the action does not know that).
- Other ways to make the Request block testable will also be great.
source
share