I use the calm routing module for asp.net mvc and am very happy with it. But I canβt get one. For example, I had a controller action as follows:
public ActionResult Index() { if (Request.IsAjaxRequest()) return PartialView(); return View(); }
And there was no problem writing a specification like this:
[Subject(typeof(LotsController))] public class When_Index_called { static LotsController controller; static ActionResult actionResult; Establish context = () => { controller = mocker.Create<LotsController>(); controller.ControllerContext = Contexts.Controller.Default; }; Because of = () => actionResult = controller.Index(); It should_render_view = () => actionResult.AssertViewRendered().ForViewWithDefaultName();
But using rest, I want to have an Index method as follows:
public ActionResult Index() { return RespondTo(format => { format.Html = () => { if (Request.IsAjaxRequest()) return PartialView(); return View(); }; format.Json = () => Json(new { }); }); }
I am sure that the previous spec does not work, because the result of the action is not of type ViewResult, its type is FormatResult. FormatResult itself overrides the ExecuteResult method, which returns void. How can I unit test such a case if I want to check the result types and result data in FormatResult?
source share