Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test custom ActionResult

I've written a custom ActionResult which returns a string. I'm trying to figure out how I can unit test it.

I've tried with 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();
  }

It 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 do I test action results?

like image 320
jgauffin Avatar asked Sep 18 '26 19:09

jgauffin


1 Answers

Guess it's not possible for MVC2 or MVC3.

like image 199
jgauffin Avatar answered Sep 21 '26 07:09

jgauffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!