I wrote a special ActionResult that returns a string. I am trying to understand how I can unit test it.
I tried the following:
string ExecuteResult(ActionResult result)
{
var ctx = new ControllerContext();
var writer = new StringWriter();
var response = new HttpResponse(writer);
var context = new HttpContext(new HttpRequest(null, "http://localhost/uri/", null), response);
System.Web.HttpContext.Current = context;
result.ExecuteResult(ctx);
return writer.ToString();
}
This gives me:
Test method Tests.Web.Mvc.ApplicationControllerTest.TestMessageBox threw exception:
System.NotImplementedException: The method or operation is not implemented.
Stack trace:
System.Web.HttpContextBase.get_Response()
System.Web.Mvc.JavaScriptResult.ExecuteResult(ControllerContext context)
Tests.Web.Mvc.ResultExecutor.InvokeActionResult(ActionResult result) in D:\utv\Framework 4.0\Main\src\Framework.Tests\Web\Mvc\ResultExecutor.cs: line 22
Tests.Web.Mvc.ApplicationControllerTest.TestMessageBox() in D:\utv\Framework 4.0\Main\src\Framework.Tests\Web\Mvc\ApplicationControllerTest.cs: line 46
How to check the results of actions?
source
share